aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-03-05 12:32:34 +0100
committerHampusM <hampus@hampusmat.com>2023-03-05 13:45:44 +0100
commitbcb50c3d6de52207541969bfeba0701073c56232 (patch)
tree80482cca112e8d4adf17ae833f2e35de95ed9427 /src
parent7073a63562c189b6d89b1834630898a37a4dfb0e (diff)
perf: add benchmarks for TokenStreamExt functions
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"))),
+ )
+ });
+ }
}