-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
45 lines (38 loc) · 1.35 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* @typedef {Object} Microtime
* @property {function} now - Returns the current Unix timestamp in microseconds.
* @property {function} nowDouble - Returns the current Unix timestamp in seconds with microseconds as a decimal.
* @property {function} nowStruct - Returns the current Unix timestamp as a struct with seconds and microseconds properties.
*/
var microtime = require('./index.js')
console.log('microtime.now() =', microtime.now())
console.log('microtime.nowDouble() =', microtime.nowDouble())
console.log('microtime.nowStruct() =', microtime.nowStruct())
console.log("\n")
var start = microtime.now()
var minDiff = Infinity
var minCycle = 10000
var maxCycle = 100000
var cycle = maxCycle
for (var i = 0; i < cycle; ++i){
var a = microtime.now()
var b = microtime.now()
/**
* Calculates the difference between two values.
*
* @param {number} a - The first value.
* @param {number} b - The second value.
* @param {number} start - The starting value.
* @returns {number} The difference between the values.
*/
var diff = (b - a) || (b - start)
if (diff > 0 && diff < minDiff){
minDiff = diff
cycle = minCycle
}
}
if (minDiff === Infinity){
console.log('Error: Unable to measure minimum difference.')
}else{
console.log('Minimum difference measured:', minDiff, 'microseconds')
}