-
-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathcollections.rs
More file actions
88 lines (78 loc) · 1.8 KB
/
Copy pathcollections.rs
File metadata and controls
88 lines (78 loc) · 1.8 KB
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
//! Run with:
//!
//! ```sh
//! cargo bench -q -p examples --bench collections
//! ```
use std::collections::{BTreeSet, BinaryHeap, HashSet, LinkedList, VecDeque};
use divan::{black_box, Bencher};
mod util;
fn main() {
divan::main();
}
const LENS: &[usize] = &[0, 8, 64, 1024];
#[divan::bench(types = [
Vec<i32>,
VecDeque<i32>,
LinkedList<i32>,
BinaryHeap<i32>,
HashSet<i32>,
BTreeSet<i32>,
])]
fn default<T: Default>() -> T {
T::default()
}
#[divan::bench(
types = [
Vec<i32>,
VecDeque<i32>,
BinaryHeap<i32>,
HashSet<i32>,
],
consts = LENS,
)]
fn with_capacity<T: util::WithCapacity, const N: usize>(bencher: Bencher) {
bencher.counter(N).bench(|| T::with_capacity(black_box(N)))
}
#[divan::bench(
types = [
Vec<i32>,
VecDeque<i32>,
LinkedList<i32>,
BinaryHeap<i32>,
HashSet<i32>,
BTreeSet<i32>,
],
consts = LENS,
)]
fn from_iter<T: FromIterator<i32>, const N: usize>(bencher: Bencher) {
bencher.counter(N).bench(|| util::collect_nums::<T>(N))
}
#[divan::bench(
types = [
Vec<i32>,
VecDeque<i32>,
LinkedList<i32>,
BinaryHeap<i32>,
HashSet<i32>,
BTreeSet<i32>,
],
consts = LENS,
)]
fn drop<T: FromIterator<i32>, const N: usize>(bencher: Bencher) {
bencher.counter(N).with_inputs(|| util::collect_nums::<T>(N)).bench_values(std::mem::drop);
}
#[divan::bench(
types = [
Vec<i32>,
VecDeque<i32>,
LinkedList<i32>,
BinaryHeap<i32>,
HashSet<i32>,
BTreeSet<i32>,
],
consts = LENS,
max_time = 1,
)]
fn clear<T: FromIterator<i32> + util::Clear, const N: usize>(bencher: Bencher) {
bencher.counter(N).with_inputs(|| util::collect_nums::<T>(N)).bench_refs(T::clear);
}