2021-02-09 16:29:40 +00:00
|
|
|
//! Generates large snippets of Rust code for usage in the benchmarks.
|
|
|
|
|
2021-02-09 18:52:34 +00:00
|
|
|
use std::fs;
|
|
|
|
|
2021-02-09 16:29:40 +00:00
|
|
|
use stdx::format_to;
|
|
|
|
|
2021-03-08 17:22:33 +00:00
|
|
|
use crate::project_root;
|
2021-02-09 18:52:34 +00:00
|
|
|
|
2021-02-09 16:29:40 +00:00
|
|
|
pub fn big_struct() -> String {
|
|
|
|
let n = 1_000;
|
2021-04-06 18:59:47 +00:00
|
|
|
big_struct_n(n)
|
|
|
|
}
|
2021-02-09 16:29:40 +00:00
|
|
|
|
2021-04-06 18:59:47 +00:00
|
|
|
pub fn big_struct_n(n: u32) -> String {
|
2024-02-09 15:58:06 +00:00
|
|
|
let mut buf = "pub struct RegisterBlock {".to_owned();
|
2021-02-09 16:29:40 +00:00
|
|
|
for i in 0..n {
|
|
|
|
format_to!(buf, " /// Doc comment for {}.\n", i);
|
|
|
|
format_to!(buf, " pub s{}: S{},\n", i, i);
|
|
|
|
}
|
|
|
|
buf.push_str("}\n\n");
|
|
|
|
for i in 0..n {
|
|
|
|
format_to!(
|
|
|
|
buf,
|
|
|
|
"
|
|
|
|
|
|
|
|
#[repr(transparent)]
|
|
|
|
struct S{} {{
|
|
|
|
field: u32,
|
|
|
|
}}",
|
|
|
|
i
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
buf
|
|
|
|
}
|
2021-02-09 18:52:34 +00:00
|
|
|
|
|
|
|
pub fn glorious_old_parser() -> String {
|
2021-03-08 17:22:33 +00:00
|
|
|
let path = project_root().join("bench_data/glorious_old_parser");
|
2022-12-24 21:09:08 +00:00
|
|
|
fs::read_to_string(path).unwrap()
|
2021-02-09 18:52:34 +00:00
|
|
|
}
|
2021-02-05 11:57:32 +00:00
|
|
|
|
|
|
|
pub fn numerous_macro_rules() -> String {
|
2021-03-08 17:22:33 +00:00
|
|
|
let path = project_root().join("bench_data/numerous_macro_rules");
|
2022-12-24 21:09:08 +00:00
|
|
|
fs::read_to_string(path).unwrap()
|
2021-02-05 11:57:32 +00:00
|
|
|
}
|