-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtext_image.rs
60 lines (51 loc) · 1.76 KB
/
text_image.rs
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
use std::{fs::read_dir, time::Duration};
use aarty::*;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
fn to_text_bench(c: &mut Criterion) {
let mut images = Vec::new();
for entry in read_dir("samples").unwrap() {
let path = entry.unwrap().path();
images.push((path.clone(), image::open(path).unwrap()));
}
macro_rules! group {
($name: expr, $config: expr) => {{
let mut group = c.benchmark_group($name);
for (path, image) in &images {
group.bench_with_input(
BenchmarkId::from_parameter(path.to_str().unwrap()),
image,
|b, image| {
b.iter(|| {
let _ = image.to_text($config);
});
},
);
}
group.finish();
}};
}
group!(
"convert with no colors",
Config::new(vec![' ', '.', ',', '-', '~', '!', '*', '%', '$', '@', '#'].into())
);
group!(
"convert with foeground colors",
Config::new(vec![' ', '.', ',', '-', '~', '!', '*', '%', '$', '@', '#'].into())
.with_flags(COLORS)
);
group!(
"convert with foeground colors reversed",
Config::new(vec![' ', '.', ',', '-', '~', '!', '*', '%', '$', '@', '#'].into())
.with_flags(COLORS | REVERSE)
);
group!(
"convert with foeground colors reversed and empty set",
Config::new(Sympols::empty()).with_flags(COLORS | REVERSE)
);
}
criterion_group! {
name = benches;
config = Criterion::default().sample_size(10).with_plots().warm_up_time(Duration::from_millis(200));
targets = to_text_bench
}
criterion_main!(benches);