summaryrefslogtreecommitdiffstats
path: root/vendor/anstream/benches/stream.rs
blob: 55c20b89682dbb300821a32fdb0c9cfd8c91ff6d (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
use std::io::Write as _;

use criterion::{black_box, Criterion};

fn stream(c: &mut Criterion) {
    for (name, content) in [
        ("demo.vte", &include_bytes!("../tests/demo.vte")[..]),
        ("rg_help.vte", &include_bytes!("../tests/rg_help.vte")[..]),
        ("rg_linus.vte", &include_bytes!("../tests/rg_linus.vte")[..]),
        (
            "state_changes",
            &b"\x1b]2;X\x1b\\ \x1b[0m \x1bP0@\x1b\\"[..],
        ),
    ] {
        let mut group = c.benchmark_group(name);
        group.bench_function("nop", |b| {
            b.iter(|| {
                let buffer = anstream::Buffer::with_capacity(content.len());
                let mut stream = buffer;

                stream.write_all(content).unwrap();

                black_box(stream)
            })
        });
        group.bench_function("StripStream", |b| {
            b.iter(|| {
                let buffer = anstream::Buffer::with_capacity(content.len());
                let mut stream = anstream::StripStream::new(buffer);

                stream.write_all(content).unwrap();

                black_box(stream)
            })
        });
        #[cfg(all(windows, feature = "wincon"))]
        group.bench_function("WinconStream", |b| {
            b.iter(|| {
                let buffer = anstream::Buffer::with_capacity(content.len());
                let mut stream =
                    anstream::WinconStream::new(anstyle_wincon::Console::new(buffer).unwrap());

                stream.write_all(content).unwrap();

                black_box(stream)
            })
        });
        group.bench_function("AutoStream::always_ansi", |b| {
            b.iter(|| {
                let buffer = anstream::Buffer::with_capacity(content.len());
                let mut stream = anstream::AutoStream::always_ansi(buffer);

                stream.write_all(content).unwrap();

                black_box(stream)
            })
        });
        group.bench_function("AutoStream::always", |b| {
            b.iter(|| {
                let buffer = anstream::Buffer::with_capacity(content.len());
                let mut stream = anstream::AutoStream::always(buffer);

                stream.write_all(content).unwrap();

                black_box(stream)
            })
        });
        group.bench_function("AutoStream::never", |b| {
            b.iter(|| {
                let buffer = anstream::Buffer::with_capacity(content.len());
                let mut stream = anstream::AutoStream::never(buffer);

                stream.write_all(content).unwrap();

                black_box(stream)
            })
        });
    }
}

criterion::criterion_group!(benches, stream);
criterion::criterion_main!(benches);