-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbenchmark.js
More file actions
56 lines (51 loc) · 1.11 KB
/
benchmark.js
File metadata and controls
56 lines (51 loc) · 1.11 KB
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
import {inspect} from 'node:util';
import {runInNewContext} from 'node:vm';
import isPlainObject from 'is-plain-obj';
const runBenchmarks = () => {
for (const value of values) {
const name = value instanceof Error ? String(Error) : inspect(value);
const paddedName = name.padEnd(50);
console.time(paddedName);
runLoop(value);
console.timeEnd(paddedName);
}
};
const runLoop = value => {
for (let index = 0; index < 1e8; index += 1) {
isPlainObject(value);
}
};
const values = [
undefined,
0,
0n,
'',
true,
Symbol(''),
() => {},
// eslint-disable-next-line func-names
(function namedFunction() {}),
null,
{},
Math,
new Set([]),
new ArrayBuffer(0),
Promise.resolve(),
Object.create(null),
new Intl.Locale('en'),
new Object({prop: true}),
new class Class {}(),
[],
/regexp/,
new Error('test'),
new Date(),
(function () {
// eslint-disable-next-line prefer-rest-params
return arguments;
})(),
new Proxy({}, {}),
];
// Warm up V8 optimization.
// Must go through every branch of the code, which requires using an object from a different realm.
runLoop(runInNewContext('({})'));
runBenchmarks();