summaryrefslogtreecommitdiffstats
path: root/third_party/rust/leb128/benches/bench.rs
blob: d634306dd5805fa876e5ebbe336ac1464d2a1518 (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
#![feature(test)]

extern crate test;
use leb128;

#[bench]
fn write_signed(b: &mut test::Bencher) {
    let mut buf = [0; 4096];

    b.iter(|| {
        let mut writable = &mut buf[..];
        for i in -1025..1025 {
            test::black_box(leb128::write::signed(&mut writable, i).unwrap());
        }
    });
}

#[bench]
fn write_unsigned(b: &mut test::Bencher) {
    let mut buf = [0; 4096];

    b.iter(|| {
        let mut writable = &mut buf[..];
        for i in 0..2050 {
            test::black_box(leb128::write::unsigned(&mut writable, i).unwrap());
        }
    });
}

#[bench]
fn read_signed(b: &mut test::Bencher) {
    let mut buf = [0; 4096];

    {
        let mut writable = &mut buf[..];
        for i in -1025..1025 {
            leb128::write::signed(&mut writable, i).unwrap();
        }
    }

    b.iter(|| {
        let mut readable = &buf[..];
        for _ in -1025..1025 {
            test::black_box(leb128::read::signed(&mut readable).unwrap());
        }
    });
}

#[bench]
fn read_unsigned(b: &mut test::Bencher) {
    let mut buf = [0; 4096];

    {
        let mut writable = &mut buf[..];
        for i in 0..2050 {
            leb128::write::unsigned(&mut writable, i).unwrap();
        }
    }

    b.iter(|| {
        let mut readable = &buf[..];
        for _ in 0..2050 {
            test::black_box(leb128::read::unsigned(&mut readable).unwrap());
        }
    });
}