Skip to content

Commit

Permalink
benchmark: Allow which tests to run to be specified with a command li…
Browse files Browse the repository at this point in the history
…ne argument
  • Loading branch information
nwoltman committed Apr 19, 2016
1 parent be0f4f8 commit dda6739
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 77 deletions.
5 changes: 5 additions & 0 deletions benchmark/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"env": {
"es6": true
}
}
7 changes: 7 additions & 0 deletions benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
183 changes: 106 additions & 77 deletions benchmark/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit dda6739

Please sign in to comment.