forked from fereidani/rust-channel-benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathz_types.rs
63 lines (53 loc) · 1.32 KB
/
z_types.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
61
62
63
trait BenchType: Send + Sync {
fn new(v: usize) -> Self;
// ensure that received data is tested and used to avoid compiler optimizer removing receive part.
fn test(&self);
}
struct BenchEmpty {}
struct BenchUsize {
a: usize,
}
struct BenchFixedArray([usize; 4]);
struct BenchBoxed(Box<BenchFixedArray>);
impl BenchType for BenchEmpty {
fn new(_v: usize) -> Self {
Self {}
}
#[inline(always)]
fn test(&self) {}
}
impl BenchType for BenchUsize {
fn new(v: usize) -> Self {
return Self { a: v };
}
#[inline(always)]
fn test(&self) {
if self.a < 1 {
panic!("invalid_value")
}
}
}
impl BenchType for BenchFixedArray {
fn new(v: usize) -> Self {
return BenchFixedArray([v; 4]);
}
#[inline(always)]
fn test(&self) {
// only to ensure result is being used and compiler does not remove bench type
if self.0[0] < 1 {
panic!("invalid_value")
}
}
}
impl BenchType for BenchBoxed {
fn new(v: usize) -> Self {
return BenchBoxed(BenchFixedArray([v; 4]).into());
}
#[inline(always)]
fn test(&self) {
// only to ensure result is being used and compiler does not remove bench type
if self.0 .0[0] < 1 {
panic!("invalid_value")
}
}
}