From dda673946f56d79d0341b3c26f8f5cbad71555de Mon Sep 17 00:00:00 2001 From: Nathan Woltman Date: Mon, 18 Apr 2016 20:18:52 -0400 Subject: [PATCH] benchmark: Allow which tests to run to be specified with a command line argument --- benchmark/.eslintrc.json | 5 ++ benchmark/README.md | 7 ++ benchmark/run.js | 183 +++++++++++++++++++++++---------------- 3 files changed, 118 insertions(+), 77 deletions(-) create mode 100644 benchmark/.eslintrc.json diff --git a/benchmark/.eslintrc.json b/benchmark/.eslintrc.json new file mode 100644 index 0000000..22abc7f --- /dev/null +++ b/benchmark/.eslintrc.json @@ -0,0 +1,5 @@ +{ + "env": { + "es6": true + } +} diff --git a/benchmark/README.md b/benchmark/README.md index c80ce16..26590c4 100644 --- a/benchmark/README.md +++ b/benchmark/README.md @@ -11,3 +11,10 @@ Run tests: ```sh node run ``` + +Run specific tests: + +```sh +node run 2 # runs test 2 +node run 1,2,3 # runs tests 1, 2, and 3 (make sure there are no spaces between the commas and numbers) +``` diff --git a/benchmark/run.js b/benchmark/run.js index 7c1436f..a9215c4 100644 --- a/benchmark/run.js +++ b/benchmark/run.js @@ -7,84 +7,113 @@ var Benchmark = require('benchmark'); var naturalCompareMaster = require('string-natural-compare'); var naturalCompareLocal = require('../'); - -new Benchmark.Suite() - - .add('no numbers master', function() { - naturalCompareMaster('fileA.txt', 'fileB.txt'); - naturalCompareMaster('fileB.txt', 'fileA.txt'); - }) - .add('no numbers local', function() { - naturalCompareLocal('fileA.txt', 'fileB.txt'); - naturalCompareLocal('fileB.txt', 'fileA.txt'); - }) - - .add('common numbers different lengths master', function() { - naturalCompareMaster('2.txt', '10.txt'); - naturalCompareMaster('10.txt', '2.txt'); - }) - .add('common numbers different lengths local', function() { - naturalCompareLocal('2.txt', '10.txt'); - naturalCompareLocal('10.txt', '2.txt'); - }) - - .add('common numbers same length master', function() { - naturalCompareMaster('01.txt', '05.txt'); - naturalCompareMaster('05.txt', '01.txt'); - }) - .add('common numbers same length local', function() { - naturalCompareLocal('01.txt', '05.txt'); - naturalCompareLocal('05.txt', '01.txt'); - }) - - .add('big numbers different lengths master', function() { - naturalCompareMaster('1165874568735487968325787328996865', '265812277985321589735871687040841'); - naturalCompareMaster('265812277985321589735871687040841', '1165874568735487968325787328996865'); - }) - .add('big numbers different lengths local', function() { - naturalCompareLocal('1165874568735487968325787328996865', '265812277985321589735871687040841'); - naturalCompareLocal('265812277985321589735871687040841', '1165874568735487968325787328996865'); - }) - - .add('big numbers same length master', function() { - naturalCompareMaster('1165874568735487968325787328996865', '1165874568735487989735871687040841'); - naturalCompareMaster('1165874568735487989735871687040841', '1165874568735487968325787328996865'); - }) - .add('big numbers same length local', function() { - naturalCompareLocal('1165874568735487968325787328996865', '1165874568735487989735871687040841'); - naturalCompareLocal('1165874568735487989735871687040841', '1165874568735487968325787328996865'); - }) - - .on('cycle', function(event) { - console.log(String(event.target)); - }) - .run(); - +var config = new Set( + process.argv.length > 2 ? process.argv[2].split(',') : '1234567' +); + +var suite = new Benchmark.Suite(); + +if (config.has('1')) { + suite + .add('1) no numbers master', function() { + naturalCompareMaster('fileA.txt', 'fileB.txt'); + naturalCompareMaster('fileB.txt', 'fileA.txt'); + }) + .add('1) no numbers local', function() { + naturalCompareLocal('fileA.txt', 'fileB.txt'); + naturalCompareLocal('fileB.txt', 'fileA.txt'); + }); +} + +if (config.has('2')) { + suite + .add('2) common numbers different lengths master', function() { + naturalCompareMaster('2.txt', '10.txt'); + naturalCompareMaster('10.txt', '2.txt'); + }) + .add('2) common numbers different lengths local', function() { + naturalCompareLocal('2.txt', '10.txt'); + naturalCompareLocal('10.txt', '2.txt'); + }); +} + +if (config.has('3')) { + suite + .add('3) common numbers same length master', function() { + naturalCompareMaster('01.txt', '05.txt'); + naturalCompareMaster('05.txt', '01.txt'); + }) + .add('3) common numbers same length local', function() { + naturalCompareLocal('01.txt', '05.txt'); + naturalCompareLocal('05.txt', '01.txt'); + }); +} + +if (config.has('4')) { + suite + .add('4) big numbers different lengths master', function() { + naturalCompareMaster('1165874568735487968325787328996865', '265812277985321589735871687040841'); + naturalCompareMaster('265812277985321589735871687040841', '1165874568735487968325787328996865'); + }) + .add('4) big numbers different lengths local', function() { + naturalCompareLocal('1165874568735487968325787328996865', '265812277985321589735871687040841'); + naturalCompareLocal('265812277985321589735871687040841', '1165874568735487968325787328996865'); + }); +} + +if (config.has('5')) { + suite + .add('5) big numbers same length master', function() { + naturalCompareMaster('1165874568735487968325787328996865', '1165874568735487989735871687040841'); + naturalCompareMaster('1165874568735487989735871687040841', '1165874568735487968325787328996865'); + }) + .add('5) big numbers same length local', function() { + naturalCompareLocal('1165874568735487968325787328996865', '1165874568735487989735871687040841'); + naturalCompareLocal('1165874568735487989735871687040841', '1165874568735487968325787328996865'); + }); +} + +if (suite.length) { + suite + .on('cycle', function(event) { + console.log(String(event.target)); + }) + .run(); +} naturalCompareMaster.alphabet = 'ABDEFGHIJKLMNOPRSŠZŽTUVÕÄÖÜXYabdefghijklmnoprsšzžtuvõäöüxy'; naturalCompareLocal.alphabet = 'ABDEFGHIJKLMNOPRSŠZŽTUVÕÄÖÜXYabdefghijklmnoprsšzžtuvõäöüxy'; -new Benchmark.Suite() - - .add('custom alphabet included characters master', function() { - naturalCompareMaster('š.txt', 'z.txt'); - naturalCompareMaster('z.txt', 'š.txt'); - }) - .add('custom alphabet included characters local', function() { - naturalCompareLocal('š.txt', 'z.txt'); - naturalCompareLocal('z.txt', 'š.txt'); - }) - - .add('custom alphabet missing characters master', function() { - naturalCompareMaster('é.txt', 'à.txt'); - naturalCompareMaster('à.txt', 'é.txt'); - }) - .add('custom alphabet missing characters local', function() { - naturalCompareLocal('é.txt', 'à.txt'); - naturalCompareLocal('à.txt', 'é.txt'); - }) - - .on('cycle', function(event) { - console.log(String(event.target)); - }) - .run(); +suite = new Benchmark.Suite(); + +if (config.has('6')) { + suite + .add('6) custom alphabet included characters master', function() { + naturalCompareMaster('š.txt', 'z.txt'); + naturalCompareMaster('z.txt', 'š.txt'); + }) + .add('6) custom alphabet included characters local', function() { + naturalCompareLocal('š.txt', 'z.txt'); + naturalCompareLocal('z.txt', 'š.txt'); + }); +} + +if (config.has('7')) { + suite + .add('7) custom alphabet missing characters master', function() { + naturalCompareMaster('é.txt', 'à.txt'); + naturalCompareMaster('à.txt', 'é.txt'); + }) + .add('7) custom alphabet missing characters local', function() { + naturalCompareLocal('é.txt', 'à.txt'); + naturalCompareLocal('à.txt', 'é.txt'); + }); +} + +if (suite.length) { + suite + .on('cycle', function(event) { + console.log(String(event.target)); + }) + .run(); +}