forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tracing-emit.js
82 lines (75 loc) · 2.1 KB
/
tracing-emit.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
'use strict';
const assert = require('assert');
const tracing = require('tracing');
const common = require('../common.js');
let scenarios = {
disabled(n) {
traceEmitInstantBench(n, 'test1');
},
singleCategoryDisabled(n) {
tracing.enableRecording('test2');
traceEmitInstantBench(n, 'test1');
},
multiCategoryDisabled(n) {
tracing.enableRecording('test3');
traceEmitInstantBench(n, ['test1', 'test2']);
},
singleCategoryEnabled(n) {
tracing.enableRecording('test1');
traceEmitInstantBench(n, 'test1');
},
firstCategoryEnabled(n) {
tracing.enableRecording('test1');
traceEmitInstantBench(n, ['test1', 'test2']);
},
secondCategoryEnabled(n) {
tracing.enableRecording('test2');
traceEmitInstantBench(n, ['test1', 'test2']);
},
singleCategoryEnabledCount(n) {
tracing.enableRecording('test1');
console.options.logTracingEvents = false;
traceConsoleCountBench(n, 'test1');
},
secondCategoryEnabledCount(n) {
tracing.enableRecording('test2');
console.options.logTracingEvents = false;
traceConsoleCountBench(n, ['test1', 'test2']);
},
};
const bench = common.createBenchmark(main, {
scenario: Object.keys(scenarios),
});
function main(conf) {
let n = 1000000;
let scenarioName = conf.scenario;
let scenarioFn = scenarios[scenarioName] || function () {};
bench.start();
scenarioFn(n);
bench.end(n);
}
function traceEmitInstantBench(n, category) {
for (let i = 0; i < n; i++) {
tracing.emit(category, 'benchmark');
}
}
function traceEmitCountBench(n, category) {
for (let i = 0; i < n; i++) {
tracing.emit({
eventType: 'count',
name: 'benchmark',
category,
value: i,
});
}
}
function traceConsoleInstantBench(n, category) {
for (let i = 0; i < n; i++) {
console.timeStamp('benchmark', category);
}
}
function traceConsoleCountBench(n, category) {
for (let i = 0; i < n; i++) {
console.count('benchmark', category);
}
}