forked from wadey/node-microtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
30 lines (24 loc) · 738 Bytes
/
test.js
File metadata and controls
30 lines (24 loc) · 738 Bytes
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()
, minDiff = Infinity
, minCycles = 10000
, maxCycles = 100000
, cycles = maxCycles
for (var i = 0; i < cycles; ++i) {
var a = microtime.now()
, b = microtime.now()
, 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")
}