-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #31
- Loading branch information
Shreyas Minocha
committed
Jan 18, 2019
1 parent
f44edbc
commit 52f14e8
Showing
4 changed files
with
276 additions
and
23 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
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,136 @@ | ||
const { Suite } = require('benchmark'); | ||
const { table } = require('table'); | ||
const prettyMs = require('pretty-ms'); | ||
const { bold } = require('chalk'); | ||
const VerEx = require('../dist/verbalexpressions'); | ||
|
||
const benchmarks = {}; | ||
|
||
benchmarks.constructor = { | ||
VerEx: () => { VerEx(); }, | ||
RegExp: () => { RegExp(); }, | ||
}; | ||
|
||
benchmarks.startOfLine = { | ||
VerEx: () => { VerEx().startOfLine('a').test('alpha'); }, | ||
RegExp: () => { /^a/.test('alpha'); }, | ||
}; | ||
|
||
benchmarks.endOfLine = { | ||
VerEx: () => { VerEx().endOfLine('a').test('alpha'); }, | ||
RegExp: () => { /a$/.test('alpha'); }, | ||
}; | ||
|
||
benchmarks['then|find'] = { | ||
VerEx: () => { VerEx().find('alpha').test('alpha'); }, | ||
RegExp: () => { /alpha/.test('alpha'); }, | ||
}; | ||
|
||
benchmarks.maybe = { | ||
VerEx: () => { | ||
const expr = VerEx().maybe('a'); | ||
expr.test('a'); expr.test(''); | ||
}, | ||
RegExp: () => { | ||
const expr = /a?/; | ||
expr.test('a'); expr.test(''); | ||
}, | ||
}; | ||
|
||
benchmarks.anything = { | ||
VerEx: () => { VerEx().anything().test('alpha'); }, | ||
RegExp: () => { /.*/.test('alpha'); }, | ||
}; | ||
|
||
benchmarks.anythingBut = { | ||
VerEx: () => { | ||
const expr = VerEx().anythingBut('a'); | ||
expr.test('alpha'); expr.test('epsilon'); | ||
}, | ||
RegExp: () => { | ||
const expr = /.*/; | ||
expr.test('alpha'); expr.test('epsilon'); | ||
}, | ||
}; | ||
|
||
benchmarks.something = { | ||
VerEx: () => { | ||
const expr = VerEx().somethingBut('a'); | ||
expr.test('alpha'); expr.test(''); | ||
}, | ||
RegExp: () => { | ||
const expr = /.+/; | ||
expr.test('alpha'); expr.test(''); | ||
}, | ||
}; | ||
|
||
benchmarks.somethingBut = { | ||
VerEx: () => { | ||
const expr = VerEx().somethingBut('a'); | ||
expr.test('alpha'); expr.test('epsilon'); expr.test(''); | ||
}, | ||
RegExp: () => { | ||
const expr = /.+/; | ||
expr.test('alpha'); expr.test('epsilon'); expr.test(''); | ||
}, | ||
}; | ||
|
||
/* | ||
* TODO | ||
*/ | ||
|
||
// benchmarks['anyOf|any'] = { VerEx: () => {}, RegExp: () => {} }; | ||
// benchmarks.not = { VerEx: () => {}, RegExp: () => {} }; | ||
// benchmarks.range = { VerEx: () => {}, RegExp: () => {} }; | ||
// benchmarks['lineBreak|br'] = { VerEx: () => {}, RegExp: () => {} }; | ||
// benchmarks.tab = { VerEx: () => {}, RegExp: () => {} }; | ||
// benchmarks.word = { VerEx: () => {}, RegExp: () => {} }; | ||
// benchmarks.digit = { VerEx: () => {}, RegExp: () => {} }; | ||
// benchmarks.whitespace = { VerEx: () => {}, RegExp: () => {} }; | ||
// benchmarks.addModifier = { VerEx: () => {}, RegExp: () => {} }; | ||
// benchmarks.removeModifier = { VerEx: () => {}, RegExp: () => {} }; | ||
// benchmarks.withAnyCase = { VerEx: () => {}, RegExp: () => {} }; | ||
// benchmarks.stopAtFirst = { VerEx: () => {}, RegExp: () => {} }; | ||
// benchmarks.searchOneLine = { VerEx: () => {}, RegExp: () => {} }; | ||
// benchmarks.repeatPrevious = { VerEx: () => {}, RegExp: () => {} }; | ||
// benchmarks.oneOrMore = { VerEx: () => {}, RegExp: () => {} }; | ||
// benchmarks.multiple = { VerEx: () => {}, RegExp: () => {} }; | ||
// benchmarks.beginCapture = { VerEx: () => {}, RegExp: () => {} }; | ||
// benchmarks.endCapture = { VerEx: () => {}, RegExp: () => {} }; | ||
// benchmarks.replace = { VerEx: () => {}, RegExp: () => {} }; | ||
// benchmarks.toRegExp = { VerEx: () => {}, RegExp: () => {} }; | ||
|
||
const suite = new Suite(); | ||
|
||
for (const [name, bench] of Object.entries(benchmarks)) { | ||
const VerExRun = bench.VerEx; | ||
const RegExpRun = bench.RegExp; | ||
|
||
suite | ||
.add(`VerEx ${name}`, VerExRun) | ||
.add(`RegExp ${name}`, RegExpRun); | ||
} | ||
|
||
const tableData = []; | ||
|
||
tableData.push([ | ||
bold('Description'), bold('Time'), bold('Uncertainty'), | ||
]); | ||
|
||
suite.on('cycle', (event) => { | ||
const { name, stats } = event.target; | ||
|
||
tableData.push([ | ||
name, | ||
prettyMs(stats.mean * 1000, { formatSubMs: true }), | ||
`±${stats.rme.toFixed(2)}%`, | ||
]); | ||
}); | ||
|
||
suite.run(); | ||
|
||
const tableConfig = { | ||
drawHorizontalLine: index => index === 0 || index % 2 !== 0, | ||
}; | ||
|
||
console.log(table(tableData, tableConfig)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.