Skip to content

Commit

Permalink
bench/ initial version of the benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromeetienne committed Feb 17, 2012
1 parent 389ffde commit 9669ceb
Show file tree
Hide file tree
Showing 29 changed files with 9,507 additions and 0 deletions.
1 change: 1 addition & 0 deletions bench/benchmark.js/.gitattributes
@@ -0,0 +1 @@
* text=auto
4 changes: 4 additions & 0 deletions bench/benchmark.js/.gitignore
@@ -0,0 +1,4 @@
.DS_Store
node_modules/
tests/benchmark.air/src/*.js
tests/benchmark.air/bin-debug/
15 changes: 15 additions & 0 deletions bench/benchmark.js/.gitmodules
@@ -0,0 +1,15 @@
[submodule "vendor/qunit"]
path = vendor/qunit
url = git://github.com/jquery/qunit.git
[submodule "vendor/docdown"]
path = vendor/docdown
url = git://github.com/jdalton/docdown.git
[submodule "vendor/requirejs"]
path = vendor/requirejs
url = git://github.com/jrburke/requirejs.git
[submodule "vendor/platform.js"]
path = vendor/platform.js
url = git://github.com/bestiejs/platform.js.git
[submodule "vendor/qunit-clib"]
path = vendor/qunit-clib
url = git://github.com/jdalton/qunit-clib.git
8 changes: 8 additions & 0 deletions bench/benchmark.js/.npmignore
@@ -0,0 +1,8 @@
.*
nano.*
examples/
plugins/
vendor/
docs/*.php
tests/*.air
tests/*.html
22 changes: 22 additions & 0 deletions bench/benchmark.js/LICENSE.txt
@@ -0,0 +1,22 @@
Copyright 2010-2012 Mathias Bynens <http://mathiasbynens.be/>
Based on JSLitmus.js, copyright Robert Kieffer <http://broofa.com/>
Modified by John-David Dalton <http://allyoucanleet.com/>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
151 changes: 151 additions & 0 deletions bench/benchmark.js/README.md
@@ -0,0 +1,151 @@
# Benchmark.js

A [robust](http://calendar.perfplanet.com/2010/bulletproof-javascript-benchmarks/ "Bulletproof JavaScript benchmarks") benchmarking library that works on nearly all JavaScript platforms<sup><a name="fnref1" href="#fn1">1</a></sup>, supports high-resolution timers, and returns statistically significant results. As seen on [jsPerf](http://jsperf.com/).

## 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, and plenty of documentation.

## Documentation

The documentation for Benchmark.js can be viewed here: <http://benchmarkjs.com/docs>

For a list of upcoming features, check out our [roadmap](https://github.com/bestiejs/benchmark.js/wiki/Roadmap).

## Installation and usage

In a browser or Adobe AIR:

~~~ html
<script src="benchmark.js"></script>
~~~

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

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

Or enable Chrome’s microsecond timer by using the [command line switch](http://peter.sh/experiments/chromium-command-line-switches/#enable-benchmarking):

--enable-benchmarking

Via [npm](http://npmjs.org/):

~~~ bash
npm install benchmark
~~~

In [Node.js](http://nodejs.org/) and [RingoJS v0.8.0+](http://ringojs.org/):

~~~ js
var Benchmark = require('benchmark');
~~~

Optionally, use the [microtime module](https://github.com/wadey/node-microtime) by Wade Simmons:

~~~ bash
npm install microtime
~~~

In [Narwhal](http://narwhaljs.org/) and [RingoJS v0.7.0-](http://ringojs.org/):

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

In [Rhino](http://www.mozilla.org/rhino/):

~~~ js
load('benchmark.js');
~~~

In [RequireJS](http://requirejs.org/):

~~~ js
require({
'paths': {
'benchmark': 'path/to/benchmark'
}
},
['benchmark'], function(Benchmark) {
console.log(Benchmark.version);
});

// or with platform.js
// https://github.com/bestiejs/platform.js
require({
'paths': {
'benchmark': 'path/to/benchmark',
'platform': 'path/to/platform'
}
},
['benchmark', 'platform'], function(Benchmark, platform) {
Benchmark.platform = platform;
console.log(Benchmark.platform.name);
});
~~~

Usage example:

~~~ js
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, bench) {
console.log(String(bench));
})
.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
~~~

## Cloning this repo

To clone this repository including all submodules, using Git 1.6.5 or later:

~~~ bash
git clone --recursive https://github.com/bestiejs/benchmark.js.git
cd benchmark.js
~~~

For older Git versions, just use:

~~~ bash
git clone https://github.com/bestiejs/benchmark.js.git
cd benchmark.js
git submodule update --init
~~~

Feel free to fork if you see possible improvements!

## Footnotes

1. Benchmark.js has been tested in at least Adobe AIR 2.6, Chrome 5-15, Firefox 1.5-8, IE 6-10, Opera 9.25-11.52, Safari 2-5.1.1, Node.js 0.4.8-0.6.1, Narwhal 0.3.2, RingoJS 0.7-0.8, and Rhino 1.7RC3.
<a name="fn1" title="Jump back to footnote 1 in the text." href="#fnref1">&#8617;</a>

## Authors

* [Mathias Bynens](http://mathiasbynens.be/)
[![twitter/mathias](http://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](https://twitter.com/mathias "Follow @mathias on Twitter")
* [John-David Dalton](http://allyoucanleet.com/)
[![twitter/jdalton](http://gravatar.com/avatar/299a3d891ff1920b69c364d061007043?s=70)](https://twitter.com/jdalton "Follow @jdalton on Twitter")

## Contributors

* [Kit Cambridge](http://kitcambridge.github.com/)
[![twitter/kitcambridge](http://gravatar.com/avatar/6662a1d02f351b5ef2f8b4d815804661?s=70)](https://twitter.com/kitcambridge "Follow @kitcambridge on Twitter")

0 comments on commit 9669ceb

Please sign in to comment.