1fad3a1d3Sopenharmony_ci// $ cargo bench --features full,test --bench file 2fad3a1d3Sopenharmony_ci 3fad3a1d3Sopenharmony_ci#![feature(rustc_private, test)] 4fad3a1d3Sopenharmony_ci#![recursion_limit = "1024"] 5fad3a1d3Sopenharmony_ci#![allow( 6fad3a1d3Sopenharmony_ci clippy::items_after_statements, 7fad3a1d3Sopenharmony_ci clippy::manual_let_else, 8fad3a1d3Sopenharmony_ci clippy::match_like_matches_macro, 9fad3a1d3Sopenharmony_ci clippy::missing_panics_doc, 10fad3a1d3Sopenharmony_ci clippy::must_use_candidate, 11fad3a1d3Sopenharmony_ci clippy::uninlined_format_args 12fad3a1d3Sopenharmony_ci)] 13fad3a1d3Sopenharmony_ci 14fad3a1d3Sopenharmony_ciextern crate test; 15fad3a1d3Sopenharmony_ci 16fad3a1d3Sopenharmony_ci#[macro_use] 17fad3a1d3Sopenharmony_ci#[path = "../tests/macros/mod.rs"] 18fad3a1d3Sopenharmony_cimod macros; 19fad3a1d3Sopenharmony_ci 20fad3a1d3Sopenharmony_ci#[allow(dead_code)] 21fad3a1d3Sopenharmony_ci#[path = "../tests/repo/mod.rs"] 22fad3a1d3Sopenharmony_cimod repo; 23fad3a1d3Sopenharmony_ci 24fad3a1d3Sopenharmony_ciuse proc_macro2::{Span, TokenStream}; 25fad3a1d3Sopenharmony_ciuse std::fs; 26fad3a1d3Sopenharmony_ciuse std::str::FromStr; 27fad3a1d3Sopenharmony_ciuse syn::parse::{ParseStream, Parser}; 28fad3a1d3Sopenharmony_ciuse test::Bencher; 29fad3a1d3Sopenharmony_ci 30fad3a1d3Sopenharmony_ciconst FILE: &str = "tests/rust/library/core/src/str/mod.rs"; 31fad3a1d3Sopenharmony_ci 32fad3a1d3Sopenharmony_cifn get_tokens() -> TokenStream { 33fad3a1d3Sopenharmony_ci repo::clone_rust(); 34fad3a1d3Sopenharmony_ci let content = fs::read_to_string(FILE).unwrap(); 35fad3a1d3Sopenharmony_ci TokenStream::from_str(&content).unwrap() 36fad3a1d3Sopenharmony_ci} 37fad3a1d3Sopenharmony_ci 38fad3a1d3Sopenharmony_ci#[bench] 39fad3a1d3Sopenharmony_cifn baseline(b: &mut Bencher) { 40fad3a1d3Sopenharmony_ci let tokens = get_tokens(); 41fad3a1d3Sopenharmony_ci b.iter(|| drop(tokens.clone())); 42fad3a1d3Sopenharmony_ci} 43fad3a1d3Sopenharmony_ci 44fad3a1d3Sopenharmony_ci#[bench] 45fad3a1d3Sopenharmony_cifn create_token_buffer(b: &mut Bencher) { 46fad3a1d3Sopenharmony_ci let tokens = get_tokens(); 47fad3a1d3Sopenharmony_ci fn immediate_fail(_input: ParseStream) -> syn::Result<()> { 48fad3a1d3Sopenharmony_ci Err(syn::Error::new(Span::call_site(), "")) 49fad3a1d3Sopenharmony_ci } 50fad3a1d3Sopenharmony_ci b.iter(|| immediate_fail.parse2(tokens.clone())); 51fad3a1d3Sopenharmony_ci} 52fad3a1d3Sopenharmony_ci 53fad3a1d3Sopenharmony_ci#[bench] 54fad3a1d3Sopenharmony_cifn parse_file(b: &mut Bencher) { 55fad3a1d3Sopenharmony_ci let tokens = get_tokens(); 56fad3a1d3Sopenharmony_ci b.iter(|| syn::parse2::<syn::File>(tokens.clone())); 57fad3a1d3Sopenharmony_ci} 58