A Karma plugin to run Benchmark.js over multiple browsers with Jenkins CI compatible output.
npm install karma-benchmark --save-dev
module.exports = function(config) { config.set({ // Everything discussed below goes in here. // Other values such as browsers, files, autoWatch, reporters etc. // are needed as normal, but have been left out of these example. }); };
In the options object supplied to config.set(), add benchmark
to the list of frameworks in karma.conf.js.
frameworks: ['benchmark']
If you'd like to feed your data into Jenkins, install the jUnit reporter.
npm install karma-junit-reporter --save-dev
Then add to the options object supplied to config.set(), the junitReporter
configuration with the path you want the output xml to be written to.
junitReporter: { suite: 'unit', outputFile: 'build/junit-benchmark-results.xml' }
As large suites of Benchmarks take a long time to run, you may need to increase Karma's timeout from it's default of 60000.
captureTimeout: 60000
Benchmarks can be written as normal using the var suite = new Benchmark.Suite;
format detailed at benchmarkjs.com or with an optional wrapper provided for Benchmark.js that offers a coding style familiar to users of Jasmine and Mocha.
benchmark('_.each', function () { when('iterating over an array', function () { _.each([1, 2, 3], function(el){ return el; }); }); when('iterating over an object', function () { _.each({one : 1, two : 2, three : 3}, function(el){ return el; }); }); });
The equivalent of the above _.each when iterating over an array
benchmark with setup and teardown methods is as follows.
benchmark('_.each', function () { when('iterating over an array', { before: function() { this.list = [5, 4, 3]; }, run: function() { _.each(this.list, function(el) { return el * Math.random(); }); }, after: function() { this.list = null; } }); });
--
You received this message because you are subscribed to the Google Groups "karma-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to karma-users...@googlegroups.com.
To post to this group, send email to karma...@googlegroups.com.
Visit this group at http://groups.google.com/group/karma-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/karma-users/f7e6566d-03d9-48a7-b312-b4796f0cbda3%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.