Skip to content

Commit 5eeea45

Browse files
ci: add dummy bench with input
1 parent 9403273 commit 5eeea45

File tree

3 files changed

+152
-2
lines changed

3 files changed

+152
-2
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
"values": [
3+
1,
4+
2,
5+
3,
6+
4,
7+
5,
8+
6,
9+
7,
10+
8,
11+
9,
12+
10,
13+
11,
14+
12,
15+
13,
16+
14,
17+
15,
18+
16,
19+
17,
20+
18,
21+
19,
22+
20,
23+
21,
24+
22,
25+
23,
26+
24,
27+
25,
28+
26,
29+
27,
30+
28,
31+
29,
32+
30,
33+
31,
34+
32,
35+
33,
36+
34,
37+
35,
38+
36,
39+
37,
40+
38,
41+
39,
42+
40,
43+
41,
44+
42,
45+
43,
46+
44,
47+
45,
48+
46,
49+
47,
50+
48,
51+
49,
52+
50,
53+
51,
54+
52,
55+
53,
56+
54,
57+
55,
58+
56,
59+
57,
60+
58,
61+
59,
62+
60,
63+
61,
64+
62,
65+
63,
66+
64,
67+
65,
68+
66,
69+
67,
70+
68,
71+
69,
72+
70,
73+
71,
74+
72,
75+
73,
76+
74,
77+
75,
78+
76,
79+
77,
80+
78,
81+
79,
82+
80,
83+
81,
84+
82,
85+
83,
86+
84,
87+
85,
88+
86,
89+
87,
90+
88,
91+
89,
92+
90,
93+
91,
94+
92,
95+
93,
96+
94,
97+
95,
98+
96,
99+
97,
100+
98,
101+
99,
102+
100
103+
],
104+
"multiplier": 10
105+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"values": [
3+
1,
4+
2,
5+
3,
6+
4,
7+
5,
8+
6,
9+
7,
10+
8,
11+
9,
12+
10
13+
],
14+
"multiplier": 2
15+
}

crates/bench_tools/src/benches/dummy_bench.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
use std::hint::black_box;
22

33
use criterion::{criterion_group, criterion_main, Criterion};
4+
use serde::{Deserialize, Serialize};
5+
6+
// Input files are embedded at compile time.
7+
// Before building, ensure these files exist (e.g., downloaded from GCS).
8+
const SMALL_INPUT: &str = include_str!("../../data/dummy_bench_input/small_input.json");
9+
const LARGE_INPUT: &str = include_str!("../../data/dummy_bench_input/large_input.json");
10+
11+
#[derive(Debug, Serialize, Deserialize)]
12+
struct DummyInput {
13+
values: Vec<u64>,
14+
multiplier: u64,
15+
}
416

517
#[allow(dead_code)]
618
fn dummy_function(n: u64) -> u64 {
719
// Simple function that does some work
820
(0..n).sum()
921
}
1022

11-
/// Example benchmark function that demonstrates how to use Criterion for benchmarking.
23+
/// Example benchmark functions to demonstrate how to use Criterion for benchmarking.
1224
/// This is used to test the benchmarking infrastructure and generate sample benchmark results
1325
/// that can be parsed by the bench_tools framework.
1426
#[allow(dead_code)]
@@ -19,5 +31,23 @@ fn dummy_benchmark(c: &mut Criterion) {
1931
c.bench_function("dummy_sum_1000", |b| b.iter(|| black_box(dummy_function(1000))));
2032
}
2133

22-
criterion_group!(benches, dummy_benchmark);
34+
#[allow(dead_code)]
35+
fn dummy_benchmark_with_input(c: &mut Criterion) {
36+
let process_input = |input: &DummyInput| input.values.iter().sum::<u64>() * input.multiplier;
37+
38+
let small_input: DummyInput = serde_json::from_str(SMALL_INPUT).unwrap();
39+
let large_input: DummyInput = serde_json::from_str(LARGE_INPUT).unwrap();
40+
41+
c.bench_function("dummy_process_small_input", |b| {
42+
// black_box prevents the compiler from optimizing away the function call during
43+
// benchmarking
44+
b.iter(|| black_box(process_input(&small_input)))
45+
});
46+
47+
c.bench_function("dummy_process_large_input", |b| {
48+
b.iter(|| black_box(process_input(&large_input)))
49+
});
50+
}
51+
52+
criterion_group!(benches, dummy_benchmark, dummy_benchmark_with_input);
2353
criterion_main!(benches);

0 commit comments

Comments
 (0)