diff options
Diffstat (limited to 'proc-macro2/benches/bench-libproc-macro/lib.rs')
-rw-r--r-- | proc-macro2/benches/bench-libproc-macro/lib.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/proc-macro2/benches/bench-libproc-macro/lib.rs b/proc-macro2/benches/bench-libproc-macro/lib.rs new file mode 100644 index 0000000..46b3711 --- /dev/null +++ b/proc-macro2/benches/bench-libproc-macro/lib.rs @@ -0,0 +1,49 @@ +extern crate proc_macro; + +use proc_macro::{Ident, Punct, Spacing, Span, TokenStream, TokenTree}; +use std::iter::once; +use std::time::Instant; + +const N: u32 = 7000; + +#[proc_macro] +pub fn bench(_input: TokenStream) -> TokenStream { + let start = Instant::now(); + let mut string = String::new(); + for _ in 0..N { + string += "core"; + string += ":"; + string += ":"; + string += "option"; + string += ":"; + string += ":"; + string += "Option"; + string += ":"; + string += ":"; + string += "None"; + string += ","; + } + string.parse::<TokenStream>().unwrap(); + eprintln!("STRING: {} millis", start.elapsed().as_millis()); + + let start = Instant::now(); + 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)))); + } + eprintln!("TOKENSTREAM: {} millis", start.elapsed().as_millis()); + + TokenStream::new() +} |