File: attr_options.rs

package info (click to toggle)
rust-divan 0.1.21-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 580 kB
  • sloc: makefile: 2
file content (58 lines) | stat: -rw-r--r-- 1,284 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Tests that attribute options produce the correct results.

// Miri cannot discover benchmarks.
#![cfg(not(miri))]

use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};

use divan::Divan;

static CHILD1_ITERS: AtomicUsize = AtomicUsize::new(0);
static CHILD2_ITERS: AtomicUsize = AtomicUsize::new(0);
static CHILD3_ITERS: AtomicUsize = AtomicUsize::new(0);

#[divan::bench_group(sample_count = 10, sample_size = 50)]
mod parent {
    use super::*;

    // 10 × 1 = 10
    #[divan::bench_group(sample_size = 1)]
    mod child1 {
        use super::*;

        #[divan::bench]
        fn bench() {
            CHILD1_ITERS.fetch_add(1, SeqCst);
        }
    }

    // 42 × 50 = 2100
    #[divan::bench_group(sample_count = 42)]
    mod child2 {
        use super::*;

        #[divan::bench]
        fn bench() {
            CHILD2_ITERS.fetch_add(1, SeqCst);
        }
    }

    mod child3 {
        use super::*;

        // 1 × 50 = 50
        #[divan::bench(sample_count = 1)]
        fn bench() {
            CHILD3_ITERS.fetch_add(1, SeqCst);
        }
    }
}

#[test]
fn iter_count() {
    Divan::default().run_benches();

    assert_eq!(CHILD1_ITERS.load(SeqCst), 10);
    assert_eq!(CHILD2_ITERS.load(SeqCst), 2100);
    assert_eq!(CHILD3_ITERS.load(SeqCst), 50);
}