Comparing version 0.3.0 to 0.4.0
@@ -47,2 +47,9 @@ var EventEmitter = require('events').EventEmitter; | ||
* duration is reached (in seconds). Default is 1 second. | ||
* * report - {function(number, number):string} Optional function for | ||
* formatting the benchmark results. By default, the benchmark runner will | ||
* write out the file name and number of ops per second to stdout. You can | ||
* change this behavior by providing a report function that will be called | ||
* with the number of runs and the total elapsed time (in nanoseconds). | ||
* The runner will write any string returned to stdout. To supress | ||
* writing, return a falsey value. | ||
*/ | ||
@@ -99,2 +106,8 @@ var Benchmark = exports.Benchmark = function(config) { | ||
/** | ||
* Any custom reporter. | ||
* @type {function(number, number):string} | ||
*/ | ||
this._reporter = config.report || null; | ||
}; | ||
@@ -242,3 +255,3 @@ | ||
} | ||
emitter.emit('done', calls, elapsed); | ||
emitter.emit('done', calls, elapsed, this._reporter); | ||
}; |
@@ -1,3 +0,3 @@ | ||
/* eslint-disable no-console */ | ||
var path = require('path'); | ||
var util = require('util'); | ||
@@ -17,13 +17,28 @@ var Benchmark = require('./benchmark').Benchmark; | ||
} catch (err) { | ||
return callback( | ||
new Error('Benchmark failed: ' + file + '\n' + err.message)); | ||
return callback(new Error( | ||
util.format('Benchmark failed: %s\n%s', file, err.message))); | ||
} | ||
var emitter = benchmark.run(); | ||
emitter.on('error', function(err) { | ||
callback(new Error('Benchmark failed: ' + file + '\n' + err.message)); | ||
callback(new Error( | ||
util.format('Benchmark failed: %s\n%s', file, err.message))); | ||
}); | ||
// TODO: introduce reporter | ||
emitter.on('done', function(calls, elapsed) { | ||
console.log('%s %d ops/sec', | ||
path.basename(file), Math.floor(calls / (elapsed / 1e9))); | ||
emitter.on('done', function(calls, elapsed, reporter) { | ||
var message; | ||
if (reporter) { | ||
try { | ||
message = reporter(calls, elapsed); | ||
} catch (err) { | ||
callback(new Error( | ||
util.format('Reporter failed: %s\n%s', file, err.message))); | ||
return; | ||
} | ||
} else { | ||
message = util.format('%s %d ops/sec\n', | ||
path.basename(file), Math.floor(calls / (elapsed / 1e9))); | ||
} | ||
if (message) { | ||
process.stdout.write(message); | ||
} | ||
++current; | ||
@@ -42,3 +57,3 @@ iterate(files, current, callback); | ||
if (err) { | ||
console.error(err.message); | ||
process.stderr.write(err.message + '\n'); | ||
process.exit(1); | ||
@@ -45,0 +60,0 @@ } |
{ | ||
"name": "bench-it", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Benchmark your code", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/tschaub/bench-it", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11638
278