-
Notifications
You must be signed in to change notification settings - Fork 0
/
format_whitespace_leftalign.rs
42 lines (37 loc) · 1.19 KB
/
format_whitespace_leftalign.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
use criterion::{black_box, criterion_group, Criterion};
pub fn format_whitespace_10_leftalign(c: &mut Criterion) {
let width: usize = 10;
c.bench_function("format! ws 10 la", |b| {
b.iter(|| black_box(format!("{:<width$}", "hej")))
});
}
pub fn format_whitespace_100_leftalign(c: &mut Criterion) {
let width: usize = 100;
c.bench_function("format! ws 100 la", |b| {
b.iter(|| black_box(format!("{:<width$}", "bingbong")))
});
}
pub fn format_whitespace_1000_leftalign(c: &mut Criterion) {
let width: usize = 1000;
c.bench_function("format! ws 1000 la", |b| {
b.iter(|| black_box(format!("{:<width$}", "Undercity is a cool capital...")))
});
}
pub fn format_whitespace_10000_leftalign(c: &mut Criterion) {
let width: usize = 10000;
c.bench_function("format! ws 10000 la", |b| {
b.iter(|| {
black_box(format!(
"{:<width$}",
"¤)(åäöåa this is a very long string... xd"
))
})
});
}
criterion_group!(
formats,
format_whitespace_10_leftalign,
format_whitespace_100_leftalign,
format_whitespace_1000_leftalign,
format_whitespace_10000_leftalign,
);