-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.coffee
executable file
·38 lines (26 loc) · 1.06 KB
/
example.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
37
#!/usr/bin/env coffee
isNode = if process?.hrtime()? then true else false
console.log "hrtime output is:", process.hrtime()
console.log "time is:", new Date().getTime()
console.log "Is Node.js: #{isNode}"
{stopwatch, time: timeSync, timeAsync} = require './src/index.coffee'
watch = stopwatch()
console.log "Duration should be zero:", watch.duration().nanos()
console.log "Formatted, no time registered: ", watch.duration().format()
console.log "Should be same format as above:", watch.format()
watch = stopwatch().start()
console.log "Duration should be non-zero:", watch.duration().nanos()
watch.stop()
console.log "Formatted duration, with time: ", watch.duration().format()
console.log "Should be same format as above:", watch.format()
console.log "Format on creation: ",
stopwatch().start().stop().format()
action = ->
num for num in [1 .. 5000000]
actionAsync = (next) ->
num for num in [5000000 .. 10000000]
next()
timeAsync(actionAsync, ((duration) ->
console.log "Async timing:", duration.format()
))
console.log "Sync timing:", timeSync(action).format()