summaryrefslogtreecommitdiff
path: root/benches/bench_sm.rs
blob: 25dd3cc3abaaf8e3fd07b876067ad24d35d98b42 (plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//! This file benchmarks the `sm` function.

use criterion::{black_box, criterion_group, criterion_main, Criterion};

use rand::{
    distributions::{Distribution, Uniform},
    thread_rng,
};

#[allow(unused_imports)]
use sort::{sm, smi};

fn bench_10(c: &mut Criterion) {
    let mut rng = thread_rng();

    let input = {
        let uniform = Uniform::new(-100.0f32, 100.0f32);
        uniform.sample_iter(&mut rng).take(10).collect::<Vec<_>>()
    };

    assert_eq!(input.len(), 10);

    c.bench_function("smi", |b| {
        b.iter(|| {
            let mut count = 0;
            black_box(smi(input.as_slice(), &mut count))
        })
    });
}

fn bench_20(c: &mut Criterion) {
    let mut rng = thread_rng();

    let input = {
        let uniform = Uniform::new(-100.0f32, 100.0f32);
        uniform.sample_iter(&mut rng).take(20).collect::<Vec<_>>()
    };

    assert_eq!(input.len(), 20);

    c.bench_function("smi", |b| {
        b.iter(|| {
            let mut count = 0;
            black_box(smi(input.as_slice(), &mut count))
        })
    });
}

fn bench_40(c: &mut Criterion) {
    let mut rng = thread_rng();

    let input = {
        let uniform = Uniform::new(-100.0f32, 100.0f32);
        uniform.sample_iter(&mut rng).take(40).collect::<Vec<_>>()
    };

    assert_eq!(input.len(), 40);

    c.bench_function("smi", |b| {
        b.iter(|| {
            let mut count = 0;
            black_box(smi(input.as_slice(), &mut count))
        })
    });
}

fn bench_80(c: &mut Criterion) {
    let mut rng = thread_rng();

    let input = {
        let uniform = Uniform::new(-100.0f32, 100.0f32);
        uniform.sample_iter(&mut rng).take(80).collect::<Vec<_>>()
    };

    assert_eq!(input.len(), 80);

    c.bench_function("smi", |b| {
        b.iter(|| {
            let mut count = 0;
            black_box(smi(input.as_slice(), &mut count))
        })
    });
}

fn bench_160(c: &mut Criterion) {
    let mut rng = thread_rng();

    let input = {
        let uniform = Uniform::new(-100.0f32, 100.0f32);
        uniform.sample_iter(&mut rng).take(160).collect::<Vec<_>>()
    };

    assert_eq!(input.len(), 160);

    c.bench_function("smi", |b| {
        b.iter(|| {
            let mut count = 0;
            black_box(smi(input.as_slice(), &mut count))
        })
    });
}

criterion_group!(benches, bench_10, bench_20, bench_40, bench_80, bench_160);
criterion_main!(benches);