Permalink
Browse files

use Date.now() for bm

  • Loading branch information...
1 parent 2d2e77d commit cb589582361724c033a7281701d92ea6f1b9aa68 @tj committed Nov 6, 2012
Showing with 8 additions and 8 deletions.
  1. +8 −8 benchmark/sub.js
View
@@ -11,21 +11,21 @@ var sock = ss.socket(program.type);
sock.connect(3000);
var n = 0;
-var ops = 200;
+var ops = 5000;
var bytes = program.size || 1024;
-var t = start = process.hrtime();
+var prev = start = Date.now();
var results = [];
console.log();
sock.on('message', function(msg){
if (n++ % ops == 0) {
- t = process.hrtime(t);
- var ms = t[1] / 1000 / 1000;
- var persec = (ops * (1000 / ms) | 0);
+ var ms = Date.now() - prev;
+ var sec = ms / 1000;
+ var persec = ops / sec | 0;
results.push(persec);
process.stdout.write('\r [' + persec + ' ops/s] [' + n + ']');
- t = process.hrtime();
+ prev = Date.now();
}
});
@@ -53,13 +53,13 @@ function median(arr) {
}
process.on('SIGINT', function(){
- t = process.hrtime(start);
+ var ms = Date.now() - start;
var avg = mean(results);
console.log('\n');
console.log(' min: %d ops/s', min(results));
console.log(' mean: %d ops/s', avg);
console.log(' median: %d ops/s', median(results));
- console.log(' total: %d ops in %d.%ds', n, t[0], t[1] / 1000 / 1000 | 0);
+ console.log(' total: %d ops in %ds', n, ms / 1000);
console.log(' through: %d mb/s', (avg * bytes) / 1024 / 1024);
console.log();
process.exit();

0 comments on commit cb58958

Please sign in to comment.