Skip to content

Instantly share code, notes, and snippets.

@retorquere
Created November 8, 2019 16:22
Show Gist options
  • Save retorquere/79fb0ad7062a85a1d83e4b004d40985e to your computer and use it in GitHub Desktop.
Save retorquere/79fb0ad7062a85a1d83e4b004d40985e to your computer and use it in GitHub Desktop.
const Benchmark = require('benchmark');
const fs = require('fs')
const path = require('path')
let parsers = [
'current',
// 'nearley',
'idea',
'idea-reworked',
'astrocite',
'fiduswriter',
'zotero',
'bbt'
]
parsers = parsers.map(function(name) {
const parser = require(`../lib/${name}`)
parser.parse_async = async function(text) { await this.parse(text) }
if (!parser.init) parser.init = async function() {}
return { name, parser }
})
const dirPath = path.join(__dirname, 'files')
function run(method, filename) {
return new Promise(function(resolve, reject) {
const suite = new Benchmark.Suite()
suite.on("cycle", function(event) {
const bench = event.target;
if (bench.error) {
console.log(bench.toString());
} else {
console.log(`${bench.name} ${filename || ''}: ${1000 / bench.hz}ms \xb1 ${bench.stats.rme}% (${bench.stats.sample.length} run${bench.stats.sample.length === 1 ? '' : 's'} sampled)`)
}
});
suite.on("complete", function() {
console.log("Fastest is " + this.filter("fastest").map("name"));
resolve()
});
const text = filename ? fs.readFileSync(path.join(dirPath, filename), 'utf8') : null
for (const parser of parsers) {
(function(p) {
suite.add(`${p.name}.${method}`, {
defer: true,
fn: function(test) {
p.parser[method](text).then(() => test.resolve())
}
})
})(parser)
}
suite.run({ async: true })
})
}
async function main() {
await run('init')
for (let filename of fs.readdirSync(dirPath)) {
await run('parse_async', filename)
}
}
// const console = global.console
// global.console = {}
main()
.then(console.table)
.catch(console.error)
@retorquere
Copy link
Author

current.init : 0.00008125034127555368ms ± 0.7328979200540323% (79 runs sampled)
idea.init : 0.00008377297798049938ms ± 0.8293023897392079% (81 runs sampled)
idea-reworked.init : 0.00008206290057170758ms ± 1.015470233358381% (79 runs sampled)
astrocite.init : 0.00008029323962139948ms ± 0.6561219011589493% (83 runs sampled)
fiduswriter.init : 0.00008033520171268243ms ± 0.8103141207571031% (79 runs sampled)
zotero.init : 71.99192728358209ms ± 4.605564934513947% (67 runs sampled)
bbt.init : 0.00008535002438945916ms ± 0.9782591901304101% (77 runs sampled)
Fastest is astrocite.init,fiduswriter.init

current.parse_async long.bib: 1430.4951857500002ms ± 5.147678326831084% (8 runs sampled)
idea.parse_async long.bib: 1032.6004006666667ms ± 1.665639535135364% (9 runs sampled)
idea-reworked.parse_async long.bib: 637.3302681666667ms ± 4.289239160912746% (12 runs sampled)
astrocite.parse_async long.bib: 1407.077368875ms ± 3.946642062399618% (8 runs sampled)
fiduswriter.parse_async long.bib: 80379.24906840001ms ± 1.903699602846312% (5 runs sampled)
zotero.parse_async long.bib: 16072.225707799998ms ± 1.622624276170948% (5 runs sampled)
bbt.parse_async long.bib: 11101.383971199999ms ± 1.9085378691681334% (5 runs sampled)
Fastest is idea-reworked.parse_async

current.parse_async single.bib: 0.6989025964169356ms ± 0.7499580140991932% (79 runs sampled)
idea.parse_async single.bib: 0.3234387876763405ms ± 0.8645590422948286% (76 runs sampled)
idea-reworked.parse_async single.bib: 0.3240267421783411ms ± 1.1119646244145625% (79 runs sampled)
astrocite.parse_async single.bib: 0.49662317468252676ms ± 1.213547762374137% (82 runs sampled)
fiduswriter.parse_async single.bib: 8.12110048312236ms ± 0.6403295454546399% (79 runs sampled)
zotero.parse_async single.bib: 13.000957445270274ms ± 8.697967264236793% (74 runs sampled)
bbt.parse_async single.bib: 0.8244344925768883ms ± 0.8441201474523171% (80 runs sampled)
Fastest is idea.parse_async,idea-reworked.parse_async

@larsgw
Copy link

larsgw commented Jan 3, 2020

I forgot to ask explicitly last time, can I add this to the repository?

@retorquere
Copy link
Author

Oh yeah, sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment