lap
#### JavaScript performance testing library for the browser or server
API
#### Methods
-
lap.time(laps, racers)
-
lap.speed(laps, racers)
-
lap.timestamp()
#### Parameters
-
laps refers to number of laps to run (positive integer)
-
racers refers to function(s) to race (array or single function)
#### Usage tips
- Use JavaScript exponential notation like
1e3 (rather than
1000) for expressing large numbers
- Accurate results require many
laps. The ideal amount depends on how complex the racers are:
-
Infinity speeds and
0 times both indicate inadequate
laps
- Results taking too long indicates excessive
laps. Use less
laps or use the
.async syntax
####
lap.time(laps, racers)
- Time how long it takes each racer to run the given number of laps
-
@return array of times measured in milliseconds
#####
.time example
``
js
lap.time(1e5, [
function() { document.getElementById('example') },
function() { document.querySelector('#example') },
function() { document.querySelectorAll('#example')[0] }
]) // => [40.000000000873115, 44.99999999825377, 116.00000000180444]
`
#### lap.speed(laps, racers)
- Estimate each racer's average speed over a course of laps
- @return array of speeds measured in operations per second
##### .speed
example
`
js
lap.speed(1e5, [
function() { document.getElementById('example') },
function() { document.querySelector('#example') },
function() { document.querySelectorAll('#example')[0] }
]) // => [2500000.0004001777, 2222222.2219491494, 884955.7522315352]
`
#### lap.timestamp()
- Get a hi-resolution timestamp
- @return number measured in milliseconds
##### .timestamp
example
`
js
lap.timestamp() // => 1610.000000000582
`
#### .async
- Methods are callable .async
with the same arguments plus a (err, result)
callback
- @return undefined
##### .async
syntax
- lap.time.async(laps, racers, callback)
- lap.speed.async(laps, racers, callback)
- lap.timestamp.async(callback)
##### .async
example
`
js
lap.time.async(1e5, function() {
[].concat([0, 1, 2, 3])
}, function(err, result) {
err || console.log(result[0] + ' ms')
}) // => undefined
`
#### .sync
.sync
methods are included for expressiveness but these are just aliases. lap.time === lap.time.sync
etc.
##### .sync
example
`
js
lap.time.sync(1e5, [
function() { document.getElementById('example') },
function() { document.querySelector('#example') },
function() { document.querySelectorAll('#example')[0] }
]) // => [40.000000000873115, 45.99999999481952, 115.00000000523869]
`
Compatibility
Works...everywhere! Tested in node, Chrome, FF, Opera, IE8
Contribute
`
sh
$ npm start
$ npm test
``