diff --git a/collector/benchmarks/README.md b/collector/benchmarks/README.md index ff5a77e16..025798446 100644 --- a/collector/benchmarks/README.md +++ b/collector/benchmarks/README.md @@ -81,6 +81,9 @@ programs. performance](https://github.com/rust-lang/rust/issues/46449) in the past. - **regression-31157**: A small program that caused a [large performance regression](https://github.com/rust-lang/rust/issues/31157) from the past. +- **token-stream-stress**: Constructs a long token stream much like the `quote` + crate does, which caused [quadratic + behavior](https://github.com/rust-lang/rust/issues/65080) in the past. - **tuple-stress**: Contains a single array of 65,535 nested `(i32, (f64, f64, f64))` tuples. The data was extracted and reduced from a [program dealing with grid coordinates](https://github.com/urschrei/ostn15_phf) that was diff --git a/collector/benchmarks/token-stream-stress/Cargo.lock b/collector/benchmarks/token-stream-stress/Cargo.lock new file mode 100644 index 000000000..12748c19b --- /dev/null +++ b/collector/benchmarks/token-stream-stress/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "token-stream-stress" +version = "0.0.0" + diff --git a/collector/benchmarks/token-stream-stress/Cargo.toml b/collector/benchmarks/token-stream-stress/Cargo.toml new file mode 100644 index 000000000..6d476f55f --- /dev/null +++ b/collector/benchmarks/token-stream-stress/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "token-stream-stress" +version = "0.0.0" +edition = "2018" +publish = false + +[lib] +path = "src/lib.rs" +proc-macro = true + +[[bin]] +name = "token-stream-stress" +path = "src/main.rs" diff --git a/collector/benchmarks/token-stream-stress/perf-config.json b/collector/benchmarks/token-stream-stress/perf-config.json new file mode 100644 index 000000000..956c1ebf6 --- /dev/null +++ b/collector/benchmarks/token-stream-stress/perf-config.json @@ -0,0 +1,3 @@ +{ + "cargo_opts": "--bin token-stream-stress" +} diff --git a/collector/benchmarks/token-stream-stress/src/lib.rs b/collector/benchmarks/token-stream-stress/src/lib.rs new file mode 100644 index 000000000..334ad6636 --- /dev/null +++ b/collector/benchmarks/token-stream-stress/src/lib.rs @@ -0,0 +1,28 @@ +extern crate proc_macro; + +use proc_macro::{Ident, Punct, Spacing, Span, TokenStream, TokenTree}; +use std::iter::once; + +const N: u32 = 2000; + +#[proc_macro] +pub fn bench(_input: TokenStream) -> TokenStream { + let span = Span::call_site(); + let mut tokens = TokenStream::new(); + for _ in 0..N { + // Similar to what is emitted by `quote`. + tokens.extend(once(TokenTree::Ident(Ident::new("core", span)))); + tokens.extend(once(TokenTree::Punct(Punct::new(':', Spacing::Joint)))); + tokens.extend(once(TokenTree::Punct(Punct::new(':', Spacing::Alone)))); + tokens.extend(once(TokenTree::Ident(Ident::new("option", span)))); + tokens.extend(once(TokenTree::Punct(Punct::new(':', Spacing::Joint)))); + tokens.extend(once(TokenTree::Punct(Punct::new(':', Spacing::Alone)))); + tokens.extend(once(TokenTree::Ident(Ident::new("Option", span)))); + tokens.extend(once(TokenTree::Punct(Punct::new(':', Spacing::Joint)))); + tokens.extend(once(TokenTree::Punct(Punct::new(':', Spacing::Alone)))); + tokens.extend(once(TokenTree::Ident(Ident::new("None", span)))); + tokens.extend(once(TokenTree::Punct(Punct::new(',', Spacing::Joint)))); + } + + TokenStream::new() +} diff --git a/collector/benchmarks/token-stream-stress/src/main.rs b/collector/benchmarks/token-stream-stress/src/main.rs new file mode 100644 index 000000000..089274fd1 --- /dev/null +++ b/collector/benchmarks/token-stream-stress/src/main.rs @@ -0,0 +1,3 @@ +token_stream_stress::bench!(); + +fn main() {}