-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbenchmark.js
More file actions
41 lines (36 loc) · 1.38 KB
/
benchmark.js
File metadata and controls
41 lines (36 loc) · 1.38 KB
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
'use strict';
var Benchmark = require('benchmark');
var benchmarks = require('beautify-benchmark');
var murmurhash = require('../');
var asciiBuffer = new Buffer('haha, this is key');
var utf8Buffer = new Buffer('快使用双节棍,嘿嘿嘿嘿。');
var asciiString = 'haha, this is key';
var utf8String = '快使用双节棍,嘿嘿嘿嘿。';
console.log('murmurhash should be 335538535: %s', murmurhash(asciiBuffer));
console.log('murmurhash utf8 should be 705333708: %s', murmurhash(utf8Buffer));
console.log('murmurhash with custom key should be 2639541842: %s', murmurhash(utf8Buffer, 12333));
console.log("murmurhash('hello 中国') should be 1248731102: %s", murmurhash('hello 中国'));
var suite = new Benchmark.Suite();
suite
.add("murmurhash(new Buffer('haha, this is key'))", function () {
murmurhash(asciiBuffer);
})
.add("murmurhash(new Buffer('快使用双节棍,嘿嘿嘿嘿。'))", function () {
murmurhash(utf8Buffer);
})
.add("murmurhash('haha, this is key')", function () {
murmurhash(asciiString);
})
.add("murmurhash('快使用双节棍,嘿嘿嘿嘿。')", function () {
murmurhash(utf8String);
})
.on('cycle', function(event) {
benchmarks.add(event.target);
})
.on('start', function(event) {
console.log('\n node version: %s, date: %s\n Starting...', process.version, Date());
})
.on('complete', function done() {
benchmarks.log();
})
.run({ 'async': false });