performance-now.coffee 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. assert = require "assert"
  2. delay = (ms, fn) -> setTimeout fn, ms
  3. now = undefined
  4. describe "now", ->
  5. it "initially gives a near zero (< 20 ms) time ", ->
  6. now = require "../"
  7. assert now() < 20
  8. it "gives a positive time", ->
  9. assert now() > 0
  10. it "two subsequent calls return an increasing number", ->
  11. a = now()
  12. b = now()
  13. assert now() < now()
  14. it "has less than 10 microseconds overhead", ->
  15. Math.abs(now() - now()) < 0.010
  16. it "can do 1,000,000 calls really quickly", ->
  17. now() for i in [0...1000000]
  18. it "shows that at least 990 ms has passed after a timeout of 1 second", (done) ->
  19. a = now()
  20. delay 1000, ->
  21. b = now()
  22. diff = b - a
  23. return done new Error "Diff (#{diff}) lower than 990." if diff < 990
  24. return done null
  25. it "shows that not more than 1020 ms has passed after a timeout of 1 second", (done) ->
  26. a = now()
  27. delay 1000, ->
  28. b = now()
  29. diff = b - a
  30. return done new Error "Diff (#{diff}) higher than 1020." if diff > 1020
  31. return done null