-
-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathindex.js
63 lines (55 loc) · 1.3 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
const { Suite } = require('benchmark');
const classnames = require('classnames');
const classcat = require('classcat');
const clsx = require('../dist/clsx');
const old = require('clsx');
const lite = require('../dist/lite');
function bench(name, ...args) {
console.log(`\n# ${name}`);
new Suite()
.add('classcat ≠ ', () => classcat.apply(classcat, [args]))
.add('classnames ', () => classnames.apply(classnames, args))
.add('clsx (prev) ', () => old.apply(old, args))
.add('clsx ', () => clsx.apply(clsx, args))
.add('clsx (lite) ', () => lite.apply(lite, args))
.on('cycle', e => console.log(' ' + e.target))
.run();
}
bench(
'Strings',
'foo', '', 'bar', 'baz', 'bax', 'bux'
);
bench(
'Objects',
{ foo:true, bar:true, bax:true, bux:false },
{ baz:true, bax:false, bux:true }
);
bench(
'Arrays',
['foo', 'bar'],
['baz', 'bax', 'bux']
);
bench(
'Nested Arrays',
['foo', ['bar']],
['baz', ['bax', ['bux']]]
);
bench(
'Nested Arrays w/ Objects',
['foo', { bar:true, bax:true, bux:false }],
['bax', { bax:false, bux:true }]
);
bench(
'Mixed',
'foo', 'bar',
{ bax:true, bux:false },
['baz', { bax:false, bux:true }]
);
bench(
'Mixed (Bad Data)',
'foo', 'bar',
undefined, null, NaN,
() => {},
{ bax:true, bux:false, 123:true },
['baz', { bax:false, bux:true, abc:null }, {}]
);