Skip to content

Commit

Permalink
replaced microtime with process.hrtime()
Browse files Browse the repository at this point in the history
  • Loading branch information
tjwebb committed Sep 8, 2015
1 parent 5395854 commit b0b94c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
"istanbul": "*",
"wrench": "~1.5.8",
"benchmark": "~1.0.0",
"microtime": "~1.3.0",
"expect.js": "~0.3.1",
"should": "~5.2.0",
"supertest": "~0.15.0",
Expand Down
29 changes: 14 additions & 15 deletions test/benchmarks/sails.load.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('benchmarks', function () {
var sails = new Sails();
return cb();
});


//
// Load
Expand Down Expand Up @@ -135,30 +135,32 @@ describe('benchmarks', function () {

/**
* Run the specified function, capturing time elapsed.
*
*
* @param {[type]} description [description]
* @param {Function} fn [description]
* @return {[type]} [description]
*/
function benchmark (description, fn) {

it (description, function (cb) {
var self = this;

var startedAt = self.microtime.now();
// console.time(description);
var t1 = process.hrtime()

fn.apply(this, [function _callback () {

var _result = {};

// If a `comment` or `expected` was provided, harvest it
_result.expected = self.expected;
self.expected = null;

_result.comment = self.comment;
self.comment = null;
var finishedAt = self.microtime.now();
_result.duration = finishedAt - startedAt;

var diff = process.hrtime(t1);

_.result.duration = (diff[0] * 1e6) + (diff[1] / 1e3)
_result.benchmark = description;

// console.log('finished ',_result);
Expand All @@ -171,21 +173,18 @@ function benchmark (description, fn) {

/**
* Use in mocha's `before`
*
*
* @this {Array} benchmarks
* @this {Object} microtime
*/
function setupBenchmarks() {
this.microtime = require('microtime');
this.benchmarks = [];
}


/**
* Use in mocha's `after`
*
*
* @this {Array} benchmarks
* @this {Object} microtime
*/
function reportBenchmarks () {
var _ = require('lodash');
Expand Down Expand Up @@ -214,7 +213,7 @@ function reportBenchmarks () {
(ms < 1*expected/10) ? 'green' :
(ms < 3*expected/10) ? 'green' :
(ms < 6*expected/10) ? 'cyan' :
(ms < threshold) ? 'yellow' :
(ms < threshold) ? 'yellow' :
'red';

ms += 'ms';
Expand All @@ -223,7 +222,7 @@ function reportBenchmarks () {
// Whether to show expected ms
var showExpected = true; // ms >= threshold;

return memo + '\n ' +
return memo + '\n ' +
(result.benchmark+'') + ' :: '.grey + ms +

// Expected ms provided, and the test took quite a while
Expand Down

0 comments on commit b0b94c9

Please sign in to comment.