twitst4tz

twitter statistics web application
Log | Files | Refs | README | LICENSE

performance-now.coffee (1497B)


      1 chai = require "chai"
      2 chai.use(require "chai-increasing")
      3 {assert,expect} = chai
      4 Bluebird = require "bluebird"
      5 
      6 now = require "../"
      7 
      8 getUptime = -> process.uptime() * 1e3
      9 
     10 describe "now", ->
     11   it "reported time differs at most 1ms from a freshly reported uptime", ->
     12     assert.isAtMost Math.abs(now()-getUptime()), 1
     13 
     14   it "two subsequent calls return an increasing number", ->
     15     assert.isBelow now(), now()
     16 
     17   it "has less than 10 microseconds overhead", ->
     18     assert.isBelow Math.abs(now() - now()), 0.010
     19 
     20   it "can be called 1 million times in under 1 second (averaging under 1 microsecond per call)", ->
     21     @timeout 1000
     22     now() for [0...1e6]
     23     undefined
     24 
     25   it "for 10,000 numbers, number n is never bigger than number n-1", ->
     26     stamps = (now() for [1...10000])
     27     expect(stamps).to.be.increasing
     28 
     29   it "shows that at least 0.2 ms has passed after a timeout of 1 ms", ->
     30     earlier = now()
     31     Bluebird.resolve().delay(1).then -> assert.isAbove (now()-earlier), 0.2
     32 
     33   it "shows that at most 3 ms has passed after a timeout of 1 ms", ->
     34     earlier = now()
     35     Bluebird.resolve().delay(1).then -> assert.isBelow (now()-earlier), 3
     36 
     37   it "shows that at least 190ms ms has passed after a timeout of 200ms", ->
     38     earlier = now()
     39     Bluebird.resolve().delay(200).then -> assert.isAbove (now()-earlier), 190
     40 
     41   it "shows that at most 220 ms has passed after a timeout of 200ms", ->
     42     earlier = now()
     43     Bluebird.resolve().delay(200).then -> assert.isBelow (now()-earlier), 220