jbrown / benchmark.js

A benchmarking library that works on nearly all JavaScript platforms, supports high-resolution timers, & returns statistically significant results. As used on jsPerf.com.

Home Page:http://benchmarkjs.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Benchmark.js v2.0.0-pre

A robust benchmarking library that works on nearly all JavaScript platforms, supports high-resolution timers, & returns statistically significant results. As seen on jsPerf.

Documentation

Download

Installation

Benchmark.js’ only hard dependency is Lo-Dash. Include platform.js to populate Benchmark.platform.

In a browser:

<script src="lodash.js"></script>
<script src="platform.js"></script>
<script src="benchmark.js"></script>

Optionally, expose Java’s nanosecond timer by adding the nano applet to the <body>:

<applet code="nano" archive="nano.jar"></applet>

Or enable Chrome’s microsecond timer by using the command line switch:

  --enable-benchmarking

In an AMD loader:

require({
  'paths': {
    'benchmark': 'path/to/benchmark',
    'lodash': 'path/to/lodash',
    'platform': 'path/to/platform'
  }
},
['benchmark'], function(Benchmark) {/*…*/});

Using npm:

$ npm i --save benchmark

In Node.js:

var Benchmark = require('benchmark');

Optionally, use the microtime module by Wade Simmons:

npm install microtime

Usage example:

var suite = new Benchmark.Suite;

// add tests
suite.add('RegExp#test', function() {
  /o/.test('Hello World!');
})
.add('String#indexOf', function() {
  'Hello World!'.indexOf('o') > -1;
})
// add listeners
.on('cycle', function(event) {
  console.log(String(event.target));
})
.on('complete', function() {
  console.log('Fastest is ' + this.filter('fastest').pluck('name'));
})
// run async
.run({ 'async': true });

// logs:
// => RegExp#test x 4,161,532 +-0.99% (59 cycles)
// => String#indexOf x 6,139,623 +-1.00% (131 cycles)
// => Fastest is String#indexOf

Support

Tested in Chrome 38-39, Firefox 33-34, IE 6-11, Opera 25-26, Safari 5-8, Node.js 0.8.26~0.10.33, PhantomJS 1.9.7, RingoJS 0.11, & Rhino 1.7RC5.

BestieJS

Benchmark.js is part of the BestieJS “Best in Class” module collection. This means we promote solid browser/environment support, ES5+ precedents, unit testing, & plenty of documentation.

Authors

twitter/mathias twitter/jdalton
Mathias Bynens John-David Dalton

Contributors

twitter/kitcambridge
Kit Cambridge

About

A benchmarking library that works on nearly all JavaScript platforms, supports high-resolution timers, & returns statistically significant results. As used on jsPerf.com.

http://benchmarkjs.com/

License:Other


Languages

Language:JavaScript 94.3%Language:CSS 4.7%Language:PHP 0.6%Language:Java 0.3%Language:Shell 0.1%