-
Notifications
You must be signed in to change notification settings - Fork 2
/
benches.rs
111 lines (101 loc) · 2.57 KB
/
benches.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#![feature(test)]
extern crate recycler;
extern crate test;
use test::Bencher;
use recycler::*;
#[bench]
fn recycler_vec_vec_str(bencher: &mut Bencher) {
let mut r1 = make_recycler::<Vec<Vec<String>>>();
bencher.iter(|| {
let v = { // scope the borrow of r1
let (mut v1, r2) = r1.new();
for _ in 0..10 {
let (mut v2, r3) = r2.new();
for _ in 0..10 {
v2.push(r3.new_from("test!"));
}
v1.push(v2);
}
v1
};
r1.recycle(v);
});
}
#[bench]
fn allocate_vec_vec_str(bencher: &mut Bencher) {
bencher.iter(|| {
let mut v1 = Vec::with_capacity(10);
for _ in 0..10 {
let mut v2 = Vec::with_capacity(10);
for _ in 0..10 {
v2.push(("test!").to_owned());
}
v1.push(v2);
}
v1
});
}
#[bench]
fn recreate_vec_vec_str(bencher: &mut Bencher) {
let mut recycler = make_recycler::<Vec<Vec<String>>>();
let data = vec![vec!["test!".to_owned(); 10]; 10];
bencher.iter(|| {
let record = recycler.recreate(&data);
recycler.recycle(record);
});
}
#[bench]
fn clone_vec_vec_str(bencher: &mut Bencher) {
let data = vec![vec!["test!".to_owned(); 10]; 10];
bencher.iter(|| {
data.clone()
});
}
#[bench]
fn recycler_vec_vec_u64(bencher: &mut Bencher) {
let mut r1 = make_recycler::<Vec<Vec<u64>>>();
bencher.iter(move || {
let v = { // scope the borrow of r1
let (mut v1, r2) = r1.new();
for _ in 0..10 {
let (mut v2, _r3) = r2.new();
for _ in 0..10 {
v2.push(0u64);
}
v1.push(v2);
}
v1
};
r1.recycle(v);
});
}
#[bench]
fn allocate_vec_vec_u64(bencher: &mut Bencher) {
bencher.iter(|| {
let mut v1 = Vec::with_capacity(10);
for _ in 0..10 {
let mut v2 = Vec::with_capacity(10);
for _ in 0..10 {
v2.push(0u64);
}
v1.push(v2);
}
v1
});
}
#[bench]
fn recreate_vec_vec_u64(bencher: &mut Bencher) {
let mut recycler = make_recycler::<Vec<Vec<u64>>>();
let data = vec![vec![0u64; 10]; 10];
bencher.iter(|| {
let record = recycler.recreate(&data);
recycler.recycle(record);
});
}
#[bench]
fn clone_vec_vec_u64(bencher: &mut Bencher) {
let data = vec![vec![0u64; 10]; 10];
bencher.iter(|| {
data.clone()
});
}