-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
box_error.rs
60 lines (58 loc) · 1.76 KB
/
box_error.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 zino_core::error::Error;
pub fn bench(c: &mut criterion::Criterion) {
type BoxError = Box<dyn std::error::Error + 'static>;
c.bench_function("static_str_into_box_error", |b| {
b.iter(|| {
let message = "a string error";
BoxError::from(message)
})
});
c.bench_function("string_into_box_error", |b| {
b.iter(|| {
let message = String::from("a string error");
BoxError::from(message)
})
});
c.bench_function("parse_int_error_into_box_error", |b| {
b.iter(|| {
let err = "12.15".parse::<i32>().unwrap_err();
BoxError::from(err)
})
});
c.bench_function("static_str_into_anyhow_error", |b| {
b.iter(|| {
let message = "a string error";
anyhow::Error::msg(message)
})
});
c.bench_function("string_into_anyhow_error", |b| {
b.iter(|| {
let message = String::from("a string error");
anyhow::Error::msg(message)
})
});
c.bench_function("parse_int_error_into_anyhow_error", |b| {
b.iter(|| {
let err = "12.15".parse::<i32>().unwrap_err();
anyhow::Error::new(err)
})
});
c.bench_function("static_str_into_zino_error", |b| {
b.iter(|| {
let message = "a string error";
Error::new(message)
})
});
c.bench_function("string_into_zino_error", |b| {
b.iter(|| {
let message = String::from("a string error");
Error::new(message)
})
});
c.bench_function("parse_int_error_into_zino_error", |b| {
b.iter(|| {
let err = "12.15".parse::<i32>().unwrap_err();
Error::from(err)
})
});
}