summaryrefslogtreecommitdiffstats
path: root/third_party/rust/adler/benches/bench.rs
blob: 0969f59483ef9ff6b0f1a9fd7e3d519c65405b16 (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
105
106
107
108
109
extern crate adler;
extern crate criterion;

use adler::{adler32_slice, Adler32};
use criterion::{criterion_group, criterion_main, Criterion, Throughput};

fn simple(c: &mut Criterion) {
    {
        const SIZE: usize = 100;

        let mut group = c.benchmark_group("simple-100b");
        group.throughput(Throughput::Bytes(SIZE as u64));
        group.bench_function("zeroes-100", |bencher| {
            bencher.iter(|| {
                adler32_slice(&[0; SIZE]);
            });
        });
        group.bench_function("ones-100", |bencher| {
            bencher.iter(|| {
                adler32_slice(&[0xff; SIZE]);
            });
        });
    }

    {
        const SIZE: usize = 1024;

        let mut group = c.benchmark_group("simple-1k");
        group.throughput(Throughput::Bytes(SIZE as u64));

        group.bench_function("zeroes-1k", |bencher| {
            bencher.iter(|| {
                adler32_slice(&[0; SIZE]);
            });
        });

        group.bench_function("ones-1k", |bencher| {
            bencher.iter(|| {
                adler32_slice(&[0xff; SIZE]);
            });
        });
    }

    {
        const SIZE: usize = 1024 * 1024;

        let mut group = c.benchmark_group("simple-1m");
        group.throughput(Throughput::Bytes(SIZE as u64));
        group.bench_function("zeroes-1m", |bencher| {
            bencher.iter(|| {
                adler32_slice(&[0; SIZE]);
            });
        });

        group.bench_function("ones-1m", |bencher| {
            bencher.iter(|| {
                adler32_slice(&[0xff; SIZE]);
            });
        });
    }
}

fn chunked(c: &mut Criterion) {
    const SIZE: usize = 16 * 1024 * 1024;

    let data = vec![0xAB; SIZE];

    let mut group = c.benchmark_group("chunked-16m");
    group.throughput(Throughput::Bytes(SIZE as u64));
    group.bench_function("5552", |bencher| {
        bencher.iter(|| {
            let mut h = Adler32::new();
            for chunk in data.chunks(5552) {
                h.write_slice(chunk);
            }
            h.checksum()
        });
    });
    group.bench_function("8k", |bencher| {
        bencher.iter(|| {
            let mut h = Adler32::new();
            for chunk in data.chunks(8 * 1024) {
                h.write_slice(chunk);
            }
            h.checksum()
        });
    });
    group.bench_function("64k", |bencher| {
        bencher.iter(|| {
            let mut h = Adler32::new();
            for chunk in data.chunks(64 * 1024) {
                h.write_slice(chunk);
            }
            h.checksum()
        });
    });
    group.bench_function("1m", |bencher| {
        bencher.iter(|| {
            let mut h = Adler32::new();
            for chunk in data.chunks(1024 * 1024) {
                h.write_slice(chunk);
            }
            h.checksum()
        });
    });
}

criterion_group!(benches, simple, chunked);
criterion_main!(benches);