UNPKG

897 Btext/coffeescriptView Raw
1durations = require './src/index.coffee'
2
3watch = durations.stopwatch()
4console.log "Duration should be zero:", watch.duration().nanos()
5console.log "Formatted, no time registered: ", watch.duration().format()
6console.log "Should be same format as above:", watch.format()
7
8watch = durations.stopwatch().start()
9console.log "Duration should be non-zero:", watch.duration().nanos()
10watch.stop()
11console.log "Formatted duration, with time: ", watch.duration().format()
12console.log "Should be same format as above:", watch.format()
13
14console.log "Format on creation: ",
15 durations.stopwatch().start().stop().format()
16
17action = ->
18 num for num in [1 .. 5000000]
19
20actionAsync = (next) ->
21 num for num in [5000000 .. 10000000]
22 next()
23
24durations.timeAsync(actionAsync).then((duration) ->
25 console.log "Async timing:", duration.format()
26)
27
28console.log "Sync timing:", durations.time(action).format()
29