aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs1
-rw-r--r--src/token_stream.rs48
2 files changed, 48 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 35d975f..0ec71be 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,6 +1,7 @@
//! Macros utilizing the [OpenGL API and Extension Registry].
//!
//! [OpenGL API and Extension Registry]: https://github.com/KhronosGroup/OpenGL-Registry
+#![cfg_attr(test, feature(test))]
#![deny(clippy::all, clippy::pedantic, missing_docs)]
use once_cell::sync::Lazy;
use opengl_registry::Registry;
diff --git a/src/token_stream.rs b/src/token_stream.rs
index 043de89..5b755c9 100644
--- a/src/token_stream.rs
+++ b/src/token_stream.rs
@@ -163,8 +163,13 @@ mod index_path
#[cfg(test)]
mod tests
{
+ extern crate test;
+
+ use std::hint::black_box;
+
use proc_macro2::Span;
- use quote::quote;
+ use quote::{format_ident, quote};
+ use test::Bencher;
use super::*;
@@ -260,4 +265,45 @@ mod tests
.to_string()
);
}
+
+ #[bench]
+ fn bench_find_all_ident(bencher: &mut Bencher)
+ {
+ let input_strem = quote! {
+ let foo = |abc| {
+ let x = "foo";
+
+ let y = a_foo;
+
+ let foo = "Hello";
+
+ foo.to_string()
+ };
+ };
+
+ bencher.iter(|| input_strem.find_all_ident(&black_box(format_ident!("foo"))));
+ }
+
+ #[bench]
+ fn bench_replace_tokens(bencher: &mut Bencher)
+ {
+ let input_strem = quote! {
+ let foo = |abc| {
+ let x = "foo";
+
+ let y = a_foo;
+
+ let foo = "Hello";
+
+ foo.to_string()
+ };
+ };
+
+ bencher.iter(|| {
+ input_strem.replace_tokens(
+ black_box(&[[1].into(), [6, 11].into(), [6, 15].into()]),
+ black_box(&TokenTree::Ident(format_ident!("foobar"))),
+ )
+ });
+ }
}