aboutsummaryrefslogtreecommitdiff
path: root/src/token_stream.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/token_stream.rs')
-rw-r--r--src/token_stream.rs48
1 files changed, 47 insertions, 1 deletions
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"))),
+ )
+ });
+ }
}