-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathperfTest.js
45 lines (38 loc) · 1.19 KB
/
perfTest.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
'use strict';
var varanus = require('./index.js')({
flush: function() {},
maxRecords: 4000,
level: 'info'
});
var monitor = varanus.newMonitor(__filename);
function fn() {}
var fnInfo = monitor.info(fn);
var fnDebug = monitor.debug(fn);
var fnTrace = monitor.trace(fn);
var fnLogTimeInfo = function() {
var time = Date.now();
monitor.logTime('fooService', 'info', 'fooFn', time, time + 50);
};
var fnLogTimeTrace = function() {
return monitor.logTime('fooService', 'debug', 'fooFn', 0, 42);
};
var rawTime = time(fn);
console.log('Monitor Info Overhead/Call: ', time(fnInfo) - rawTime, 'ns');
console.log('Monitor Debug Overhead/Call: ', time(fnDebug) - rawTime, 'ns');
console.log('Monitor trace Overhead/Call: ', time(fnTrace) - rawTime, 'ns');
console.log('LogTime Info Time/Call: ', time(fnLogTimeInfo), 'ns');
console.log('LogTime Debug Time/Call: ', time(fnLogTimeTrace), 'ns');
process.exit(0);
function time(f) {
var iterations = 1000000;
var start = process.hrtime();
for (var i = 0; i < iterations; i += 1) {
f();
}
var res = Math.ceil(toNanos(process.hrtime(start))/iterations);
varanus.flush();
return res;
}
function toNanos(time) {
return time[0] * 1e9 + time[1];
}