1 |
|
2 | Stopwatch
|
3 | ===========
|
4 |
|
5 | A stopwatch class built around [`process.hrtime()`](http://nodejs.org/api/process.html#process_process_hrtime),
|
6 | with all the usual stopwatch methods like "start" and "stop".
|
7 |
|
8 | Timer
|
9 | =====
|
10 |
|
11 | Times the execution of a function, and returns the duration.
|
12 |
|
13 | Installation
|
14 | ============
|
15 |
|
16 | npm install --save durations
|
17 |
|
18 | Usage
|
19 | =====
|
20 |
|
21 | durations = require 'durations'
|
22 |
|
23 | watch = durations.stopwatch()
|
24 | watch.stop() # Pauses the stopwatch. Returns the stopwatch.
|
25 | watch.start() # Starts the stopwatch from where it was last stopped. Returns the stopwatch.
|
26 | watch.reset() # Reset the stopwatch (duration is set back to zero). Returns the stopwatch.
|
27 | duration = watch.duration() # Returns the Duration.
|
28 |
|
29 |
|
30 | durations.time(someFunction)
|
31 | .then (duration) ->
|
32 | console.log "Took", duration.format(), "to do something."
|
33 |
|
34 |
|
35 | Compatibilty
|
36 | ============
|
37 |
|
38 | The `durations` module uses `process.hrtime()`, therefore it will work only in node.js, not in browsers.
|
39 |
|