forked from wadey/node-microtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
30 lines (24 loc) · 738 Bytes
/
test.js
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
var microtime = require('./index')
console.log('microtime.now() =', microtime.now())
console.log('microtime.nowDouble() =', microtime.nowDouble())
console.log('microtime.nowStruct() =', microtime.nowStruct())
console.log('\nGuessing clock resolution...')
var start = microtime.now()
var minDiff = Infinity
var minCycles = 10000
var maxCycles = 100000
var cycles = maxCycles
for (var i = 0; i < cycles; ++i) {
var a = microtime.now()
var b = microtime.now()
var diff = (b - a) || (b - start)
if (diff > 0 && diff < minDiff) {
minDiff = diff
cycles = minCycles
}
}
if (minDiff === Infinity) {
console.log('Unable to guess clock resolution')
} else {
console.log('Clock resolution observed: ' + minDiff + 'us')
}