bench_compare/
bench_compare.rs1use tiny_bench::black_box;
2
3fn main() {
4 let label = "compare_functions";
5 tiny_bench::bench_labeled(label, my_slow_function);
6 tiny_bench::bench_labeled(label, my_faster_function);
7}
8
9fn my_slow_function() {
10 let mut num_iters = 0;
11 for _ in 0..10_000 {
12 num_iters += black_box(1);
13 }
14 assert_eq!(10_000, black_box(num_iters));
15}
16
17fn my_faster_function() {
18 let mut num_iters = 0;
19 for _ in 0..5_000 {
20 num_iters += black_box(1);
21 }
22 assert_eq!(5_000, black_box(num_iters));
23}