-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
91 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Bench } from 'tinybench'; | ||
|
||
import local from 'classnames-local'; | ||
import dedupe from 'classnames-local/dedupe.js'; | ||
import localPackage from 'classnames-local/package.json' with { type: 'json' }; | ||
|
||
import npm from 'classnames-npm'; | ||
import npmDedupe from 'classnames-npm/dedupe.js'; | ||
import npmPackage from 'classnames-npm/package.json' with { type: 'json' }; | ||
|
||
if (localPackage.version !== npmPackage.version) { | ||
console.warn( | ||
`Your local version (${localPackage.version}) does not match the installed version (${npmPackage.version}).\n\n` + | ||
'Please run `npm update classnames-npm` in ./benchmarks to ensure you are benchmarking against the latest version published to NPM.\n' | ||
); | ||
} | ||
|
||
const benchmarks = [ | ||
{ | ||
description: 'strings', | ||
args: ['one', 'two', 'three'] | ||
}, | ||
{ | ||
description: 'object', | ||
args: [{one: true, two: true, three: false}] | ||
}, | ||
{ | ||
description: 'strings, object', | ||
args: ['one', 'two', {four: true, three: false}] | ||
}, | ||
{ | ||
description: 'mix', | ||
args: ['one', {two: true, three: false}, {four: 'four', five: true}, 6, {}] | ||
}, | ||
{ | ||
description: 'arrays', | ||
args: [['one', 'two'], ['three'], ['four', ['five']], [{six: true}, {seven: false}]] | ||
} | ||
]; | ||
|
||
export async function runBenchmarks () { | ||
for (const benchmark of benchmarks) { | ||
console.log(`Benchmarking '${benchmark.description}'.`); | ||
const bench = await runBenchmark(benchmark); | ||
console.table(bench.table()); | ||
} | ||
|
||
console.log('Finished!'); | ||
} | ||
|
||
async function runBenchmark (benchmark) { | ||
const bench = new Bench(); | ||
|
||
bench.add(`local#${benchmark.description}`, () => { | ||
local(...benchmark.args); | ||
}); | ||
|
||
bench.add(`npm#${benchmark.description}`, () => { | ||
npm(...benchmark.args); | ||
}); | ||
|
||
bench.add(`local/dedupe#${benchmark.description}`, () => { | ||
dedupe(...benchmark.args); | ||
}); | ||
|
||
bench.add(`npm/dedupe#${benchmark.description}`, () => { | ||
npmDedupe(...benchmark.args); | ||
}); | ||
|
||
await bench.run(); | ||
return bench; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,3 @@ | ||
import local from 'classnames-local'; | ||
import dedupe from 'classnames-local/dedupe.js'; | ||
import localPackage from 'classnames-local/package.json' with { type: 'json' }; | ||
import { runBenchmarks } from './benchmarks.js'; | ||
|
||
import npm from 'classnames-npm'; | ||
import npmDedupe from 'classnames-npm/dedupe.js'; | ||
import npmPackage from 'classnames-npm/package.json' with { type: 'json' }; | ||
|
||
import fixtures from './fixtures.js'; | ||
import runChecks from './runChecks.js'; | ||
import runSuite from './runSuite.js'; | ||
|
||
if (localPackage.version !== npmPackage.version) { | ||
log( | ||
`Your local version (${localPackage.version} does not match the installed version (${npmPackage.version})\n\n` + | ||
'Please run `npm update classnames-npm` in ./benchmarks to ensure you are benchmarking\n' + | ||
'the latest version of this package.\n' | ||
); | ||
process.exit(0); | ||
} | ||
|
||
fixtures.forEach((f) => { | ||
runChecks(local, npm, dedupe, npmDedupe, f); | ||
runSuite(local, npm, dedupe, npmDedupe, f, log); | ||
}); | ||
|
||
function log (message) { | ||
console.log(message); | ||
} | ||
await runBenchmarks(); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,9 @@ | ||
import local from 'classnames-local'; | ||
import dedupe from 'classnames-local/dedupe.js'; | ||
import localPackage from 'classnames-local/package.json' with { type: 'json' }; | ||
|
||
import npm from 'classnames-npm'; | ||
import npmDedupe from 'classnames-npm/dedupe.js'; | ||
import npmPackage from 'classnames-npm/package.json' with { type: 'json' }; | ||
|
||
import fixtures from './fixtures.js'; | ||
import runSuite from './runSuite.js'; | ||
import { runBenchmarks } from './benchmarks.js'; | ||
|
||
const startButton = document.getElementById('start'); | ||
const results = document.getElementById('results'); | ||
|
||
startButton.addEventListener('click', runBenchmarks); | ||
|
||
if (localPackage.version === npmPackage.version) { | ||
startButton.addEventListener('click', async () => { | ||
startButton.disabled = true; | ||
await runBenchmarks(); | ||
startButton.disabled = false; | ||
} else { | ||
startButton.style.display = 'none'; | ||
|
||
log( | ||
`Your local version (${localPackage.version} does not match the installed version (${npmPackage.version})\n\n` + | ||
'Please run `npm update classnames-npm` in ./benchmarks to ensure you are benchmarking\n' + | ||
'the latest version of this package.\n' | ||
); | ||
} | ||
|
||
async function runBenchmarks () { | ||
startButton.style.display = 'none'; | ||
|
||
log('Running benchmark…'); | ||
log(navigator.userAgent); | ||
|
||
await nextTick(); | ||
|
||
for (const fixture of fixtures) { | ||
runSuite(local, npm, dedupe, npmDedupe, fixture, log); | ||
await nextTick(); | ||
} | ||
|
||
log('Finished!'); | ||
} | ||
|
||
function log (message) { | ||
console.log(message); | ||
results.textContent += `${message}\n`; | ||
} | ||
|
||
function nextTick () { | ||
return new Promise((resolve) => setTimeout(resolve)); | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.