Skip to content

Commit 4b86220

Browse files
committed
include sip13
1 parent 17d773d commit 4b86220

File tree

5 files changed

+329
-76
lines changed

5 files changed

+329
-76
lines changed

Cargo.lock

Lines changed: 60 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ Benchmarks of various hashers: http://cglab.ca/~abeinges/blah/hash-rs/
44
To build the results, run `cargo run` (this will in turn run Cargo bench in the background).
55
This will produce some csv's that index.html will consume.
66

7+
To see the resutlts run `python -m SimpleHTTPServer 8000` at the root folder and navigate to http://localhost:8000
8+
79
Currently only Sip, Fnv, Farm, and XX are supported. Other hasher crates were in an inappropriate state.
810
Patches to change this welcome!
911

1012
This does not necessarily reflect the quality of the algorithms themselves, but rather the performance
11-
of the implementations when used with Rust's hasher infrastructure.
13+
of the implementations when used with Rust's hasher infrastructure.
1214

1315
I would like to bench different workloads in the future (everything has been set up to enable this generically).

index.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE HTML>
22
<html>
33
<head>
4-
<script src="//cdnjs.cloudflare.com/ajax/libs/dygraph/1.1.1/dygraph-combined.js"></script>
4+
<script src="http://cdnjs.cloudflare.com/ajax/libs/dygraph/1.1.1/dygraph-combined.js"></script>
55

66
<style>
77
.dygraph-legend {
@@ -173,14 +173,13 @@
173173
"bytes hashed");
174174

175175
makeBench("mapcountdense",
176-
"Counting number of occurrences of 1000 byte-strings (mostly duplicates)",
176+
"Counting number of occurrences of X byte-strings (mostly duplicates)",
177177
"bytes per string");
178178

179179
makeBench("mapcountsparse",
180-
"Counting number of occurrences of 1000 byte-strings (mostly unique)",
180+
"Counting number of occurrences of X byte-strings (mostly unique)",
181181
"bytes per string");
182182

183183
</script>
184184
</body>
185185
</html>
186-

src/main.rs

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ extern crate rand;
1515
extern crate btree_rewrite;
1616

1717
mod multiply_shift;
18+
mod sip_opt;
1819

1920
use std::process::{Stdio, Command};
2021
use std::io::Result as IoResult;
@@ -128,9 +129,9 @@ macro_rules! hash_benches {
128129
use blake2_rfc::blake2s::Blake2s;
129130
use _fnv::FnvHasher as Fnv;
130131
use farmhash::FarmHasher as Farm;
131-
use std::hash::Hasher;
132-
use std::collections::hash_state::{DefaultState, HashState};
132+
use std::hash::{Hasher, BuildHasher, BuildHasherDefault};
133133
use multiply_shift::HornerHasher;
134+
use sip_opt::SipHasher as SipOpt;
134135

135136
use std::collections::HashMap;
136137
use test::{black_box, Bencher};
@@ -140,13 +141,13 @@ macro_rules! hash_benches {
140141
fn hasher_bench<H>(b: B, len: usize)
141142
where H: Hasher + Default
142143
{
143-
let hash_state = DefaultState::<H>::default();
144+
let hash_state = BuildHasherDefault::<H>::default();
144145
let bytes: Vec<u8> = (0..100).cycle().take(len).collect();
145146
let bytes = black_box(bytes);
146147

147148
b.bytes = bytes.len() as u64;
148149
b.iter(|| {
149-
let mut hasher = hash_state.hasher();
150+
let mut hasher = hash_state.build_hasher();
150151
hasher.write(&bytes);
151152
hasher.finish()
152153
});
@@ -163,9 +164,9 @@ macro_rules! hash_benches {
163164
b.bytes = (len * num_strings) as u64;
164165
b.iter(|| {
165166
// don't reserve space to be fair to BTree
166-
let mut map = HashMap::with_hash_state(DefaultState::<H>::default());
167+
let mut map = HashMap::with_hasher(BuildHasherDefault::<H>::default());
167168
for chunk in data.chunks(len) {
168-
*map.entry(chunk).or_insert(0) += 1;
169+
*map.entry(chunk).or_insert(0usize) += 1;
169170
}
170171
map
171172
});
@@ -183,15 +184,15 @@ macro_rules! hash_benches {
183184
b.bytes = (len * num_strings) as u64;
184185
b.iter(|| {
185186
// don't reserve space to be fair to BTree
186-
let mut map = HashMap::with_hash_state(DefaultState::<H>::default());
187+
let mut map = HashMap::with_hasher(BuildHasherDefault::<H>::default());
187188
for chunk in data.chunks(len) {
188-
*map.entry(chunk).or_insert(0) += 1;
189+
*map.entry(chunk).or_insert(0usize) += 1;
189190
}
190191
map
191192
});
192193
}
193194

194-
#[bench] fn bytes_000000001(b: B) { hasher_bench::<$Impl>(b, 1) }
195+
// #[bench] fn bytes_000000001(b: B) { hasher_bench::<$Impl>(b, 1) }
195196
#[bench] fn bytes_000000002(b: B) { hasher_bench::<$Impl>(b, 2) }
196197
#[bench] fn bytes_000000004(b: B) { hasher_bench::<$Impl>(b, 4) }
197198
#[bench] fn bytes_000000008(b: B) { hasher_bench::<$Impl>(b, 8) }
@@ -200,11 +201,11 @@ macro_rules! hash_benches {
200201
#[bench] fn bytes_000000064(b: B) { hasher_bench::<$Impl>(b, 64) }
201202
#[bench] fn bytes_000000128(b: B) { hasher_bench::<$Impl>(b, 128) }
202203
#[bench] fn bytes_000000256(b: B) { hasher_bench::<$Impl>(b, 256) }
203-
#[bench] fn bytes_000000512(b: B) { hasher_bench::<$Impl>(b, 512) }
204-
#[bench] fn bytes_000001024(b: B) { hasher_bench::<$Impl>(b, 1024) }
205-
#[bench] fn bytes_000002048(b: B) { hasher_bench::<$Impl>(b, 2048) }
204+
// #[bench] fn bytes_000000512(b: B) { hasher_bench::<$Impl>(b, 512) }
205+
// #[bench] fn bytes_000001024(b: B) { hasher_bench::<$Impl>(b, 1024) }
206+
// #[bench] fn bytes_000002048(b: B) { hasher_bench::<$Impl>(b, 2048) }
206207

207-
#[bench] fn mapcountsparse_000000001(b: B) { map_bench_sparse::<$Impl>(b, 1) }
208+
// #[bench] fn mapcountsparse_000000001(b: B) { map_bench_sparse::<$Impl>(b, 1) }
208209
#[bench] fn mapcountsparse_000000002(b: B) { map_bench_sparse::<$Impl>(b, 2) }
209210
#[bench] fn mapcountsparse_000000004(b: B) { map_bench_sparse::<$Impl>(b, 4) }
210211
#[bench] fn mapcountsparse_000000008(b: B) { map_bench_sparse::<$Impl>(b, 8) }
@@ -213,11 +214,11 @@ macro_rules! hash_benches {
213214
#[bench] fn mapcountsparse_000000064(b: B) { map_bench_sparse::<$Impl>(b, 64) }
214215
#[bench] fn mapcountsparse_000000128(b: B) { map_bench_sparse::<$Impl>(b, 128) }
215216
#[bench] fn mapcountsparse_000000256(b: B) { map_bench_sparse::<$Impl>(b, 256) }
216-
#[bench] fn mapcountsparse_000000512(b: B) { map_bench_sparse::<$Impl>(b, 512) }
217-
#[bench] fn mapcountsparse_000001024(b: B) { map_bench_sparse::<$Impl>(b, 1024) }
218-
#[bench] fn mapcountsparse_000002048(b: B) { map_bench_sparse::<$Impl>(b, 2048) }
217+
// #[bench] fn mapcountsparse_000000512(b: B) { map_bench_sparse::<$Impl>(b, 512) }
218+
// #[bench] fn mapcountsparse_000001024(b: B) { map_bench_sparse::<$Impl>(b, 1024) }
219+
// #[bench] fn mapcountsparse_000002048(b: B) { map_bench_sparse::<$Impl>(b, 2048) }
219220

220-
#[bench] fn mapcountdense_000000001(b: B) { map_bench_dense::<$Impl>(b, 1) }
221+
// #[bench] fn mapcountdense_000000001(b: B) { map_bench_dense::<$Impl>(b, 1) }
221222
#[bench] fn mapcountdense_000000002(b: B) { map_bench_dense::<$Impl>(b, 2) }
222223
#[bench] fn mapcountdense_000000004(b: B) { map_bench_dense::<$Impl>(b, 4) }
223224
#[bench] fn mapcountdense_000000008(b: B) { map_bench_dense::<$Impl>(b, 8) }
@@ -226,16 +227,15 @@ macro_rules! hash_benches {
226227
#[bench] fn mapcountdense_000000064(b: B) { map_bench_dense::<$Impl>(b, 64) }
227228
#[bench] fn mapcountdense_000000128(b: B) { map_bench_dense::<$Impl>(b, 128) }
228229
#[bench] fn mapcountdense_000000256(b: B) { map_bench_dense::<$Impl>(b, 256) }
229-
#[bench] fn mapcountdense_000000512(b: B) { map_bench_dense::<$Impl>(b, 512) }
230-
#[bench] fn mapcountdense_000001024(b: B) { map_bench_dense::<$Impl>(b, 1024) }
231-
#[bench] fn mapcountdense_000002048(b: B) { map_bench_dense::<$Impl>(b, 2048) }
230+
// #[bench] fn mapcountdense_000000512(b: B) { map_bench_dense::<$Impl>(b, 512) }
231+
// #[bench] fn mapcountdense_000001024(b: B) { map_bench_dense::<$Impl>(b, 1024) }
232+
// #[bench] fn mapcountdense_000002048(b: B) { map_bench_dense::<$Impl>(b, 2048) }
232233
}
233234
}
234235

235236
macro_rules! tree_benches {
236237
($Impl: ty) => {
237238
use std::collections::BTreeMap as StdBTree;
238-
use btree_rewrite::map::BTreeMap as NewBTree;
239239

240240
use test::{black_box, Bencher};
241241
pub type B<'a> = &'a mut Bencher;
@@ -275,7 +275,7 @@ macro_rules! tree_benches {
275275
}
276276

277277

278-
#[bench] fn mapcountsparse_000000001(b: B) { map_bench_sparse(b, 1) }
278+
// #[bench] fn mapcountsparse_000000001(b: B) { map_bench_sparse(b, 1) }
279279
#[bench] fn mapcountsparse_000000002(b: B) { map_bench_sparse(b, 2) }
280280
#[bench] fn mapcountsparse_000000004(b: B) { map_bench_sparse(b, 4) }
281281
#[bench] fn mapcountsparse_000000008(b: B) { map_bench_sparse(b, 8) }
@@ -284,11 +284,11 @@ macro_rules! tree_benches {
284284
#[bench] fn mapcountsparse_000000064(b: B) { map_bench_sparse(b, 64) }
285285
#[bench] fn mapcountsparse_000000128(b: B) { map_bench_sparse(b, 128) }
286286
#[bench] fn mapcountsparse_000000256(b: B) { map_bench_sparse(b, 256) }
287-
#[bench] fn mapcountsparse_000000512(b: B) { map_bench_sparse(b, 512) }
288-
#[bench] fn mapcountsparse_000001024(b: B) { map_bench_sparse(b, 1024) }
289-
#[bench] fn mapcountsparse_000002048(b: B) { map_bench_sparse(b, 2048) }
287+
// #[bench] fn mapcountsparse_000000512(b: B) { map_bench_sparse(b, 512) }
288+
// #[bench] fn mapcountsparse_000001024(b: B) { map_bench_sparse(b, 1024) }
289+
// #[bench] fn mapcountsparse_000002048(b: B) { map_bench_sparse(b, 2048) }
290290

291-
#[bench] fn mapcountdense_000000001(b: B) { map_bench_dense(b, 1) }
291+
// #[bench] fn mapcountdense_000000001(b: B) { map_bench_dense(b, 1) }
292292
#[bench] fn mapcountdense_000000002(b: B) { map_bench_dense(b, 2) }
293293
#[bench] fn mapcountdense_000000004(b: B) { map_bench_dense(b, 4) }
294294
#[bench] fn mapcountdense_000000008(b: B) { map_bench_dense(b, 8) }
@@ -297,9 +297,9 @@ macro_rules! tree_benches {
297297
#[bench] fn mapcountdense_000000064(b: B) { map_bench_dense(b, 64) }
298298
#[bench] fn mapcountdense_000000128(b: B) { map_bench_dense(b, 128) }
299299
#[bench] fn mapcountdense_000000256(b: B) { map_bench_dense(b, 256) }
300-
#[bench] fn mapcountdense_000000512(b: B) { map_bench_dense(b, 512) }
301-
#[bench] fn mapcountdense_000001024(b: B) { map_bench_dense(b, 1024) }
302-
#[bench] fn mapcountdense_000002048(b: B) { map_bench_dense(b, 2048) }
300+
// #[bench] fn mapcountdense_000000512(b: B) { map_bench_dense(b, 512) }
301+
// #[bench] fn mapcountdense_000001024(b: B) { map_bench_dense(b, 1024) }
302+
// #[bench] fn mapcountdense_000002048(b: B) { map_bench_dense(b, 2048) }
303303
}
304304
}
305305

@@ -308,6 +308,7 @@ macro_rules! tree_benches {
308308
#[cfg(test)] mod farm { hash_benches!{Farm} }
309309
#[cfg(test)] mod fnv { hash_benches!{Fnv} }
310310
#[cfg(test)] mod horner { hash_benches!{HornerHasher} }
311+
#[cfg(test)] mod sip_opt_b { hash_benches!{SipOpt} }
311312

312313
// one day?
313314

@@ -316,7 +317,5 @@ macro_rules! tree_benches {
316317
// #[cfg(test)] mod murmur { hash_benches!{MurMur}}
317318

318319

319-
#[cfg(test)] mod btree { tree_benches!{StdBTree<&[u8], i32>} }
320-
#[cfg(test)] mod btreenew { tree_benches!{NewBTree<&[u8], i32>} }
321-
322-
320+
// #[cfg(test)] mod btree { tree_benches!{StdBTree<&[u8], usize>} }
321+
// #[cfg(test)] mod btreenew { tree_benches!{NewBTree<&[u8], i32>} }

0 commit comments

Comments
 (0)