Skip to content

Commit a9b33eb

Browse files
committed
modify benchmarks to support either in-place or persistent
1 parent dcf84c5 commit a9b33eb

File tree

1 file changed

+84
-2
lines changed

1 file changed

+84
-2
lines changed

src/unify/tests.rs

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// Naming the benchmarks using uppercase letters helps them sort
12+
// better.
13+
#![allow(non_snake_case)]
14+
1115
#[cfg(feature = "bench")]
1216
extern crate test;
1317
#[cfg(feature = "bench")]
@@ -112,16 +116,94 @@ fn big_array_bench_generic<S: UnificationStore<Key=UnitKey, Value=()>>(b: &mut B
112116

113117
#[cfg(feature = "bench")]
114118
#[bench]
115-
fn big_array_bench_in_place(b: &mut Bencher) {
119+
fn big_array_bench_InPlace(b: &mut Bencher) {
116120
big_array_bench_generic::<InPlace<UnitKey>>(b);
117121
}
118122

119123
#[cfg(all(feature = "bench", feature = "persistent"))]
120124
#[bench]
121-
fn big_array_bench_persistent(b: &mut Bencher) {
125+
fn big_array_bench_Persistent(b: &mut Bencher) {
122126
big_array_bench_generic::<Persistent<UnitKey>>(b);
123127
}
124128

129+
#[cfg(feature = "bench")]
130+
fn big_array_bench_in_snapshot_generic<S: UnificationStore<Key=UnitKey, Value=()>>(b: &mut Bencher) {
131+
let mut ut: UnificationTable<S> = UnificationTable::new();
132+
let mut keys = Vec::new();
133+
const MAX: usize = 1 << 15;
134+
135+
for _ in 0..MAX {
136+
keys.push(ut.new_key(()));
137+
}
138+
139+
b.iter(|| {
140+
let snapshot = ut.snapshot();
141+
142+
for i in 1..MAX {
143+
let l = keys[i - 1];
144+
let r = keys[i];
145+
ut.union(l, r);
146+
}
147+
148+
for i in 0..MAX {
149+
assert!(ut.unioned(keys[0], keys[i]));
150+
}
151+
152+
ut.rollback_to(snapshot);
153+
})
154+
}
155+
156+
#[cfg(feature = "bench")]
157+
#[bench]
158+
fn big_array_bench_in_snapshot_InPlace(b: &mut Bencher) {
159+
big_array_bench_in_snapshot_generic::<InPlace<UnitKey>>(b);
160+
}
161+
162+
#[cfg(all(feature = "bench", feature = "persistent"))]
163+
#[bench]
164+
fn big_array_bench_in_snapshot_Persistent(b: &mut Bencher) {
165+
big_array_bench_in_snapshot_generic::<Persistent<UnitKey>>(b);
166+
}
167+
168+
#[cfg(feature = "bench")]
169+
fn big_array_bench_clone_generic<S: UnificationStore<Key=UnitKey, Value=()>>(b: &mut Bencher) {
170+
let mut ut: UnificationTable<S> = UnificationTable::new();
171+
let mut keys = Vec::new();
172+
const MAX: usize = 1 << 15;
173+
174+
for _ in 0..MAX {
175+
keys.push(ut.new_key(()));
176+
}
177+
178+
b.iter(|| {
179+
let saved_table = ut.clone();
180+
181+
for i in 1..MAX {
182+
let l = keys[i - 1];
183+
let r = keys[i];
184+
ut.union(l, r);
185+
}
186+
187+
for i in 0..MAX {
188+
assert!(ut.unioned(keys[0], keys[i]));
189+
}
190+
191+
ut = saved_table;
192+
})
193+
}
194+
195+
#[cfg(feature = "bench")]
196+
#[bench]
197+
fn big_array_bench_clone_InPlace(b: &mut Bencher) {
198+
big_array_bench_clone_generic::<InPlace<UnitKey>>(b);
199+
}
200+
201+
#[cfg(all(feature = "bench", feature = "persistent"))]
202+
#[bench]
203+
fn big_array_bench_clone_Persistent(b: &mut Bencher) {
204+
big_array_bench_clone_generic::<Persistent<UnitKey>>(b);
205+
}
206+
125207
#[test]
126208
fn even_odd() {
127209
all_modes! {

0 commit comments

Comments
 (0)