1 //! Generates large snippets of Rust code for usage in the benchmarks. 2 3 use std::fs; 4 5 use stdx::format_to; 6 7 use crate::project_root; 8 big_struct() -> String9pub fn big_struct() -> String { 10 let n = 1_000; 11 big_struct_n(n) 12 } 13 big_struct_n(n: u32) -> String14pub fn big_struct_n(n: u32) -> String { 15 let mut buf = "pub struct RegisterBlock {".to_string(); 16 for i in 0..n { 17 format_to!(buf, " /// Doc comment for {}.\n", i); 18 format_to!(buf, " pub s{}: S{},\n", i, i); 19 } 20 buf.push_str("}\n\n"); 21 for i in 0..n { 22 format_to!( 23 buf, 24 " 25 26 #[repr(transparent)] 27 struct S{} {{ 28 field: u32, 29 }}", 30 i 31 ); 32 } 33 34 buf 35 } 36 glorious_old_parser() -> String37pub fn glorious_old_parser() -> String { 38 let path = project_root().join("bench_data/glorious_old_parser"); 39 fs::read_to_string(path).unwrap() 40 } 41 numerous_macro_rules() -> String42pub fn numerous_macro_rules() -> String { 43 let path = project_root().join("bench_data/numerous_macro_rules"); 44 fs::read_to_string(path).unwrap() 45 } 46