From ffd348ede4e2071401f832ead9b8f1d1cbaf35e9 Mon Sep 17 00:00:00 2001 From: Nathan Woltman Date: Sun, 17 Apr 2016 17:03:20 -0400 Subject: [PATCH] Add benchmark test suite [ci skip] --- benchmark/README.md | 13 ++++++++ benchmark/package.json | 8 +++++ benchmark/run.js | 72 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 benchmark/README.md create mode 100644 benchmark/package.json create mode 100644 benchmark/run.js diff --git a/benchmark/README.md b/benchmark/README.md new file mode 100644 index 0000000..c80ce16 --- /dev/null +++ b/benchmark/README.md @@ -0,0 +1,13 @@ +# String Natural Compare Benchmark Tests + +First update dependencies before running tests: + +```sh +npm install # or npm update if already installed +``` + +Run tests: + +```sh +node run +``` diff --git a/benchmark/package.json b/benchmark/package.json new file mode 100644 index 0000000..c1a9666 --- /dev/null +++ b/benchmark/package.json @@ -0,0 +1,8 @@ +{ + "description": "Dependencies for string-natural-compare bechmarking", + "license": "UNLICENSED", + "dependencies": { + "benchmark": "^2.1.0", + "string-natural-compare": "nwoltman/string-natural-compare" + } +} diff --git a/benchmark/run.js b/benchmark/run.js new file mode 100644 index 0000000..dc1eff5 --- /dev/null +++ b/benchmark/run.js @@ -0,0 +1,72 @@ +/* eslint-disable no-console */ + +'use strict'; + +var Benchmark = require('benchmark'); + +var naturalCompareMaster = require('string-natural-compare'); +var naturalCompareCurrent = require('../'); + + +new Benchmark.Suite() + + .add('no numbers master', function() { + naturalCompareMaster('file.txt', 'otherFile.txt'); + naturalCompareMaster('otherFile.txt', 'file.txt'); + }) + .add('no numbers current', function() { + naturalCompareCurrent('file.txt', 'otherFile.txt'); + naturalCompareCurrent('otherFile.txt', 'file.txt'); + }) + + .add('common numbers master', function() { + naturalCompareMaster('a2.txt', 'a10.txt'); + naturalCompareMaster('a10.txt', 'a2.txt'); + }) + .add('common numbers current', function() { + naturalCompareCurrent('a2.txt', 'a10.txt'); + naturalCompareCurrent('a10.txt', 'a2.txt'); + }) + + .add('big numbers master', function() { + naturalCompareMaster('1165874568735487968325787328996865', '265812277985321589735871687040841'); + naturalCompareMaster('265812277985321589735871687040841', '1165874568735487968325787328996865'); + }) + .add('big numbers current', function() { + naturalCompareCurrent('1165874568735487968325787328996865', '265812277985321589735871687040841'); + naturalCompareCurrent('265812277985321589735871687040841', '1165874568735487968325787328996865'); + }) + + .on('cycle', function(event) { + console.log(String(event.target)); + }) + .run(); + + +naturalCompareMaster.alphabet = 'ABDEFGHIJKLMNOPRSŠZŽTUVÕÄÖÜXYabdefghijklmnoprsšzžtuvõäöüxy'; +naturalCompareCurrent.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 current', function() { + naturalCompareCurrent('š.txt', 'z.txt'); + naturalCompareCurrent('z.txt', 'š.txt'); + }) + + .add('custom alphabet missing characters master', function() { + naturalCompareMaster('é.txt', 'à.txt'); + naturalCompareMaster('à.txt', 'é.txt'); + }) + .add('custom alphabet missing characters current', function() { + naturalCompareCurrent('é.txt', 'à.txt'); + naturalCompareCurrent('à.txt', 'é.txt'); + }) + + .on('cycle', function(event) { + console.log(String(event.target)); + }) + .run();