-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
39 lines (31 loc) · 994 Bytes
/
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
const Benchmark = require('benchmark');
const path = require('path');
const fs = require('fs');
const clsx = require('clsx');
const classnames = require('classnames');
function bench(name, { title, before, after }) {
console.log(`\n# ${name} - ${title}:`);
const suite = new Benchmark.Suite();
suite.add('before - classnames', () => before(classnames));
suite.add('before - clsx ', () => before(clsx));
// If the argument length is 0 then the function call has been optimized away
if (after.length === 0) {
suite.add('after - N/A ', after);
} else {
suite.add('after - classnames', () => after(classnames));
suite.add('after - clsx ', () => after(clsx));
}
suite.on('cycle', (e) => console.log(' ' + e.target));
suite.run();
}
const dir = path.join(__dirname, 'cases');
fs.readdir(dir, (err, files) => {
if (err) {
throw err;
}
files.forEach((f) => {
const testCase = require(path.join(dir, f));
bench(f, testCase);
});
console.log();
});