-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
84 lines (78 loc) · 2.2 KB
/
index.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
83
84
/* eslint-disable no-console */
/*
$ node index.js
$ npx playwright-test index.js --runner benchmark
*/
import Benchmark from 'benchmark'
import * as cjs from './cjs.cjs'
import * as esm from './esm.js'
import { CJSClass as NamedCJSClass } from './cjs.cjs'
import { ESMClass as NamedESMClass } from './esm.js'
import DefaultCJSClass from './cjs-default.cjs'
import DefaultESMClass from './esm-default.js'
const ConstNamespaceCJSClass = cjs.CJSClass
const ConstNamespaceESMClass = esm.ESMClass
const ConstDefaultCJSClass = DefaultCJSClass
const ConstDefaultESMClass = DefaultESMClass
const ConstNamedCJSClass = NamedCJSClass
const ConstNamedESMClass = NamedCJSClass
new Benchmark.Suite()
.add('esm named import', () => {
const obj = new NamedESMClass()
obj.method()
})
.add('cjs named import', () => {
const obj = new NamedCJSClass()
obj.method()
})
.add('esm default import', () => {
const obj = new DefaultESMClass()
obj.method()
})
.add('cjs default import', () => {
const obj = new DefaultCJSClass()
obj.method()
})
.add('esm namespace import', () => {
const obj = new esm.ESMClass()
obj.method()
})
.add('cjs namespace import', () => {
const obj = new cjs.CJSClass()
obj.method()
})
.add('esm const binding of namespace import', () => {
const obj = new ConstNamespaceESMClass()
obj.method()
})
.add('cjs const binding of namespace import', () => {
const obj = new ConstNamespaceCJSClass()
obj.method()
})
.add('esm const binding of named import', () => {
const obj = new ConstNamedESMClass()
obj.method()
})
.add('cjs const binding of named import', () => {
const obj = new ConstNamedCJSClass()
obj.method()
})
.add('esm const binding of default import', () => {
const obj = new ConstDefaultESMClass()
obj.method()
})
.add('cjs const binding of default import', () => {
const obj = new ConstDefaultCJSClass()
obj.method()
})
.on('error', (err) => {
console.error(err)
})
.on('cycle', (event) => {
console.info(String(event.target))
})
.on('complete', function () {
console.info(`Fastest is ${this.filter('fastest').map('name')}`)
})
// run async
.run({ async: true })