summaryrefslogtreecommitdiffstats
path: root/third_party/rust/line-wrap/benches/benchmarks.rs
blob: a8d84948dc281e7ab256c4bb8ff3bec8f71d31bc (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
#![feature(test)]

extern crate line_wrap;
extern crate test;

use test::Bencher;

#[bench]
fn wrap_10_10_lf(b: &mut Bencher) {
    do_wrap_bench(b, 10, 10, &line_wrap::lf());
}

#[bench]
fn wrap_10_10_crlf(b: &mut Bencher) {
    do_wrap_bench(b, 10, 10, &line_wrap::crlf());
}

#[bench]
fn wrap_10_1_lf(b: &mut Bencher) {
    do_wrap_bench(b, 10, 1, &line_wrap::lf());
}

#[bench]
fn wrap_10_1_crlf(b: &mut Bencher) {
    do_wrap_bench(b, 10, 1, &line_wrap::crlf());
}

#[bench]
fn wrap_100_10_lf(b: &mut Bencher) {
    do_wrap_bench(b, 100, 10, &line_wrap::lf());
}

#[bench]
fn wrap_100_10_crlf(b: &mut Bencher) {
    do_wrap_bench(b, 100, 10, &line_wrap::crlf());
}

#[bench]
fn wrap_100_10_slice_10(b: &mut Bencher) {
    let bytes = vec![b'\n', 10];
    let line_ending = line_wrap::SliceLineEnding::new(&bytes);
    do_wrap_bench(b, 100, 10, &line_ending);
}

#[bench]
fn wrap_100_1_lf(b: &mut Bencher) {
    do_wrap_bench(b, 100, 1, &line_wrap::lf());
}

#[bench]
fn wrap_100_1_crlf(b: &mut Bencher) {
    do_wrap_bench(b, 100, 1, &line_wrap::crlf());
}

#[bench]
fn wrap_1000_100_lf(b: &mut Bencher) {
    do_wrap_bench(b, 1000, 100, &line_wrap::lf());
}

#[bench]
fn wrap_1000_100_crlf(b: &mut Bencher) {
    do_wrap_bench(b, 1000, 100, &line_wrap::crlf());
}

#[bench]
fn wrap_10000_100_lf(b: &mut Bencher) {
    do_wrap_bench(b, 10000, 100, &line_wrap::lf());
}

#[bench]
fn wrap_10000_100_crlf(b: &mut Bencher) {
    do_wrap_bench(b, 10000, 100, &line_wrap::crlf());
}

#[bench]
fn wrap_10000_100_slice_1(b: &mut Bencher) {
    let line_ending = line_wrap::SliceLineEnding::new(b"\n");

    do_wrap_bench(b, 10000, 100, &line_ending);
}

#[bench]
fn wrap_10000_100_slice_10(b: &mut Bencher) {
    let bytes = vec![b'\n', 10];
    let line_ending = line_wrap::SliceLineEnding::new(&bytes);

    do_wrap_bench(b, 10000, 100, &line_ending);
}

fn do_wrap_bench<L: line_wrap::LineEnding>(b: &mut Bencher, input_len: usize, line_len: usize, line_ending: &L) {
    let mut v = vec![0_u8; input_len + input_len / line_len * line_ending.len()];

    b.bytes = input_len as u64;
    b.iter(|| {
        line_wrap::line_wrap(&mut v, input_len, line_len, line_ending);
    })
}