• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #![feature(test)]
2 extern crate test;
3 extern crate fnv;
4 extern crate fxhash;
5 extern crate seahash;
6 
7 use std::hash::{Hash, Hasher};
8 use test::{Bencher, black_box};
9 
10 
fnvhash<H: Hash>(b: H) -> u6411 fn fnvhash<H: Hash>(b: H) -> u64 {
12     let mut hasher = fnv::FnvHasher::default();
13     b.hash(&mut hasher);
14     hasher.finish()
15 }
16 
seahash<H: Hash>(b: H) -> u6417 fn seahash<H: Hash>(b: H) -> u64 {
18     let mut hasher = seahash::SeaHasher::default();
19     b.hash(&mut hasher);
20     hasher.finish()
21 }
22 
23 macro_rules! generate_benches {
24     ($($fx:ident, $fx32:ident, $fx64:ident, $fnv:ident, $sea:ident, $s:expr),* $(,)*) => (
25         $(
26             #[bench]
27             fn $fx(b: &mut Bencher) {
28                 let s = black_box($s);
29                 b.iter(|| {
30                     fxhash::hash(&s)
31                 })
32             }
33 
34             #[bench]
35             fn $fx32(b: &mut Bencher) {
36                 let s = black_box($s);
37                 b.iter(|| {
38                     fxhash::hash32(&s)
39                 })
40             }
41 
42             #[bench]
43             fn $fx64(b: &mut Bencher) {
44                 let s = black_box($s);
45                 b.iter(|| {
46                     fxhash::hash64(&s)
47                 })
48             }
49 
50             #[bench]
51             fn $fnv(b: &mut Bencher) {
52                 let s = black_box($s);
53                 b.iter(|| {
54                     fnvhash(&s)
55                 })
56             }
57 
58             #[bench]
59             fn $sea(b: &mut Bencher) {
60                 let s = black_box($s);
61                 b.iter(|| {
62                     seahash(&s)
63                 })
64             }
65         )*
66     )
67 }
68 
69 generate_benches!(
70     bench_fx_003, bench_fx32_003, bench_fx64_003, bench_fnv_003, bench_seahash_003, "123",
71     bench_fx_004, bench_fx32_004, bench_fx64_004, bench_fnv_004, bench_seahash_004, "1234",
72     bench_fx_011, bench_fx32_011, bench_fx64_011, bench_fnv_011, bench_seahash_011, "12345678901",
73     bench_fx_012, bench_fx32_012, bench_fx64_012, bench_fnv_012, bench_seahash_012, "123456789012",
74     bench_fx_023, bench_fx32_023, bench_fx64_023, bench_fnv_023, bench_seahash_023, "12345678901234567890123",
75     bench_fx_024, bench_fx32_024, bench_fx64_024, bench_fnv_024, bench_seahash_024, "123456789012345678901234",
76     bench_fx_068, bench_fx32_068, bench_fx64_068, bench_fnv_068, bench_seahash_068, "11234567890123456789012345678901234567890123456789012345678901234567",
77     bench_fx_132, bench_fx32_132, bench_fx64_132, bench_fnv_132, bench_seahash_132, "112345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901",
78 );