aboutsummaryrefslogtreecommitdiff
path: root/crates/test_utils/src/bench_fixture.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/test_utils/src/bench_fixture.rs')
-rw-r--r--crates/test_utils/src/bench_fixture.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/crates/test_utils/src/bench_fixture.rs b/crates/test_utils/src/bench_fixture.rs
new file mode 100644
index 000000000..aa1bea9bb
--- /dev/null
+++ b/crates/test_utils/src/bench_fixture.rs
@@ -0,0 +1,37 @@
1//! Generates large snippets of Rust code for usage in the benchmarks.
2
3use std::fs;
4
5use stdx::format_to;
6
7use crate::project_dir;
8
9pub 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)]
24struct S{} {{
25 field: u32,
26}}",
27 i
28 );
29 }
30
31 buf
32}
33
34pub fn glorious_old_parser() -> String {
35 let path = project_dir().join("bench_data/glorious_old_parser");
36 fs::read_to_string(&path).unwrap()
37}