Stopwatch for high-resolution timing
Last updated 2 years ago by aleclarson .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install elaps 
SYNC missed versions from official npm registry.

elaps v2.3.2

Stopwatch for high-resolution timing

Powered by process.hrtime()

const elaps = require('elaps');

// create a started timer
let t = elaps('do something');

// create a stopped timer
t = elaps.lazy('do something');

// choose where the elapsed time is printed
elaps('did something in %t').stop();

// print the number of laps
elaps('did something %n times').stop();

// util.format placeholders are supported
elaps('do something: %O', {meta:'data'}).stop();

// args without a placeholder default to %O
elaps('do something:', {meta:'data'}).stop();

Stopwatch class


lap: ?Lap

The newest Lap object created by a start() call.

Equals null when the newest lap is stopped.

laps: number[]

The array of lap times in order of stop time.

elapsed: number

The time passed (in milliseconds) with 1+ laps counting.

Updated when a pause() or stop() call leads to this.pending being zero.

Note: This not the same as sum(), which combines the individual lap times.

pending: number

The number of pending laps (neither paused nor stopped).

msg: string

The message passed to the elaps constructor.

Printed by stop(true) and print() calls.

Use %t to print the elapsed time.

Use %n to print the number of laps.

log: Function

The function called by the print method.

Defaults to elaps.log || console.log.



start(): Lap

Start a new lap.

Update the value of this.lap to the new lap.

stop(print: boolean): this

Stop the current lap.

Pass true to print the lap time.

print(time: ?number): this

Print this.msg with given time (in milliseconds) or this.elapsed.

You can pass a string (followed by any other values) to override this.msg for one call only. To override both the time and message, the time must come first.

time(): number

Get the updated value of this.elapsed without pausing/stopping every pending lap.

sum(): number

Get the combined time (in milliseconds) of all stopped laps.

average(): number

Get the average time (in milliseconds) of all stopped laps.

pause(): this

Shorthand for this.lap.pause()

resume(): this

Shorthand for this.lap.resume()

reset(): this

Reset this to its initial state.

Any pending laps won't affect the new state.


Lap class


elapsed: number

The lap time. Updated by pause() and stop() calls.

paused: boolean

Equals true when paused. ????

timer: ?Stopwatch

The associated Stopwatch object.

Equals null once stopped.



stop(print: boolean): this

Stop counting.

Pass true to print the lap time.

time(): number

Get the updated value of this.elapsed without pausing/stopping.

pause(): this

Pause counting and allow for resuming in the future.

resume(): this

Resume counting.


Current Tags

  • 2.3.2                                ...           latest (2 years ago)

15 Versions

  • 2.3.2                                ...           2 years ago
  • 2.3.1                                ...           2 years ago
  • 2.3.0                                ...           2 years ago
  • 2.2.0                                ...           2 years ago
  • 2.1.0                                ...           2 years ago
  • 2.0.0                                ...           2 years ago
  • 1.5.1                                ...           2 years ago
  • 1.5.0                                ...           2 years ago
  • 1.4.0                                ...           2 years ago
  • 1.3.0                                ...           2 years ago
  • 1.2.0                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 2
Last Month 3
Dependencies (2)
Dev Dependencies (0)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |