-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbenchmark.js
48 lines (37 loc) · 1.26 KB
/
benchmark.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Run using `benchr`:
// $ npm i benchr -g
// $ benchr benchmark.js
const MetroHash64 = require('./index').MetroHash64;
const MetroHash128 = require('./index').MetroHash128;
const metrohash64 = require('./index').metrohash64;
const metrohash128 = require('./index').metrohash128;
const TESTS = [
{ name: '16 byte', input : Buffer.alloc(16, 'foobar') },
{ name: '32 byte', input : Buffer.alloc(32, 'foobar') },
{ name: '64 byte', input : Buffer.alloc(64, 'foobar') },
{ name: '128 byte', input : Buffer.alloc(128, 'foobar') },
{ name: '256 byte', input : Buffer.alloc(256, 'foobar') },
{ name: '1024 byte', input : Buffer.alloc(1024, 'foobar') },
];
module.exports = (suite, benchmark) => {
for (const test of TESTS) {
suite(test.name, () => {
benchmark('MetroHash64', () => {
let hasher = new MetroHash64();
hasher.update(test.input);
return hasher.digest();
});
benchmark('MetroHash128', () => {
let hasher = new MetroHash128();
hasher.update(test.input);
return hasher.digest();
});
benchmark('metrohash64', () => {
return metrohash64(test.input);
});
benchmark('metrohash128', () => {
return metrohash128(test.input);
});
});
}
}