gulp-bench
Run performance Benchmark tests. Ported from grunt-benchmark.
Install
$ npm install --save-dev gulp-bench
Usage
The usage syntax below is the same as for grunt-benchmark.
Basic
Setup your benchmark test, e.g. in test.js
:
var { return n < 2 ? n : + ;}; module { ;};
In your gulpfile:
var gulp = ;var benchmark = ; gulp;
Run it:
$ gulp[16:11:01] Running benchmark basic [./test-data/basic.js]...[16:11:11] basic x 1,107,255 ops/sec ±0.74%
As well as outputting to console output the plugin stream returns a single file containing the test results in JSON form:
gulp;
You can modify the results filename and format by supplying plugin options.
Test options
Tests can be configured through futher options:
moduleexports = name: 'Timeout (asynchronous)' maxTime: 2 /* test should run for max. this no. of seconds */ defer: true /* indicates that test is asynchronous */ { console; } { ; };
Test suites
You can compare implementations by constructing a test suite:
var Timer = Timer; moduleexports = name: 'Timeout Showdown' maxTime: 2 tests: { return; } 'Timeout: 50ms (asynchronous)': defer: true { start; } 'Timeout: 100ms (asynchronous)': defer: true { start; } ;
The expected console output for the above test suite will look similar to:
[16:11:01] Running suite Timeout Showdown [./test-data/compare.js]...[16:11:11] Sync x 69,826,905 ops/sec ±4.27% [16:11:26] Async-50 x 19.64 ops/sec ±0.25% [16:11:38] Async-100 x 9.91 ops/sec ±0.17% [16:11:40] Fastest test is Sync at 3,555,514.2x faster than Async-50
The tests within a suite can also be specified as an array:
var Timer = Timer; moduleexports = name: 'Timeout Showdown' maxTime: 2 tests: name: 'Return immediately (synchronous)' { return; } name: 'Timeout 50ms (asynchronous)' defer: true { start; } name: 'Timeout 100ms (asynchronous)' defer: true { start; } ;
Plugin Options
output
Type: String
Default: benchmark-results.json
Specifies the name of the file in which to write test results.
outputFormat
Type: String
Default: json
Values: csv
, json
Specifies the format for the output
file.
License
MIT - see LICENSE.md