Benchmark.js v1.0.0

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

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('String#match', function() {
!!'Hello World!'.match(/o/);
// add listeners
.on('cycle', function(event) {
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').pluck('name'));
// run async
.run({ 'async': true });

Download v1.0.0

Dive in

We’ve got API docs and unit tests.


Benchmark.js v1.0.0 has been tested in at least Adobe AIR 3.1, Chrome 5-26, Firefox 2-20, IE 6-10, Opera 9.25-12, Safari 3-6, Node.js v0.4.8-0.10.5, Narwhal 0.3.2, PhantomJS 1.9.0, RingoJS 0.9, and Rhino 1.7RC5.

Installation and usage

In a browser:

<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:


Via npm:

npm install benchmark

In Node.js and RingoJS v0.8.0+:

var Benchmark = require('benchmark');

Optionally, use the microtime module for Node.js by Wade Simmons:

npm install microtime

In RingoJS v0.7.0-:

var Benchmark = require('benchmark').Benchmark;

In Rhino:

Fork me on GitHub