Skip to content

Commit

Permalink
Fixed the timer test to output on a timer basis as it suggests
Browse files Browse the repository at this point in the history
Added a random duration to give a clear picture of what the timer actually does
  • Loading branch information
Frank Hassanabad committed Mar 10, 2015
1 parent c48628c commit f72957b
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions tests/timer.js
Expand Up @@ -2,26 +2,39 @@ var Timer = require('../metrics/timer');

var test = function(callback){
console.log("\nCreating a new timer, updating 10 times / sec for 30 secs");
var timer = new Timer();
var timer = new Timer()
, n = 0;

var updateInterval = setInterval(function(){
//simulates the duration that a task takes between 0 and 500 milliseconds
//And then update the timer for the duration of that time
var duration = Math.round(Math.random() * (500));
timer.update(duration);
n += 1;
if (n % 10 == 0) {
process.stdout.write(".")
}
}, 100);

setTimeout(function(){
clearInterval(updateInterval);
console.log('Expected rate: 10/sec');
console.log('count: ' + timer.count());
console.log('min: ' + timer.min());
console.log('max: ' + timer.max());
console.log('mean: ' + timer.mean());
console.log('stdDev: ' + timer.stdDev());
console.log('percentiles: ' + JSON.stringify(timer.percentiles(), undefined, 2));
console.log('oneMinuteRate: ' + timer.oneMinuteRate());
console.log('fiveMinuteRate: ' + timer.fiveMinuteRate());
console.log('fifteeenMinuteRate: ' + timer.fifteenMinuteRate());
console.log('meanRate: ' + timer.meanRate());
}, 30000);

for(var i = 0; i < 10000; i++) {
timer.update(i);
}
timer.tick();
console.log(timer.count());
console.log(timer.min());
console.log(timer.max());
console.log(timer.mean());
console.log(timer.stdDev());
console.log(timer.percentiles());
console.log(timer.oneMinuteRate());
console.log(timer.fiveMinuteRate());
console.log(timer.fifteenMinuteRate());
console.log(timer.meanRate());
if (typeof callback == 'function') {
callback();
}
}
};

if (module.parent) {
module.exports = test;
Expand Down

0 comments on commit f72957b

Please sign in to comment.