Stop! Hammer time.
hammer(config).time(fn);
Wait... Should this be hammer(fn).time(config)
or hammer(config).time(fn)
?!
npm install hammertime
A configuration object can be passed to the hammer
function to configure the context for the timer.
before
- function to run as setup, passed a callback to invoke when complete.after
- function to run after timer runs, results fromtime
are passed to this function.iterations
- number of iterations, default is100
.
Configuration can also be performed by composition as seen in some examples below.
hammer(config)
- create and configure a timer context.
Example:
var hammer = require('hammertime');
hammer({
before: function (next) {
next();
},
after: function (results) {
console.dir(results);
},
iterations: 500
});
Once hammer()
is called, an object will be returned with the following functions.
before(fn)
- function to run beforetime
, in lieu of configuration option.fn
is passed a callback to invoke when complete.time(fn)
- begins the iterations offn
.fn
can be asynchronous if a callback argument is supplied.
Example:
hammer()
.before(function (next) {
next();
})
.time(function (next) {
asyncFunction(function (result) {
next();
});
});
time
will also return an object that provides a single function:
after(fn)
- function to run aftertime
's iterations, in lieu of configuration option.fn
is passed the results oftime
.
Example:
hammer()
.time(fn)
.after(function (results) {
console.dir(results);
});
iterations
- number of completed iterations.time
- time, in microseconds, that it took to complete.ops
- operations per second.