|
| 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