Skip to content

Add token-stream-stress benchmark. #516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions collector/benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions collector/benchmarks/token-stream-stress/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions collector/benchmarks/token-stream-stress/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions collector/benchmarks/token-stream-stress/perf-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cargo_opts": "--bin token-stream-stress"
}
28 changes: 28 additions & 0 deletions collector/benchmarks/token-stream-stress/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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()
}
3 changes: 3 additions & 0 deletions collector/benchmarks/token-stream-stress/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
token_stream_stress::bench!();

fn main() {}