https://github.com/ryanve/lap
JavaScript performance testing library
https://github.com/ryanve/lap
javascript performance timestamp
Last synced: 9 months ago
JSON representation
JavaScript performance testing library
- Host: GitHub
- URL: https://github.com/ryanve/lap
- Owner: ryanve
- License: mit
- Created: 2014-03-03T05:16:24.000Z (over 12 years ago)
- Default Branch: gh-pages
- Last Pushed: 2016-12-11T02:21:31.000Z (over 9 years ago)
- Last Synced: 2025-04-02T18:56:26.904Z (over 1 year ago)
- Topics: javascript, performance, timestamp
- Language: JavaScript
- Homepage: https://ryanve.github.io/lap
- Size: 31.3 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE-MIT
Awesome Lists containing this project
README
# lap
#### JavaScript performance testing library for the browser or server
- 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`](#async-sync) 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](#methods-toc) 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