An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# 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`](#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


```sh
$ npm start
$ npm test
```