Callback function.
Callback function.
Callback function.
Times a snippet.
state
parameter is simply an empty object which allows the before
, after
, and code
snippets to share state.snippet to time
callback to invoke upon completion
var code = '';
code += 'var x = Math.pow( Math.random(), 3 );';
code += 'if ( x !== x ) {';
code += 'throw new Error( \'Something went wrong.\' );';
code += '}';
timeit( code, done );
function done( error, results ) {
if ( error ) {
throw error;
}
console.dir( results );
}
Times a snippet.
asynchronous
option is set to true
, the implementation assumes that before
, after
, and code
snippets are all asynchronous. Accordingly, these snippets should invoke a next( [error] )
callback once complete. The implementation wraps the snippet within a function accepting two arguments: state
and next
.state
parameter is simply an empty object which allows the before
, after
, and code
snippets to share state.asynchronous
option is true
, ensure that the main code
snippet is actually asynchronous. If a snippet releases the zalgo, an error complaining about exceeding the maximum call stack size is highly likely.snippet to time
function options
callback to invoke upon completion
var code = 'var x = Math.pow( Math.random(), 3 );';
code += 'if ( x !== x ) {';
code += 'var err = new Error( \'Something went wrong.\' );';
code += 'next( err );';
code += '}';
code += 'process.nextTick( next );';
var opts = {
'iterations': 1e2,
'asynchronous': true
};
timeit( code, opts, done );
function done( error, results ) {
if ( error ) {
throw error;
}
console.dir( results );
}
Callback function.
encountered error or null
timing results