Skip to content

Commit

Permalink
chore: add node benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed Apr 6, 2019
1 parent 91f5e68 commit b7c3973
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
61 changes: 61 additions & 0 deletions bench/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const { Suite } = require('benchmark');
const classnames = require('classnames');
const classcat = require('classcat');
const clsx = require('../dist/clsx');
const old = require('clsx');

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))
.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 }, {}]
);
9 changes: 9 additions & 0 deletions bench/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"private": true,
"devDependencies": {
"benchmark": "^2.1.4",
"classcat": "^3.2.5",
"classnames": "^2.2.6",
"clsx": "1.0.3"
}
}

0 comments on commit b7c3973

Please sign in to comment.