|
0 |
diff --git a/Cargo.toml b/Cargo.toml
|
|
1 |
index b412f79..9d5c5b7 100644
|
|
2 |
--- a/Cargo.toml
|
|
3 |
+++ b/Cargo.toml
|
|
4 |
@@ -54,18 +54,6 @@ doctest = true
|
|
5 |
bench = true
|
|
6 |
doc = true
|
|
7 |
|
|
8 |
-[[bench]]
|
|
9 |
-name = "ahash"
|
|
10 |
-path = "tests/bench.rs"
|
|
11 |
-harness = false
|
|
12 |
-
|
|
13 |
-[[bench]]
|
|
14 |
-name = "map"
|
|
15 |
-path = "tests/map_tests.rs"
|
|
16 |
-harness = false
|
|
17 |
-[dev-dependencies.criterion]
|
|
18 |
-version = "0.3.2"
|
|
19 |
-
|
|
20 |
[dev-dependencies.fnv]
|
|
21 |
version = "1.0.5"
|
|
22 |
|
|
23 |
diff --git a/tests/bench.rs b/tests/bench.rs
|
|
24 |
deleted file mode 100644
|
|
25 |
index 9e6dccc..0000000
|
|
26 |
--- a/tests/bench.rs
|
|
27 |
+++ /dev/null
|
|
28 |
@@ -1,154 +0,0 @@
|
|
29 |
-use ahash::{CallHasher, RandomState};
|
|
30 |
-use criterion::*;
|
|
31 |
-use fxhash::FxHasher;
|
|
32 |
-use std::collections::hash_map::DefaultHasher;
|
|
33 |
-use std::hash::{Hash, Hasher};
|
|
34 |
-
|
|
35 |
-#[cfg(any(
|
|
36 |
- all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)),
|
|
37 |
- all(any(target_arch = "arm", target_arch = "aarch64"), target_feature = "crypto", not(miri), feature = "stdsimd")
|
|
38 |
-))]
|
|
39 |
-fn aeshash<H: Hash>(b: &H) -> u64 {
|
|
40 |
- let build_hasher = RandomState::with_seeds(1, 2, 3, 4);
|
|
41 |
- H::get_hash(b, &build_hasher)
|
|
42 |
-}
|
|
43 |
-#[cfg(not(any(
|
|
44 |
- all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)),
|
|
45 |
- all(any(target_arch = "arm", target_arch = "aarch64"), target_feature = "crypto", not(miri), feature = "stdsimd")
|
|
46 |
-)))]
|
|
47 |
-fn aeshash<H: Hash>(_b: &H) -> u64 {
|
|
48 |
- panic!("aes must be enabled")
|
|
49 |
-}
|
|
50 |
-
|
|
51 |
-#[cfg(not(any(
|
|
52 |
- all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)),
|
|
53 |
- all(any(target_arch = "arm", target_arch = "aarch64"), target_feature = "crypto", not(miri), feature = "stdsimd")
|
|
54 |
-)))]
|
|
55 |
-fn fallbackhash<H: Hash>(b: &H) -> u64 {
|
|
56 |
- let build_hasher = RandomState::with_seeds(1, 2, 3, 4);
|
|
57 |
- H::get_hash(b, &build_hasher)
|
|
58 |
-}
|
|
59 |
-#[cfg(any(
|
|
60 |
- all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)),
|
|
61 |
- all(any(target_arch = "arm", target_arch = "aarch64"), target_feature = "crypto", not(miri), feature = "stdsimd")
|
|
62 |
-))]
|
|
63 |
-fn fallbackhash<H: Hash>(_b: &H) -> u64 {
|
|
64 |
- panic!("aes must be disabled")
|
|
65 |
-}
|
|
66 |
-
|
|
67 |
-fn fnvhash<H: Hash>(b: &H) -> u64 {
|
|
68 |
- let mut hasher = fnv::FnvHasher::default();
|
|
69 |
- b.hash(&mut hasher);
|
|
70 |
- hasher.finish()
|
|
71 |
-}
|
|
72 |
-
|
|
73 |
-fn siphash<H: Hash>(b: &H) -> u64 {
|
|
74 |
- let mut hasher = DefaultHasher::default();
|
|
75 |
- b.hash(&mut hasher);
|
|
76 |
- hasher.finish()
|
|
77 |
-}
|
|
78 |
-
|
|
79 |
-fn fxhash<H: Hash>(b: &H) -> u64 {
|
|
80 |
- let mut hasher = FxHasher::default();
|
|
81 |
- b.hash(&mut hasher);
|
|
82 |
- hasher.finish()
|
|
83 |
-}
|
|
84 |
-
|
|
85 |
-fn seahash<H: Hash>(b: &H) -> u64 {
|
|
86 |
- let mut hasher = seahash::SeaHasher::default();
|
|
87 |
- b.hash(&mut hasher);
|
|
88 |
- hasher.finish()
|
|
89 |
-}
|
|
90 |
-
|
|
91 |
-const STRING_LENGTHS: [u32; 12] = [1, 3, 4, 7, 8, 15, 16, 24, 33, 68, 132, 1024];
|
|
92 |
-
|
|
93 |
-fn gen_strings() -> Vec<String> {
|
|
94 |
- STRING_LENGTHS
|
|
95 |
- .iter()
|
|
96 |
- .map(|len| {
|
|
97 |
- let mut string = String::default();
|
|
98 |
- for pos in 1..=*len {
|
|
99 |
- let c = (48 + (pos % 10) as u8) as char;
|
|
100 |
- string.push(c);
|
|
101 |
- }
|
|
102 |
- string
|
|
103 |
- })
|
|
104 |
- .collect()
|
|
105 |
-}
|
|
106 |
-
|
|
107 |
-const U8_VALUE: u8 = 123;
|
|
108 |
-const U16_VALUE: u16 = 1234;
|
|
109 |
-const U32_VALUE: u32 = 12345678;
|
|
110 |
-const U64_VALUE: u64 = 1234567890123456;
|
|
111 |
-const U128_VALUE: u128 = 12345678901234567890123456789012;
|
|
112 |
-
|
|
113 |
-fn bench_ahash(c: &mut Criterion) {
|
|
114 |
- let mut group = c.benchmark_group("aeshash");
|
|
115 |
- group.bench_with_input("u8", &U8_VALUE, |b, s| b.iter(|| black_box(aeshash(s))));
|
|
116 |
- group.bench_with_input("u16", &U16_VALUE, |b, s| b.iter(|| black_box(aeshash(s))));
|
|
117 |
- group.bench_with_input("u32", &U32_VALUE, |b, s| b.iter(|| black_box(aeshash(s))));
|
|
118 |
- group.bench_with_input("u64", &U64_VALUE, |b, s| b.iter(|| black_box(aeshash(s))));
|
|
119 |
- group.bench_with_input("u128", &U128_VALUE, |b, s| b.iter(|| black_box(aeshash(s))));
|
|
120 |
- group.bench_with_input("string", &gen_strings(), |b, s| b.iter(|| black_box(aeshash(s))));
|
|
121 |
-}
|
|
122 |
-
|
|
123 |
-fn bench_fallback(c: &mut Criterion) {
|
|
124 |
- let mut group = c.benchmark_group("fallback");
|
|
125 |
- group.bench_with_input("u8", &U8_VALUE, |b, s| b.iter(|| black_box(fallbackhash(s))));
|
|
126 |
- group.bench_with_input("u16", &U16_VALUE, |b, s| b.iter(|| black_box(fallbackhash(s))));
|
|
127 |
- group.bench_with_input("u32", &U32_VALUE, |b, s| b.iter(|| black_box(fallbackhash(s))));
|
|
128 |
- group.bench_with_input("u64", &U64_VALUE, |b, s| b.iter(|| black_box(fallbackhash(s))));
|
|
129 |
- group.bench_with_input("u128", &U128_VALUE, |b, s| b.iter(|| black_box(fallbackhash(s))));
|
|
130 |
- group.bench_with_input("string", &gen_strings(), |b, s| b.iter(|| black_box(fallbackhash(s))));
|
|
131 |
-}
|
|
132 |
-
|
|
133 |
-fn bench_fx(c: &mut Criterion) {
|
|
134 |
- let mut group = c.benchmark_group("fx");
|
|
135 |
- group.bench_with_input("u8", &U8_VALUE, |b, s| b.iter(|| black_box(fxhash(s))));
|
|
136 |
- group.bench_with_input("u16", &U16_VALUE, |b, s| b.iter(|| black_box(fxhash(s))));
|
|
137 |
- group.bench_with_input("u32", &U32_VALUE, |b, s| b.iter(|| black_box(fxhash(s))));
|
|
138 |
- group.bench_with_input("u64", &U64_VALUE, |b, s| b.iter(|| black_box(fxhash(s))));
|
|
139 |
- group.bench_with_input("u128", &U128_VALUE, |b, s| b.iter(|| black_box(fxhash(s))));
|
|
140 |
- group.bench_with_input("string", &gen_strings(), |b, s| b.iter(|| black_box(fxhash(s))));
|
|
141 |
-}
|
|
142 |
-
|
|
143 |
-fn bench_fnv(c: &mut Criterion) {
|
|
144 |
- let mut group = c.benchmark_group("fnv");
|
|
145 |
- group.bench_with_input("u8", &U8_VALUE, |b, s| b.iter(|| black_box(fnvhash(s))));
|
|
146 |
- group.bench_with_input("u16", &U16_VALUE, |b, s| b.iter(|| black_box(fnvhash(s))));
|
|
147 |
- group.bench_with_input("u32", &U32_VALUE, |b, s| b.iter(|| black_box(fnvhash(s))));
|
|
148 |
- group.bench_with_input("u64", &U64_VALUE, |b, s| b.iter(|| black_box(fnvhash(s))));
|
|
149 |
- group.bench_with_input("u128", &U128_VALUE, |b, s| b.iter(|| black_box(fnvhash(s))));
|
|
150 |
- group.bench_with_input("string", &gen_strings(), |b, s| b.iter(|| black_box(fnvhash(s))));
|
|
151 |
-}
|
|
152 |
-
|
|
153 |
-fn bench_sea(c: &mut Criterion) {
|
|
154 |
- let mut group = c.benchmark_group("sea");
|
|
155 |
- group.bench_with_input("u8", &U8_VALUE, |b, s| b.iter(|| black_box(seahash(s))));
|
|
156 |
- group.bench_with_input("u16", &U16_VALUE, |b, s| b.iter(|| black_box(seahash(s))));
|
|
157 |
- group.bench_with_input("u32", &U32_VALUE, |b, s| b.iter(|| black_box(seahash(s))));
|
|
158 |
- group.bench_with_input("u64", &U64_VALUE, |b, s| b.iter(|| black_box(seahash(s))));
|
|
159 |
- group.bench_with_input("u128", &U128_VALUE, |b, s| b.iter(|| black_box(seahash(s))));
|
|
160 |
- group.bench_with_input("string", &gen_strings(), |b, s| b.iter(|| black_box(seahash(s))));
|
|
161 |
-}
|
|
162 |
-
|
|
163 |
-fn bench_sip(c: &mut Criterion) {
|
|
164 |
- let mut group = c.benchmark_group("sip");
|
|
165 |
- group.bench_with_input("u8", &U8_VALUE, |b, s| b.iter(|| black_box(siphash(s))));
|
|
166 |
- group.bench_with_input("u16", &U16_VALUE, |b, s| b.iter(|| black_box(siphash(s))));
|
|
167 |
- group.bench_with_input("u32", &U32_VALUE, |b, s| b.iter(|| black_box(siphash(s))));
|
|
168 |
- group.bench_with_input("u64", &U64_VALUE, |b, s| b.iter(|| black_box(siphash(s))));
|
|
169 |
- group.bench_with_input("u128", &U128_VALUE, |b, s| b.iter(|| black_box(siphash(s))));
|
|
170 |
- group.bench_with_input("string", &gen_strings(), |b, s| b.iter(|| black_box(siphash(s))));
|
|
171 |
-}
|
|
172 |
-
|
|
173 |
-criterion_main!(benches);
|
|
174 |
-criterion_group!(
|
|
175 |
- benches,
|
|
176 |
- bench_ahash,
|
|
177 |
- bench_fallback,
|
|
178 |
- bench_fx,
|
|
179 |
- bench_fnv,
|
|
180 |
- bench_sea,
|
|
181 |
- bench_sip
|
|
182 |
-);
|
|
183 |
diff --git a/tests/map_tests.rs b/tests/map_tests.rs
|
|
184 |
deleted file mode 100644
|
|
185 |
index be617a2..0000000
|
|
186 |
--- a/tests/map_tests.rs
|
|
187 |
+++ /dev/null
|
|
188 |
@@ -1,203 +0,0 @@
|
|
189 |
-use std::hash::{BuildHasher, Hash, Hasher};
|
|
190 |
-
|
|
191 |
-use criterion::*;
|
|
192 |
-use fxhash::FxHasher;
|
|
193 |
-
|
|
194 |
-use ahash::{AHasher, CallHasher, RandomState};
|
|
195 |
-
|
|
196 |
-fn gen_word_pairs() -> Vec<String> {
|
|
197 |
- let words: Vec<_> = r#"
|
|
198 |
-a, ability, able, about, above, accept, according, account, across, act, action,
|
|
199 |
-activity, actually, add, address, administration, admit, adult, affect, after,
|
|
200 |
-again, against, age, agency, agent, ago, agree, agreement, ahead, air, all,
|
|
201 |
-allow, almost, alone, along, already, also, although, always, American, among,
|
|
202 |
-amount, analysis, and, animal, another, answer, any, anyone, anything, appear,
|
|
203 |
-apply, approach, area, argue, arm, around, arrive, art, article, artist, as,
|
|
204 |
-ask, assume, at, attack, attention, attorney, audience, author, authority,
|
|
205 |
-available, avoid, away, baby, back, bad, bag, ball, bank, bar, base, be, beat,
|
|
206 |
-beautiful, because, become, bed, before, begin, behavior, behind, believe,
|
|
207 |
-benefit, best, better, between, beyond, big, bill, billion, bit, black, blood,
|
|
208 |
-blue, board, body, book, born, both, box, boy, break, bring, brother, budget,
|
|
209 |
-build, building, business, but, buy, by, call, camera, campaign, can, cancer,
|
|
210 |
-candidate, capital, car, card, care, career, carry, case, catch, cause, cell,
|
|
211 |
-center, central, century, certain, certainly, chair, challenge, chance, change,
|
|
212 |
-character, charge, check, child, choice, choose, church, citizen, city, civil,
|
|
213 |
-claim, class, clear, clearly, close, coach, cold, collection, college, color,
|
|
214 |
-come, commercial, common, community, company, compare, computer, concern,
|
|
215 |
-condition, conference, Congress, consider, consumer, contain, continue, control,
|
|
216 |
-cost, could, country, couple, course, court, cover, create, crime, cultural,
|
|
217 |
-culture, cup, current, customer, cut, dark, data, daughter, day, dead, deal,
|
|
218 |
-death, debate, decade, decide, decision, deep, defense, degree, Democrat,
|
|
219 |
-democratic, describe, design, despite, detail, determine, develop, development,
|
|
220 |
-die, difference, different, difficult, dinner, direction, director, discover,
|
|
221 |
-discuss, discussion, disease, do, doctor, dog, door, down, draw, dream, drive,
|
|
222 |
-drop, drug, during, each, early, east, easy, eat, economic, economy, edge,
|
|
223 |
-education, effect, effort, eight, either, election, else, employee, end, energy,
|
|
224 |
-enjoy, enough, enter, entire, environment, environmental, especially, establish,
|
|
225 |
-even, evening, event, ever, every, everybody, everyone, everything, evidence,
|
|
226 |
-exactly, example, executive, exist, expect, experience, expert, explain, eye,
|
|
227 |
-face, fact, factor, fail, fall, family, far, fast, father, fear, federal, feel,
|
|
228 |
-feeling, few, field, fight, figure, fill, film, final, finally, financial, find,
|
|
229 |
-fine, finger, finish, fire, firm, first, fish, five, floor, fly, focus, follow,
|
|
230 |
-food, foot, for, force, foreign, forget, form, former, forward, four, free,
|
|
231 |
-friend, from, front, full, fund, future, game, garden, gas, general, generation,
|
|
232 |
-get, girl, give, glass, go, goal, good, government, great, green, ground, group,
|
|
233 |
-grow, growth, guess, gun, guy, hair, half, hand, hang, happen, happy, hard,
|
|
234 |
-have, he, head, health, hear, heart, heat, heavy, help, her, here, herself,
|
|
235 |
-high, him, himself, his, history, hit, hold, home, hope, hospital, hot, hotel,
|
|
236 |
-hour, house, how, however, huge, human, hundred, husband, I, idea, identify, if,
|
|
237 |
-image, imagine, impact, important, improve, in, include, including, increase,
|
|
238 |
-indeed, indicate, individual, industry, information, inside, instead,
|
|
239 |
-institution, interest, interesting, international, interview, into, investment,
|
|
240 |
-involve, issue, it, item, its, itself, job, join, just, keep, key, kid, kill,
|
|
241 |
-kind, kitchen, know, knowledge, land, language, large, last, late, later, laugh,
|
|
242 |
-law, lawyer, lay, lead, leader, learn, least, leave, left, leg, legal, less,
|
|
243 |
-let, letter, level, lie, life, light, like, likely, line, list, listen, little,
|
|
244 |
-live, local, long, look, lose, loss, lot, love, low, machine, magazine, main,
|
|
245 |
-maintain, major, majority, make, man, manage, management, manager, many, market,
|
|
246 |
-marriage, material, matter, may, maybe, me, mean, measure, media, medical, meet,
|
|
247 |
-meeting, member, memory, mention, message, method, middle, might, military,
|
|
248 |
-million, mind, minute, miss, mission, model, modern, moment, money, month, more,
|
|
249 |
-morning, most, mother, mouth, move, movement, movie, Mr, Mrs, much, music, must,
|
|
250 |
-my, myself, name, nation, national, natural, nature, near, nearly, necessary,
|
|
251 |
-need, network, never, new, news, newspaper, next, nice, night, no, none, nor,
|
|
252 |
-north, not, note, nothing, notice, now, n't, number, occur, of, off, offer,
|
|
253 |
-office, officer, official, often, oh, oil, ok, old, on, once, one, only, onto,
|
|
254 |
-open, operation, opportunity, option, or, order, organization, other, others,
|
|
255 |
-our, out, outside, over, own, owner, page, pain, painting, paper, parent, part,
|
|
256 |
-participant, particular, particularly, partner, party, pass, past, patient,
|
|
257 |
-pattern, pay, peace, people, per, perform, performance, perhaps, period, person,
|
|
258 |
-personal, phone, physical, pick, picture, piece, place, plan, plant, play,
|
|
259 |
-player, PM, point, police, policy, political, politics, poor, popular,
|
|
260 |
-population, position, positive, possible, power, practice, prepare, present,
|
|
261 |
-president, pressure, pretty, prevent, price, private, probably, problem,
|
|
262 |
-process, produce, product, production, professional, professor, program,
|
|
263 |
-project, property, protect, prove, provide, public, pull, purpose, push, put,
|
|
264 |
-quality, question, quickly, quite, race, radio, raise, range, rate, rather,
|
|
265 |
-reach, read, ready, real, reality, realize, really, reason, receive, recent,
|
|
266 |
-recently, recognize, record, red, reduce, reflect, region, relate, relationship,
|
|
267 |
-religious, remain, remember, remove, report, represent, Republican, require,
|
|
268 |
-research, resource, respond, response, responsibility, rest, result, return,
|
|
269 |
-reveal, rich, right, rise, risk, road, rock, role, room, rule, run, safe, same,
|
|
270 |
-save, say, scene, school, science, scientist, score, sea, season, seat, second,
|
|
271 |
-section, security, see, seek, seem, sell, send, senior, sense, series, serious,
|
|
272 |
-serve, service, set, seven, several, sex, sexual, shake, share, she, shoot,
|
|
273 |
-short, shot, should, shoulder, show, side, sign, significant, similar, simple,
|
|
274 |
-simply, since, sing, single, sister, sit, site, situation, six, size, skill,
|
|
275 |
-skin, small, smile, so, social, society, soldier, some, somebody, someone,
|
|
276 |
-something, sometimes, son, song, soon, sort, sound, source, south, southern,
|
|
277 |
-space, speak, special, specific, speech, spend, sport, spring, staff, stage,
|
|
278 |
-stand, standard, star, start, state, statement, station, stay, step, still,
|
|
279 |
-stock, stop, store, story, strategy, street, strong, structure, student, study,
|
|
280 |
-stuff, style, subject, success, successful, such, suddenly, suffer, suggest,
|
|
281 |
-summer, support, sure, surface, system, table, take, talk, task, tax, teach,
|
|
282 |
-teacher, team, technology, television, tell, ten, tend, term, test, than, thank,
|
|
283 |
-that, the, their, them, themselves, then, theory, there, these, they, thing,
|
|
284 |
-think, third, this, those, though, thought, thousand, threat, three, through,
|
|
285 |
-throughout, throw, thus, time, to, today, together, tonight, too, top, total,
|
|
286 |
-tough, toward, town, trade, traditional, training, travel, treat, treatment,
|
|
287 |
-tree, trial, trip, trouble, true, truth, try, turn, TV, two, type, under,
|
|
288 |
-understand, unit, until, up, upon, us, use, usually, value, various, very,
|
|
289 |
-victim, view, violence, visit, voice, vote, wait, walk, wall, want, war, watch,
|
|
290 |
-water, way, we, weapon, wear, week, weight, well, west, western, what, whatever,
|
|
291 |
-when, where, whether, which, while, white, who, whole, whom, whose, why, wide,
|
|
292 |
-wife, will, win, wind, window, wish, with, within, without, woman, wonder, word,
|
|
293 |
-work, worker, world, worry, would, write, writer, wrong, yard, yeah, year, yes,
|
|
294 |
-yet, you, young, your, yourself"#
|
|
295 |
- .split(',')
|
|
296 |
- .map(|word| word.trim())
|
|
297 |
- .collect();
|
|
298 |
-
|
|
299 |
- let mut word_pairs: Vec<_> = Vec::new();
|
|
300 |
- for word in &words {
|
|
301 |
- for other_word in &words {
|
|
302 |
- word_pairs.push(word.to_string() + " " + other_word);
|
|
303 |
- }
|
|
304 |
- }
|
|
305 |
- assert_eq!(1_000_000, word_pairs.len());
|
|
306 |
- word_pairs
|
|
307 |
-}
|
|
308 |
-
|
|
309 |
-#[allow(unused)] // False positive
|
|
310 |
-fn test_hash_common_words<B: BuildHasher>(build_hasher: &B) {
|
|
311 |
- let word_pairs: Vec<_> = gen_word_pairs();
|
|
312 |
- check_for_collisions(build_hasher, &word_pairs, 32);
|
|
313 |
-}
|
|
314 |
-
|
|
315 |
-#[allow(unused)] // False positive
|
|
316 |
-fn check_for_collisions<H: Hash, B: BuildHasher>(build_hasher: &B, items: &[H], bucket_count: usize) {
|
|
317 |
- let mut buckets = vec![0; bucket_count];
|
|
318 |
- for item in items {
|
|
319 |
- let value = hash(item, build_hasher) as usize;
|
|
320 |
- buckets[value % bucket_count] += 1;
|
|
321 |
- }
|
|
322 |
- let mean = items.len() / bucket_count;
|
|
323 |
- let max = *buckets.iter().max().unwrap();
|
|
324 |
- let min = *buckets.iter().min().unwrap();
|
|
325 |
- assert!(
|
|
326 |
- (min as f64) > (mean as f64) * 0.95,
|
|
327 |
- "min: {}, max:{}, {:?}",
|
|
328 |
- min,
|
|
329 |
- max,
|
|
330 |
- buckets
|
|
331 |
- );
|
|
332 |
- assert!(
|
|
333 |
- (max as f64) < (mean as f64) * 1.05,
|
|
334 |
- "min: {}, max:{}, {:?}",
|
|
335 |
- min,
|
|
336 |
- max,
|
|
337 |
- buckets
|
|
338 |
- );
|
|
339 |
-}
|
|
340 |
-
|
|
341 |
-#[allow(unused)] // False positive
|
|
342 |
-fn hash<H: Hash, B: BuildHasher>(b: &H, build_hasher: &B) -> u64 {
|
|
343 |
- H::get_hash(b, build_hasher)
|
|
344 |
-}
|
|
345 |
-
|
|
346 |
-#[test]
|
|
347 |
-fn test_bucket_distribution() {
|
|
348 |
- let build_hasher = RandomState::with_seeds(1, 2, 3, 4);
|
|
349 |
- test_hash_common_words(&build_hasher);
|
|
350 |
- let sequence: Vec<_> = (0..320000).collect();
|
|
351 |
- check_for_collisions(&build_hasher, &sequence, 32);
|
|
352 |
- let sequence: Vec<_> = (0..2560000).collect();
|
|
353 |
- check_for_collisions(&build_hasher, &sequence, 256);
|
|
354 |
- let sequence: Vec<_> = (0..320000).map(|i| i * 1024).collect();
|
|
355 |
- check_for_collisions(&build_hasher, &sequence, 32);
|
|
356 |
- let sequence: Vec<_> = (0..2560000_u64).map(|i| i * 1024).collect();
|
|
357 |
- check_for_collisions(&build_hasher, &sequence, 256);
|
|
358 |
-}
|
|
359 |
-
|
|
360 |
-fn ahash_vec<H: Hash>(b: &Vec<H>) -> u64 {
|
|
361 |
- let mut total: u64 = 0;
|
|
362 |
- for item in b {
|
|
363 |
- let mut hasher = AHasher::new_with_keys(1234, 5678);
|
|
364 |
- item.hash(&mut hasher);
|
|
365 |
- total = total.wrapping_add(hasher.finish());
|
|
366 |
- }
|
|
367 |
- total
|
|
368 |
-}
|
|
369 |
-
|
|
370 |
-fn fxhash_vec<H: Hash>(b: &Vec<H>) -> u64 {
|
|
371 |
- let mut total: u64 = 0;
|
|
372 |
- for item in b {
|
|
373 |
- let mut hasher = FxHasher::default();
|
|
374 |
- item.hash(&mut hasher);
|
|
375 |
- total = total.wrapping_add(hasher.finish());
|
|
376 |
- }
|
|
377 |
- total
|
|
378 |
-}
|
|
379 |
-
|
|
380 |
-fn bench_ahash_words(c: &mut Criterion) {
|
|
381 |
- let words = gen_word_pairs();
|
|
382 |
- c.bench_function("aes_words", |b| b.iter(|| black_box(ahash_vec(&words))));
|
|
383 |
-}
|
|
384 |
-
|
|
385 |
-fn bench_fx_words(c: &mut Criterion) {
|
|
386 |
- let words = gen_word_pairs();
|
|
387 |
- c.bench_function("fx_words", |b| b.iter(|| black_box(fxhash_vec(&words))));
|
|
388 |
-}
|
|
389 |
-
|
|
390 |
-criterion_main!(benches);
|
|
391 |
-criterion_group!(benches, bench_ahash_words, bench_fx_words,);
|