Debian Codegraph @

debian/rust-vendor/codspeed-divan-compat-walltime/tests/attr_options.rs

raw
1 // Tests that attribute options produce the correct results.
2
3 // Miri cannot discover benchmarks.
4 #![cfg(not(miri))]
5
6 use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
7
8 extern crate codspeed_divan_compat_walltime as divan;
9 use divan::Divan;
10
11 static CHILD1_ITERS: AtomicUsize = AtomicUsize::new(0);
12 static CHILD2_ITERS: AtomicUsize = AtomicUsize::new(0);
13 static CHILD3_ITERS: AtomicUsize = AtomicUsize::new(0);
14
15 #[divan::bench_group(sample_count = 10, sample_size = 50)]
16 mod parent {
17 use super::*;
18
19 // 10 × 1 = 10
20 #[divan::bench_group(sample_size = 1)]
21 mod child1 {
22 use super::*;
23
24 #[divan::bench]
25 fn bench() {
26 CHILD1_ITERS.fetch_add(1, SeqCst);
27 }
28 }
29
30 // 42 × 50 = 2100
31 #[divan::bench_group(sample_count = 42)]
32 mod child2 {
33 use super::*;
34
35 #[divan::bench]
36 fn bench() {
37 CHILD2_ITERS.fetch_add(1, SeqCst);
38 }
39 }
40
41 mod child3 {
42 use super::*;
43
44 // 1 × 50 = 50
45 #[divan::bench(sample_count = 1)]
46 fn bench() {
47 CHILD3_ITERS.fetch_add(1, SeqCst);
48 }
49 }
50 }
51
52 #[test]
53 fn iter_count() {
54 Divan::default().run_benches();
55
56 assert_eq!(CHILD1_ITERS.load(SeqCst), 10);
57 assert_eq!(CHILD2_ITERS.load(SeqCst), 2100);
58 assert_eq!(CHILD3_ITERS.load(SeqCst), 50);
59 }