forked from gajus/roarr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.ts
126 lines (105 loc) · 2.23 KB
/
benchmark.ts
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* eslint-disable no-console */
import { Roarr } from '../src/Roarr';
import { Suite } from 'benchmark';
import createGlobalThis from 'globalthis';
// eslint-disable-next-line node/no-process-env
if (process.env.ROARR_LOG !== 'true') {
throw new Error('Must run benchmark with ROARR_LOG=true.');
}
const globalThis = createGlobalThis();
(() => {
const suite = new Suite('roarr', {
onCycle: (event) => {
console.log(String(event.target));
},
onError: (event) => {
console.error(event.target.error);
},
});
suite.add(
'simple message',
() => {
Roarr.info('foo');
},
{
setup: () => {
globalThis.ROARR.write = () => {
return undefined;
};
},
},
);
suite.add(
'message with printf',
() => {
Roarr.info('foo %s %s %s', 'bar', 'baz', 'qux');
},
{
setup: () => {
globalThis.ROARR.write = () => {
return undefined;
};
},
},
);
suite.add(
'message with context',
() => {
Roarr.info(
{
foo: 'bar',
},
'foo',
);
},
{
setup: () => {
globalThis.ROARR.write = () => {
return undefined;
};
},
},
);
let largeContext;
suite.add(
'message with large context',
() => {
Roarr.info(largeContext, 'foo');
},
{
setup: () => {
globalThis.ROARR.write = () => {
return undefined;
};
largeContext = {};
let size = 10_000;
while (size--) {
largeContext[Math.random()] = Math.random();
}
},
},
);
let largeContextWithCircularReference;
suite.add(
'message with large context',
() => {
Roarr.info(largeContextWithCircularReference, 'foo');
},
{
setup: () => {
globalThis.ROARR.write = () => {
return undefined;
};
largeContextWithCircularReference = {};
let size = 10_000;
while (size--) {
largeContextWithCircularReference[Math.random()] = Math.random();
}
const foo: any = {};
foo.foo = foo;
largeContextWithCircularReference.foo = foo;
},
},
);
suite.run();
})();