UNPKG

999 BMarkdownView Raw
1
2Stopwatch
3===========
4
5A stopwatch class built around [`process.hrtime()`](http://nodejs.org/api/process.html#process_process_hrtime),
6with all the usual stopwatch methods like "start" and "stop".
7
8Timer
9=====
10
11Times the execution of a function, and returns the duration.
12
13Installation
14============
15
16 npm install --save durations
17
18Usage
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
35Compatibilty
36============
37
38The `durations` module uses `process.hrtime()`, therefore it will work only in node.js, not in browsers.
39