Last active
January 20, 2017 21:05
-
-
Save gabssnake/134adae0868227973a2955fb452e8329 to your computer and use it in GitHub Desktop.
Bloomrun perf tests
This file contains hidden or 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
'use strict' | |
var async = require('async') | |
var dependency = require('bloomrun') | |
var tests = require('./tests') | |
function measure (test) { | |
return function (i, done) { | |
var time = process.hrtime() | |
test(err => done(err, process.hrtime(time))) | |
} | |
} | |
function benchmark (tests, amount, dependency) { | |
return tests.map((test) => { | |
var bench = measure(test(dependency)) | |
return done => async.timesSeries(amount, bench, done) | |
}) | |
} | |
function microsecs (hrtime) { | |
return hrtime[0] * 1000000 + hrtime[1] / 1000 | |
} | |
function deepMap (fn, values) { | |
return values.map((series) => series.map(fn)) | |
} | |
var amount = 5000 | |
var series = benchmark(tests, amount, dependency) | |
async.parallel(series, results) | |
function results (err, res) { | |
if (err) throw err | |
console.log(deepMap(microsecs, res)) | |
} |
This file contains hidden or 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
'use strict' | |
function listThree (bloomrun) { | |
var instance = bloomrun({ indexing: 'depth' }) | |
var pattern = { something: 'else', answer: 42 } | |
var entries = [ | |
{ hello: 'world', answer: 42 }, | |
{ hello: 'matteo', answer: 42 }, | |
{ something: 'else', answer: 42 } | |
] | |
entries.forEach((entry) => instance.add(entry)) | |
return function listThree (done) { | |
instance.list(pattern) | |
process.nextTick(done) | |
} | |
} | |
function list400 (bloomrun) { | |
var instance = bloomrun({ indexing: 'depth' }) | |
var pattern = { bigCounter: '99', small3: 99, something: 'else' } | |
var entries = _manyEntries() | |
entries.forEach((entry) => instance.add(entry)) | |
return function list400 (done) { | |
instance.list(pattern) | |
process.nextTick(done) | |
}; | |
} | |
function _manyEntries () { | |
var results = [] | |
var obj | |
for (var i = 0; i < 100; i++) { | |
for (var k = 0; k < 4; k++) { | |
obj = { bigCounter: '' + i } | |
obj['small' + k] = i | |
results.push(obj) | |
} | |
} | |
return results | |
} | |
module.exports = [ | |
listThree, | |
list400 | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment