diff --git a/bench/README.md b/bench/README.md index 5c6b6ea1..ca07d87b 100644 --- a/bench/README.md +++ b/bench/README.md @@ -31,5 +31,63 @@ bash bench/db-bench-plot.sh master.csv wip.csv ``` ## `write-random` + +Run the benchmark: + +``` +node bench/write-random.js +``` + +This writes results to `bench/write-random.csv` by default. To save results from multiple runs, add `--out `. For example, you could switch branches (assuming that both branches have the same benchmark code): + +``` +node bench/write-random.js --out master.csv + +git checkout wip +node-gyp rebuild +node bench/write-random.js --out wip.csv +``` + +Then plot both runs with `write-random-plot.sh ` (the basenames of the files are used for the legend): + +``` +./bench/write-random-plot.sh *.csv +``` + +If you are on Windows, you can use git bash: + +``` +bash bench/write-random-plot.sh master.csv wip.csv +``` + ## `write-sorted` + +Run the benchmark: + +``` +node bench/write-sorted.js +``` + +This writes results to `bench/write-sorted.csv` by default. To save results from multiple runs, add `--out `. For example, you could switch branches (assuming that both branches have the same benchmark code): + +``` +node bench/write-sorted.js --out master.csv + +git checkout wip +node-gyp rebuild +node bench/write-sorted.js --out wip.csv +``` + +Then plot both runs with `write-sorted-plot.sh ` (the basenames of the files are used for the legend): + +``` +./bench/write-sorted-plot.sh *.csv +``` + +If you are on Windows, you can use git bash: + +``` +bash bench/write-sorted-plot.sh master.csv wip.csv +``` + ## `memory` diff --git a/bench/db-bench.js b/bench/db-bench.js index cd1b5ccd..e969233e 100755 --- a/bench/db-bench.js +++ b/bench/db-bench.js @@ -4,11 +4,10 @@ const leveldown = require('../') const fs = require('fs') const du = require('du') const path = require('path') +const rimraf = require('rimraf') const argv = require('optimist').argv const options = { - benchmark: argv.benchmark, - useExisting: argv.use_existing, db: argv.db || path.join(__dirname, 'db'), num: argv.num || 1000000, concurrency: argv.concurrency || 4, @@ -21,9 +20,7 @@ const options = { const randomString = require('slump').string const keyTmpl = '0000000000000000' -if (!options.useExisting) { - leveldown.destroy(options.db, function () {}) -} +rimraf.sync(options.db) const db = leveldown(options.db) const timesStream = fs.createWriteStream(options.out, 'utf8') @@ -56,6 +53,7 @@ function start () { if (err) throw err console.log('Database size:', Math.floor(size / 1024 / 1024) + 'M') }) + console.log('Wrote times to ', options.out) } function write () { diff --git a/bench/write-random-plot.sh b/bench/write-random-plot.sh index f9294ae3..27a9d285 100755 --- a/bench/write-random-plot.sh +++ b/bench/write-random-plot.sh @@ -1,24 +1,38 @@ #!/bin/sh +num_writes=10M +num_files=$# +platform=$(node -p process.platform) +arch=$(node -p process.arch) +node=$(node -p process.version) +png_suffix=$(date '+%Y%m%d-%H.%M.%S') + gnuplot <= concurrency || totalWrites > entryCount) return + if (totalWrites++ === options.num) return report(Date.now() - startTime) + if (inProgress >= options.concurrency || totalWrites > options.num) return - var time = process.hrtime() + var start = process.hrtime() inProgress++ db.put(uuid.v4(), data, function (err) { if (err) throw err - writeBuf += (Date.now() - startTime) + ',' + process.hrtime(time)[1] + '\n' + var duration = process.hrtime(start) + var nano = (duration[0] * 1e9) + duration[1] + + writeBuf += (Date.now() - startTime) + ',' + nano + '\n' inProgress-- process.nextTick(write) }) diff --git a/bench/write-sorted-plot.sh b/bench/write-sorted-plot.sh index 24ee173a..4d15d874 100755 --- a/bench/write-sorted-plot.sh +++ b/bench/write-sorted-plot.sh @@ -1,22 +1,39 @@ #!/bin/sh +num_writes=10M +num_files=$# +platform=$(node -p process.platform) +arch=$(node -p process.arch) +node=$(node -p process.version) +png_suffix=$(date '+%Y%m%d-%H.%M.%S') + gnuplot <= concurrency || totalWrites > entryCount) return + if (totalWrites++ === options.num) return report(Date.now() - startTime) + if (inProgress >= options.concurrency || totalWrites > options.num) return - var time = process.hrtime() + var start = process.hrtime() inProgress++ db.put(timestamp(), data, function (err) { if (err) throw err - writeBuf += (Date.now() - startTime) + ',' + process.hrtime(time)[1] + '\n' + var duration = process.hrtime(start) + var nano = (duration[0] * 1e9) + duration[1] + + writeBuf += (Date.now() - startTime) + ',' + nano + '\n' inProgress-- process.nextTick(write) })