Benchmark.prototypeBenchmark.prototype.abortedBenchmark.prototype.compiledBenchmark.prototype.countBenchmark.prototype.cyclesBenchmark.prototype.errorBenchmark.prototype.fnBenchmark.prototype.hzBenchmark.prototype.runningBenchmark.prototype.setupBenchmark.prototype.teardownBenchmark.prototype.abortBenchmark.prototype.cloneBenchmark.prototype.compareBenchmark.prototype.emitBenchmark.prototype.listenersBenchmark.prototype.offBenchmark.prototype.onBenchmark.prototype.resetBenchmark.prototype.runBenchmark.prototype.toStringBenchmark.optionsBenchmark.optionsBenchmark.options.asyncBenchmark.options.deferBenchmark.options.delayBenchmark.options.idBenchmark.options.initCountBenchmark.options.maxTimeBenchmark.options.minSamplesBenchmark.options.minTimeBenchmark.options.nameBenchmark.options.onAbortBenchmark.options.onCompleteBenchmark.options.onCycleBenchmark.options.onErrorBenchmark.options.onResetBenchmark.options.onStartBenchmark.platformBenchmark.supportBenchmark.supportBenchmark.support.airBenchmark.support.argumentsClassBenchmark.support.browserBenchmark.support.charByIndexBenchmark.support.charByOwnIndexBenchmark.support.decompilationBenchmark.support.descriptorsBenchmark.support.getAllKeysBenchmark.support.iteratesOwnLastBenchmark.support.javaBenchmark.support.nodeClassBenchmark.support.timeoutBenchmark.prototype.statsBenchmark.prototype.timesBenchmark.DeferredBenchmark.Deferred.prototypeBenchmark.EventBenchmark.Event.prototypeBenchmark.SuiteBenchmark.Suite.prototypeBenchmark.Suite.prototype.abortedBenchmark.Suite.prototype.lengthBenchmark.Suite.prototype.runningBenchmark.Suite.prototype.abortBenchmark.Suite.prototype.addBenchmark.Suite.prototype.cloneBenchmark.Suite.prototype.emitBenchmark.Suite.prototype.filterBenchmark.Suite.prototype.forEachBenchmark.Suite.prototype.indexOfBenchmark.Suite.prototype.invokeBenchmark.Suite.prototype.joinBenchmark.Suite.prototype.listenersBenchmark.Suite.prototype.mapBenchmark.Suite.prototype.offBenchmark.Suite.prototype.onBenchmark.Suite.prototype.pluckBenchmark.Suite.prototype.popBenchmark.Suite.prototype.pushBenchmark.Suite.prototype.reduceBenchmark.Suite.prototype.resetBenchmark.Suite.prototype.reverseBenchmark.Suite.prototype.runBenchmark.Suite.prototype.shiftBenchmark.Suite.prototype.sliceBenchmark.Suite.prototype.sortBenchmark.Suite.prototype.spliceBenchmark.Suite.prototype.unshiftBenchmark.Suite.optionsBenchmarkBenchmark(name, fn [, options={}])The Benchmark constructor.
name (String): A name to identify the benchmark.fn (Function|String): The test to benchmark.[options={}] (Object): Options object.// basic usage (the `new` operator is optional)
var bench = new Benchmark(fn);
// or using a name first
var bench = new Benchmark('foo', fn);
// or with options
var bench = new Benchmark('foo', fn, {
// displayed by Benchmark#toString if `name` is not available
'id': 'xyz',
// called when the benchmark starts running
'onStart': onStart,
// called after each run cycle
'onCycle': onCycle,
// called when aborted
'onAbort': onAbort,
// called when a test errors
'onError': onError,
// called when reset
'onReset': onReset,
// called when the benchmark completes running
'onComplete': onComplete,
// compiled/called before the test loop
'setup': setup,
// compiled/called after the test loop
'teardown': teardown
});
// or name and options
var bench = new Benchmark('foo', {
// a flag to indicate the benchmark is deferred
'defer': true,
// benchmark test function
'fn': function(deferred) {
// call resolve() when the deferred test is finished
deferred.resolve();
}
});
// or options only
var bench = new Benchmark({
// benchmark name
'name': 'foo',
// benchmark test as a string
'fn': '[1,2,3,4].sort()'
});
// a test’s `this` binding is set to the benchmark instance
var bench = new Benchmark('foo', function() {
'My name is '.concat(this.name); // My name is foo
});
Benchmark.deepClone(value)A deep clone utility.
value (Mixed): The value to clone.(Mixed): The cloned value.
Benchmark.each(object, callback, thisArg)An iteration utility for arrays and objects. Callbacks may terminate the loop by explicitly returning false.
object (Array|Object): The object to iterate over.callback (Function): The function called per iteration.thisArg (Mixed): The this binding for the callback.(Array, Object): Returns the object iterated over.
Benchmark.extend(destination [, source={}])Copies enumerable properties from the source(s) object to the destination object.
destination (Object): The destination object.[source={}] (Object): The source object.(Object): The destination object.
Benchmark.filter(array, callback, thisArg)A generic Array#filter like method.
array (Array): The array to iterate over.callback (Function|String): The function/alias called per iteration.thisArg (Mixed): The this binding for the callback.(Array): A new array of values that passed callback filter.
// get odd numbers
Benchmark.filter([1, 2, 3, 4, 5], function(n) {
return n % 2;
}); // -> [1, 3, 5];
// get fastest benchmarks
Benchmark.filter(benches, 'fastest');
// get slowest benchmarks
Benchmark.filter(benches, 'slowest');
// get benchmarks that completed without erroring
Benchmark.filter(benches, 'successful');
Benchmark.forEach(array, callback, thisArg)A generic Array#forEach like method. Callbacks may terminate the loop by explicitly returning false.
array (Array): The array to iterate over.callback (Function): The function called per iteration.thisArg (Mixed): The this binding for the callback.(Array): Returns the array iterated over.
Benchmark.formatNumber(number)Converts a number to a more readable comma-separated string representation.
number (Number): The number to convert.(String): The more readable string representation.
Benchmark.forOwn(object, callback, thisArg)Iterates over an object’s own properties, executing the callback for each. Callbacks may terminate the loop by explicitly returning false.
object (Object): The object to iterate over.callback (Function): The function executed per own property.thisArg (Mixed): The this binding for the callback.(Object): Returns the object iterated over.
Benchmark.hasKey(object, key)Checks if an object has the specified key as a direct property.
object (Object): The object to check.key (String): The key to check for.(Boolean): Returns true if key is a direct property, else false.
Benchmark.indexOf(array, value [, fromIndex=0])A generic Array#indexOf like method.
array (Array): The array to iterate over.value (Mixed): The value to search for.[fromIndex=0] (Number): The index to start searching from.(Number): The index of the matched value or -1.
Benchmark.interpolate(string, object)Modify a string by replacing named tokens with matching object property values.
string (String): The string to modify.object (Object): The template object.(String): The modified string.
Benchmark.invoke(benches, name [, arg1, arg2, …])Invokes a method on all items in an array.
benches (Array): Array of benchmarks to iterate over.name (String|Object): The name of the method to invoke OR options object.[arg1, arg2, …] (Mixed): Arguments to invoke the method with.(Array): A new array of values returned from each method invoked.
// invoke `reset` on all benchmarks
Benchmark.invoke(benches, 'reset');
// invoke `emit` with arguments
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',
// pass a single argument
'args': true,
// treat as queue, removing benchmarks from front of `benches` until empty
'queued': true,
// called before any benchmarks have been invoked.
'onStart': onStart,
// called between invoking benchmarks
'onCycle': onCycle,
// called after all benchmarks have been invoked.
'onComplete': onComplete
});
Benchmark.join(object [, separator1=',', separator2=': '])Creates a string of joined array values or object key-value pairs.
object (Array|Object): The object to operate on.[separator1=','] (String): The separator used between key-value pairs.[separator2=': '] (String): The separator used between keys and values.(String): The joined result.
Benchmark.map(array, callback, thisArg)A generic Array#map like method.
array (Array): The array to iterate over.callback (Function): The function called per iteration.thisArg (Mixed): The this binding for the callback.(Array): A new array of values returned by the callback.
Benchmark.prototypeBenchmark.prototype.setup(Function, String): Compiled into the test and executed immediately before the test loop.
// basic usage
var bench = Benchmark({
'setup': function() {
var c = this.count,
element = document.getElementById('container');
while (c--) {
element.appendChild(document.createElement('div'));
}
},
'fn': function() {
element.removeChild(element.lastChild);
}
});
// compiles to something like:
var c = this.count,
element = document.getElementById('container');
while (c--) {
element.appendChild(document.createElement('div'));
}
var start = new Date;
while (count--) {
element.removeChild(element.lastChild);
}
var end = new Date - start;
// or using strings
var bench = Benchmark({
'setup': '\
var a = 0;\n\
(function() {\n\
(function() {\n\
(function() {',
'fn': 'a += 1;',
'teardown': '\
}())\n\
}())\n\
}())'
});
// compiles to something like:
var a = 0;
(function() {
(function() {
(function() {
var start = new Date;
while (count--) {
a += 1;
}
var end = new Date - start;
}())
}())
}())
Benchmark.prototype.teardown(Function, String): Compiled into the test and executed immediately after the test loop.
Benchmark.prototype.abort()Aborts the benchmark without recording times.
(Object): The benchmark instance.
Benchmark.prototype.clone(options)Creates a new benchmark using the same test and options.
options (Object): Options object to overwrite cloned options.(Object): The new benchmark instance.
var bizarro = bench.clone({
'name': 'doppelganger'
});
Benchmark.prototype.compare(other)Determines if a benchmark is faster than another.
other (Object): The benchmark to compare.(Number): Returns -1 if slower, 1 if faster, and 0 if indeterminate.
Benchmark.Suite.prototype.emit(type)Executes all registered listeners of the specified event type.
type (String|Object): The event type or object.(Mixed): Returns the return value of the last listener executed.
Benchmark.Suite.prototype.listeners(type)Returns an array of event listeners for a given type that can be manipulated to add or remove listeners.
type (String): The event type.(Array): The listeners array.
Benchmark.Suite.prototype.off([type, listener])Unregisters a listener for the specified event type(s), or unregisters all listeners for the specified event type(s), or unregisters all listeners for all event types.
[type] (String): The event type.[listener] (Function): The function to unregister.(Object): The benchmark instance.
// unregister a listener for an event type
bench.off('cycle', listener);
// unregister a listener for multiple event types
bench.off('start cycle', listener);
// unregister all listeners for an event type
bench.off('cycle');
// unregister all listeners for multiple event types
bench.off('start cycle complete');
// unregister all listeners for all event types
bench.off();
Benchmark.Suite.prototype.on(type, listener)Registers a listener for the specified event type(s).
type (String): The event type.listener (Function): The function to register.(Object): The benchmark instance.
// register a listener for an event type
bench.on('cycle', listener);
// register a listener for multiple event types
bench.on('start cycle', listener);
Benchmark.prototype.reset()Reset properties and abort if running.
(Object): The benchmark instance.
Benchmark.optionsBenchmark.options.async(Boolean): A flag to indicate that benchmark cycles will execute asynchronously by default.
Benchmark.options.id(String): Displayed by Benchmark#toString when a name is not available (auto-generated if absent).
Benchmark.options.initCount(Number): The default number of times to execute a test on a benchmark’s first cycle.
Benchmark.options.maxTime(Number): The maximum time a benchmark is allowed to run before finishing (secs).
Note: Cycle delays aren't counted toward the maximum time.
Benchmark.options.minSamples(Number): The minimum sample size required to perform statistical analysis.
Benchmark.platformBenchmark.supportBenchmark.support.argumentsClass(Boolean): Detect if arguments objects have the correct internal [[Class]] value.
Benchmark.support.iteratesOwnFirst(Boolean): Detect if own properties are iterated before inherited properties (all but IE < 9).
Benchmark.prototype.statsBenchmark.prototype.stats(Object): An object of stats including mean, margin or error, and standard deviation.
Benchmark.prototype.timesBenchmark.DeferredBenchmark.Deferred.prototypeBenchmark.Deferred.prototype.cycles(Number): The number of deferred cycles performed while benchmarking.
Benchmark.EventBenchmark.Event.prototypeBenchmark.Event.prototype.aborted(Boolean): A flag to indicate if the emitters listener iteration is aborted.
Benchmark.Event.prototype.cancelled(Boolean): A flag to indicate if the default action is cancelled.
Benchmark.Event.prototype.currentTarget(Object): The object whose listeners are currently being processed.
Benchmark.SuiteBenchmark.Suite(name [, options={}])The Suite constructor.
name (String): A name to identify the suite.[options={}] (Object): Options object.// basic usage (the `new` operator is optional)
var suite = new Benchmark.Suite;
// or using a name first
var suite = new Benchmark.Suite('foo');
// or with options
var suite = new Benchmark.Suite('foo', {
// called when the suite starts running
'onStart': onStart,
// called between running benchmarks
'onCycle': onCycle,
// called when aborted
'onAbort': onAbort,
// called when a test errors
'onError': onError,
// called when reset
'onReset': onReset,
// called when the suite completes running
'onComplete': onComplete
});
Benchmark.Suite.prototypeBenchmark.Suite.prototype.abort()Aborts all benchmarks in the suite.
(Object): The suite instance.
Benchmark.Suite.prototype.add(name, fn [, options={}])Adds a test to the benchmark suite.
name (String): A name to identify the benchmark.fn (Function|String): The test to benchmark.[options={}] (Object): Options object.(Object): The benchmark instance.
// basic usage
suite.add(fn);
// or using a name first
suite.add('foo', fn);
// or with options
suite.add('foo', fn, {
'onCycle': onCycle,
'onComplete': onComplete
});
// or name and options
suite.add('foo', {
'fn': fn,
'onCycle': onCycle,
'onComplete': onComplete
});
// or options only
suite.add({
'name': 'foo',
'fn': fn,
'onCycle': onCycle,
'onComplete': onComplete
});
Benchmark.Suite.prototype.clone(options)Creates a new suite with cloned benchmarks.
options (Object): Options object to overwrite cloned options.(Object): The new suite instance.
Benchmark.Suite.prototype.emit(type)Executes all registered listeners of the specified event type.
type (String|Object): The event type or object.(Mixed): Returns the return value of the last listener executed.
Benchmark.Suite.prototype.filter(callback)An Array#filter like method.
callback (Function|String): The function/alias called per iteration.(Object): A new suite of benchmarks that passed callback filter.
Benchmark.Suite.prototype.forEach(callback)An Array#forEach like method. Callbacks may terminate the loop by explicitly returning false.
callback (Function): The function called per iteration.(Object): The suite iterated over.
Benchmark.Suite.prototype.indexOf(value)An Array#indexOf like method.
value (Mixed): The value to search for.(Number): The index of the matched value or -1.
Benchmark.Suite.prototype.invoke(name [, arg1, arg2, …])Invokes a method on all benchmarks in the suite.
name (String|Object): The name of the method to invoke OR options object.[arg1, arg2, …] (Mixed): Arguments to invoke the method with.(Array): A new array of values returned from each method invoked.
Benchmark.Suite.prototype.join([separator=','])Converts the suite of benchmarks to a string.
[separator=','] (String): A string to separate each element of the array.(String): The string.
Benchmark.Suite.prototype.listeners(type)Returns an array of event listeners for a given type that can be manipulated to add or remove listeners.
type (String): The event type.(Array): The listeners array.
Benchmark.Suite.prototype.map(callback)An Array#map like method.
callback (Function): The function called per iteration.(Array): A new array of values returned by the callback.
Benchmark.Suite.prototype.off([type, listener])Unregisters a listener for the specified event type(s), or unregisters all listeners for the specified event type(s), or unregisters all listeners for all event types.
[type] (String): The event type.[listener] (Function): The function to unregister.(Object): The benchmark instance.
// unregister a listener for an event type
bench.off('cycle', listener);
// unregister a listener for multiple event types
bench.off('start cycle', listener);
// unregister all listeners for an event type
bench.off('cycle');
// unregister all listeners for multiple event types
bench.off('start cycle complete');
// unregister all listeners for all event types
bench.off();
Benchmark.Suite.prototype.on(type, listener)Registers a listener for the specified event type(s).
type (String): The event type.listener (Function): The function to register.(Object): The benchmark instance.
// register a listener for an event type
bench.on('cycle', listener);
// register a listener for multiple event types
bench.on('start cycle', listener);
Benchmark.Suite.prototype.pluck(property)Retrieves the value of a specified property from all benchmarks in the suite.
property (String): The property to pluck.(Array): A new array of property values.
Benchmark.Suite.prototype.pop()Removes the last benchmark from the suite and returns it.
(Mixed): The removed benchmark.
Benchmark.Suite.prototype.push()Appends benchmarks to the suite.
(Number): The suite’s new length.
Benchmark.Suite.prototype.reduce(callback, accumulator)An Array#reduce like method.
callback (Function): The function called per iteration.accumulator (Mixed): Initial value of the accumulator.(Mixed): The accumulator.
Benchmark.Suite.prototype.reset()Resets all benchmarks in the suite.
(Object): The suite instance.
Benchmark.Suite.prototype.reverse()Rearrange the host array’s elements in reverse order.
(Array): The reversed array.
Benchmark.Suite.prototype.run([options={}])Runs the suite.
[options={}] (Object): Options object.(Object): The suite instance.
// basic usage
suite.run();
// or with options
suite.run({ 'async': true, 'queued': true });
Benchmark.Suite.prototype.shift()Removes the first element of the host array and returns it.
(Mixed): The first element of the array.
Benchmark.Suite.prototype.slice(start, end)Creates an array of the host array’s elements from the start index up to, but not including, the end index.
start (Number): The starting index.end (Number): The end index.(Array): The new array.
Benchmark.Suite.prototype.sort([compareFn=null])Sorts the benchmarks of the suite.
[compareFn=null] (Function): A function that defines the sort order.(Object): The sorted suite.
Benchmark.Suite.prototype.splice(start, deleteCount [, val1, val2, …])Allows removing a range of elements and/or inserting elements into the host array.
start (Number): The start index.deleteCount (Number): The number of elements to delete.[val1, val2, …] (Mixed): values to insert at the start index.(Array): An array of removed elements.