]> git.lizzy.rs Git - rust.git/blob - crates/test_utils/src/bench_fixture.rs
Merge #7918
[rust.git] / crates / test_utils / src / bench_fixture.rs
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
9 pub fn big_struct() -> String {
10     let n = 1_000;
11
12     let mut buf = "pub struct RegisterBlock {".to_string();
13     for i in 0..n {
14         format_to!(buf, "  /// Doc comment for {}.\n", i);
15         format_to!(buf, "  pub s{}: S{},\n", i, i);
16     }
17     buf.push_str("}\n\n");
18     for i in 0..n {
19         format_to!(
20             buf,
21             "
22
23 #[repr(transparent)]
24 struct S{} {{
25     field: u32,
26 }}",
27             i
28         );
29     }
30
31     buf
32 }
33
34 pub fn glorious_old_parser() -> String {
35     let path = project_root().join("bench_data/glorious_old_parser");
36     fs::read_to_string(&path).unwrap()
37 }
38
39 pub fn numerous_macro_rules() -> String {
40     let path = project_root().join("bench_data/numerous_macro_rules");
41     fs::read_to_string(&path).unwrap()
42 }