|
8 | 8 | // option. This file may not be copied, modified, or distributed
|
9 | 9 | // except according to those terms.
|
10 | 10 |
|
| 11 | +// Naming the benchmarks using uppercase letters helps them sort |
| 12 | +// better. |
| 13 | +#![allow(non_snake_case)] |
| 14 | + |
11 | 15 | #[cfg(feature = "bench")]
|
12 | 16 | extern crate test;
|
13 | 17 | #[cfg(feature = "bench")]
|
@@ -112,16 +116,94 @@ fn big_array_bench_generic<S: UnificationStore<Key=UnitKey, Value=()>>(b: &mut B
|
112 | 116 |
|
113 | 117 | #[cfg(feature = "bench")]
|
114 | 118 | #[bench]
|
115 |
| -fn big_array_bench_in_place(b: &mut Bencher) { |
| 119 | +fn big_array_bench_InPlace(b: &mut Bencher) { |
116 | 120 | big_array_bench_generic::<InPlace<UnitKey>>(b);
|
117 | 121 | }
|
118 | 122 |
|
119 | 123 | #[cfg(all(feature = "bench", feature = "persistent"))]
|
120 | 124 | #[bench]
|
121 |
| -fn big_array_bench_persistent(b: &mut Bencher) { |
| 125 | +fn big_array_bench_Persistent(b: &mut Bencher) { |
122 | 126 | big_array_bench_generic::<Persistent<UnitKey>>(b);
|
123 | 127 | }
|
124 | 128 |
|
| 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 | + |
125 | 207 | #[test]
|
126 | 208 | fn even_odd() {
|
127 | 209 | all_modes! {
|
|
0 commit comments