Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Add a .npmignore file, and be consistent in the use of single quotes …
Browse files Browse the repository at this point in the history
…for strings in code and examples.
  • Loading branch information
mathiasbynens committed Jan 10, 2011
1 parent 7ed614a commit 1be9f60
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 41 deletions.
6 changes: 6 additions & 0 deletions .npmignore
@@ -0,0 +1,6 @@
.git*
examples/
docs*
plugins/
tests/
vendor/
22 changes: 11 additions & 11 deletions README.md
Expand Up @@ -37,37 +37,37 @@ In [Rhino](http://www.mozilla.org/rhino/):
Usage example:

function testA() {
/o/.test("Hello World!");
/o/.test('Hello World!');
}

function testB() {
"Hello World!".indexOf("o") > -1;
'Hello World!'.indexOf('o') > -1;
}

var benches = [
new Benchmark("RegExp#test", testA),
new Benchmark("String#indexOf", testB)
new Benchmark('RegExp#test', testA),
new Benchmark('String#indexOf', testB)
];

// add listeners
Benchmark.invoke(benches, "on", "complete", function() {
Benchmark.invoke(benches, 'on', 'complete', function() {
console.log( this.toString() );
});

// run benchmarks (async)
Benchmark.invoke(benches, {
"name": "run",
"args": true,
"onComplete": function() {
'name': 'run',
'args': true,
'onComplete': function() {
var a = benches[0],
b = benches[1],
rank = a.compare(b);

// report results
console.log(
a.name + " is " +
(rank == 0 ? " <indeterminate> " : rank > 0 ? "faster" : "slower") +
" than " + b.name
a.name + ' is ' +
(rank == 0 ? ' <indeterminate> ' : rank > 0 ? 'faster' : 'slower') +
' than ' + b.name
);
}
});
Expand Down
60 changes: 30 additions & 30 deletions benchmark.js
Expand Up @@ -86,37 +86,37 @@
* var bench = new Benchmark(fn);
*
* // or using a name first
* var bench = new Benchmark("foo", fn);
* var bench = new Benchmark('foo', fn);
*
* // or with options
* var bench = new Benchmark("foo", fn, {
* var bench = new Benchmark('foo', fn, {
*
* // displayed by Benchmark#toString if `name` is not available
* "id": "xyz",
* 'id': 'xyz',
*
* // called when the benchmark starts
* "onStart": onStart,
* 'onStart': onStart,
*
* // called after each run cycle
* "onCycle": onCycle,
* 'onCycle': onCycle,
*
* // called when aborted
* "onAbort": onAbort,
* 'onAbort': onAbort,
*
* // called when a test errors
* "onError": onError,
* 'onError': onError,
*
* // called when reset
* "onReset": onReset,
* 'onReset': onReset,
*
* // called when benchmark is complete
* "onComplete": onComplete,
* 'onComplete': onComplete,
*
* // compiled/called before the test loop
* "setup": setup,
* 'setup': setup,
*
* // compiled/called after the test loop
* "teardown": teardown
* 'teardown': teardown
* });
*/
function Benchmark(name, fn, options) {
Expand Down Expand Up @@ -453,7 +453,7 @@
* Restores recorded benchmark results.
* @private
* @param {Object} me The benchmark instance.
* @returns {Boolean} Returns true if results were restored, else false
* @returns {Boolean} Returns `true` if results were restored, else `false`.
*/
function restore(me) {
var data,
Expand Down Expand Up @@ -565,13 +565,13 @@
* }); // -> [1, 3, 5];
*
* // get fastest benchmarks
* Benchmark.filter(benches, "fastest");
* Benchmark.filter(benches, 'fastest');
*
* // get slowest benchmarks
* Benchmark.filter(benches, "slowest");
* Benchmark.filter(benches, 'slowest');
*
* // get benchmarks that completed without erroring
* Benchmark.filter(benches, "successful");
* Benchmark.filter(benches, 'successful');
*/
function filter(array, callback) {
var source;
Expand Down Expand Up @@ -634,7 +634,7 @@
* @member Benchmark
* @param {Object} object The object to check.
* @param {String} key The key to check for.
* @returns {Boolean} Returns true if key is a direct property, else false.
* @returns {Boolean} Returns `true` if key is a direct property, else `false`.
*/
function hasKey(object, key) {
var result,
Expand Down Expand Up @@ -687,31 +687,31 @@
* @example
*
* // invoke `reset` on all benchmarks
* Benchmark.invoke(benches, "reset");
* Benchmark.invoke(benches, 'reset');
*
* // invoke `emit` with arguments
* Benchmark.invoke(benches, "emit", "complete", listener);
* Benchmark.invoke(benches, 'emit', 'complete', listener);
*
* // invoke `run(true)`, treat benchmarks as a queue, and register invoke callbacks
* Benchmark.invoke(benches, {
*
* // invoke the `run` method
* "name": "run",
* 'name': 'run',
*
* // pass a single argument
* "args": true,
* 'args': true,
*
* // treat as queue, removing benchmarks from front of `benches` until empty
* "queued": true,
* 'queued': true,
*
* // called before any benchmarks have been invoked.
* "onStart": onStart,
* 'onStart': onStart,
*
* // called between invoking benchmarks
* "onCycle": onCycle,
* 'onCycle': onCycle,
*
* // called after all benchmarks have been invoked.
* "onComplete": onComplete
* 'onComplete': onComplete
* });
*/
function invoke(benches, name) {
Expand All @@ -726,7 +726,7 @@
function execute() {
var listeners;
if (async) {
// use "next" as a listener
// use `next` as a listener
bench.on('complete', next);
listeners = bench.events['complete'];
listeners.splice(0, 0, listeners.pop());
Expand Down Expand Up @@ -804,10 +804,10 @@
* @returns {String} The modified string.
* @example
*
* Benchmark.interpolate("#{greet} #{who}!", {
* "greet": "Hello",
* "who": "world"
* }); // -> "Hello world!"
* Benchmark.interpolate('#{greet} #{who}!', {
* 'greet': 'Hello',
* 'who': 'world'
* }); // -> 'Hello world!'
*/
function interpolate(string, object) {
string = string == null ? '' : string;
Expand Down Expand Up @@ -1050,7 +1050,7 @@
* @example
*
* var bizarro = bench.clone({
* "name": "doppelganger"
* 'name': 'doppelganger'
* });
*/
function clone(options) {
Expand Down

0 comments on commit 1be9f60

Please sign in to comment.