-
Notifications
You must be signed in to change notification settings - Fork 1
/
x.coffee
37 lines (27 loc) · 1.04 KB
/
x.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{duration, stopwatch, time: timeSync, timeAsync} = require './src/index'
##
## Example for README.md (better really work)
##
#{durations, stopwatch, time: timeSync, timeAsync} = require './src/index'
nanoseconds = 987654321
console.log "Duration is", duration(nanoseconds).format()
# Or, since toString() is an alias to format()
console.log "Duration is #{duration(nanoseconds)}"
watch = stopwatch()
watch.stop() # Pauses the stopwatch. Returns the stopwatch.
watch.start() # Starts the stopwatch from where it was last stopped. Returns the stopwatch.
watch.reset() # Reset the stopwatch (duration is set back to zero). Returns the stopwatch.
duration = watch.duration() # Returns the Duration.
# Synchronous work
someFunction = ->
count = 0
for c in [1 .. 1000000]
count += 1
console.log "Count is: #{count}"
console.log "Took #{timeSync(someFunction)} to do something"
# Asynchronous work
someOtherFunction = (next) ->
someFunction()
next()
timeAsync someOtherFunction, (duration) ->
console.log "Took #{duration} to do something else."