Skip to content

Instantly share code, notes, and snippets.

@sentientwaffle
Created June 19, 2012 20:03
Show Gist options
  • Save sentientwaffle/2956222 to your computer and use it in GitHub Desktop.
Save sentientwaffle/2956222 to your computer and use it in GitHub Desktop.
Benchmark: llquantize vs metrics.Histogram
$ time node llq.js
{ '1': 104,
'2': 95,
'3': 112,
'4': 104,
'5': 95,
'6': 103,
'7': 96,
'8': 106,
'9': 100,
'10': 986,
'20': 1034,
'30': 1032,
'40': 976,
'50': 977,
'60': 1007,
'70': 1045,
'80': 993,
'90': 1027,
'100': 10078,
'200': 9958,
'300': 10234,
'400': 10011,
'500': 10107,
'600': 10137,
'700': 10015,
'800': 10118,
'900': 9997,
'1000': 100487,
'2000': 99524,
'3000': 100613,
'4000': 100214,
'5000': 100140,
'6000': 99827,
'7000': 100060,
'8000': 100647,
'9000': 99925,
'10000': 1000137,
'20000': 1000094,
'30000': 1002967,
'40000': 1002088,
'50000': 997856,
'60000': 999457,
'70000': 999818,
'80000': 1001053,
'90000': 1000877,
'100000': 9999703,
'200000': 10003456,
'300000': 10001511,
'400000': 9994089,
'500000': 9990945,
'600000': 10005991,
'700000': 9998204,
'800000': 9999159,
'900000': 10000402,
'0.7': 4,
'0.004': 1,
'0.4': 10,
'0.8': 14,
'0.3': 9,
'0.06': 2,
'0.9': 12,
'0.6': 12,
'0.2': 7,
'0.5': 13,
'0.1': 12,
'0.07': 1,
'0.05': 1,
'0.04': 2,
'0.0006': 1,
'0.08': 1,
'0.09': 1,
'0.02': 2,
'0.009': 1,
'0.01': 2,
'0.002': 1 }
real 0m22.970s
user 0m22.993s
sys 0m0.090s
var llquantize = require('llquantize')
, llq = llquantize()
for (var i = 0; i < 100000000; i++) {
llq(Math.random() * 1000000)
}
console.log(llq())
$ time node metr.js
{ type: 'histogram',
min: 0.0009313225746154785,
max: 999999.9906867743,
sum: 49998497494951.734,
variance: 83335249077.92839,
mean: 499984.97494969005,
std_dev: 288678.4527427158,
count: 100000000,
median: 493190.4720142484,
p75: 740527.1644820459,
p95: 942698.7110404298,
p99: 988890.730580315,
p999: 999618.4600321576 }
real 0m32.893s
user 0m32.935s
sys 0m0.120s
var metrics = require('metrics')
, hist = new metrics.Histogram()
for (var i = 0; i < 100000000; i++) {
hist.update(Math.random() * 1000000)
}
console.log(hist.printObj())

Install dependencies:

$ npm install llquantize
$ npm install metrics

Run:

$ time node llq.js
...

$ time node metr.js
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment