Skip to content

Commit 086fb84

Browse files
committed
Adding benchmark
1 parent 1eed31f commit 086fb84

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

benchmark/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Performance benchmarks
2+
===
3+
4+
You should have node.js and npm installed to run
5+
these benchmarks. It assumes a recent version of node.js (4.0.0 or better).
6+
7+
npm install benchmark
8+
npm install sizeof
9+
npm install fastintcompression
10+
nodejs test.js

benchmark/test.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/* performance benchmark */
2+
/* This script expects node.js */
3+
4+
'use strict';
5+
var FastIntegerCompression = require('../FastIntegerCompression.js');
6+
var os = require('os');
7+
var Benchmark = require('benchmark');
8+
var sizeof=require("sizeof");
9+
10+
function BasicBench() {
11+
var array = [];
12+
var howmany = 1000;
13+
for (var i = 0, t = 40; i < howmany; i++) {
14+
array.push(Math.round(Math.random() * t))
15+
}
16+
var buf = FastIntegerCompression.compress(array);
17+
console.log('input size: '+sizeof.format(sizeof.sizeof(array))+' compressed size: '+sizeof.format(buf.byteLength));
18+
19+
var suite = new Benchmark.Suite();
20+
var ms = suite.add('FastIntegerCompression.compress', function() {
21+
return FastIntegerCompression.compress(array);
22+
})
23+
// add listeners
24+
.on('cycle', function(event) {
25+
console.log(String(event.target));
26+
})
27+
.on('complete', function() {
28+
console.log('Fastest is ' + this.filter('fastest').pluck('name'));
29+
})
30+
// run async
31+
.run({
32+
'async': false
33+
});
34+
suite = new Benchmark.Suite();
35+
var ms = suite.add('FastIntegerCompression.uncompress', function() {
36+
return FastIntegerCompression.uncompress(buf);
37+
})
38+
// add listeners
39+
.on('cycle', function(event) {
40+
console.log(String(event.target));
41+
})
42+
.on('complete', function() {
43+
console.log('Fastest is ' + this.filter('fastest').pluck('name'));
44+
})
45+
// run async
46+
.run({
47+
'async': false
48+
});
49+
}
50+
51+
var main = function() {
52+
console.log('Platform: ' + process.platform + ' ' + os.release() + ' ' + process.arch);
53+
console.log(os.cpus()[0]['model']);
54+
console.log('Node version ' + process.versions.node + ', v8 version ' + process.versions.v8);
55+
console.log();
56+
BasicBench();
57+
console.log('');
58+
};
59+
60+
if (require.main === module) {
61+
main();
62+
}

0 commit comments

Comments
 (0)