[Pkg-javascript-commits] [node-leveldown] 108/492: revamped benchmark suite
Andrew Kelley
andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:13:49 UTC 2014
This is an automated email from the git hooks/post-receive script.
andrewrk-guest pushed a commit to annotated tag rocksdb-0.10.1
in repository node-leveldown.
commit 150c92f443c387513a0a92dbdb8bb5ac71055a78
Author: Rod Vagg <rod at vagg.org>
Date: Sat Dec 15 17:03:11 2012 +1100
revamped benchmark suite
---
test/benchmarks/engines/index.js | 8 ++
test/benchmarks/engines/leveled.js | 16 +++
test/benchmarks/engines/levelup-release.js | 16 +++
test/benchmarks/engines/levelup.js | 16 +++
test/benchmarks/index.js | 114 ++++++++++++---------
test/benchmarks/package.json | 24 +++--
.../tests/batch_int_string_x100000_leveled.js | 1 +
.../tests/batch_int_string_x100000_levelup.js | 1 +
.../tests/batch_int_string_x1000_leveled.js | 21 ++++
.../tests/batch_int_string_x1000_levelup.js | 23 +++++
test/benchmarks/tests/index.js | 29 ++++++
.../tests/put_int_string_x100000_leveled.js | 1 +
.../tests/put_int_string_x100000_levelup.js | 1 +
.../tests/put_int_string_x1000_leveled.js | 1 +
.../tests/put_int_string_x1000_levelup.js | 20 ++++
15 files changed, 232 insertions(+), 60 deletions(-)
diff --git a/test/benchmarks/engines/index.js b/test/benchmarks/engines/index.js
new file mode 100644
index 0000000..a390f8d
--- /dev/null
+++ b/test/benchmarks/engines/index.js
@@ -0,0 +1,8 @@
+module.exports.LevelUP = require('./levelup')
+module.exports.LevelUP.color = 'green'
+
+module.exports['LevelUP (release)'] = require('./levelup-release')
+module.exports['LevelUP (release)'].color = 'yellow'
+
+module.exports.Leveled = require('./leveled')
+module.exports.Leveled.color = 'cyan'
\ No newline at end of file
diff --git a/test/benchmarks/engines/leveled.js b/test/benchmarks/engines/leveled.js
new file mode 100644
index 0000000..2c8e26b
--- /dev/null
+++ b/test/benchmarks/engines/leveled.js
@@ -0,0 +1,16 @@
+var leveled = require('leveled')
+
+ , createDb = function (location, callback) {
+ var db = leveled(location) // no callback, is it sync?
+ setTimeout(callback.bind(null, null, db), 50)
+ }
+
+ , closeDb = function (db, callback) {
+ // has no close()
+ callback()
+ }
+
+module.exports = {
+ createDb : createDb
+ , closeDb : closeDb
+}
\ No newline at end of file
diff --git a/test/benchmarks/engines/levelup-release.js b/test/benchmarks/engines/levelup-release.js
new file mode 100644
index 0000000..22a384a
--- /dev/null
+++ b/test/benchmarks/engines/levelup-release.js
@@ -0,0 +1,16 @@
+var levelup = require('levelup')
+
+ , createDb = function (location, callback) {
+ levelup(location, { createIfMissing: true, errorIfExists: true }, function (err, db) {
+ setTimeout(callback.bind(null, err, db), 50)
+ })
+ }
+
+ , closeDb = function (db, callback) {
+ db.close(callback)
+ }
+
+module.exports = {
+ createDb : createDb
+ , closeDb : closeDb
+}
\ No newline at end of file
diff --git a/test/benchmarks/engines/levelup.js b/test/benchmarks/engines/levelup.js
new file mode 100644
index 0000000..47080b8
--- /dev/null
+++ b/test/benchmarks/engines/levelup.js
@@ -0,0 +1,16 @@
+var levelup = require('../../../')
+
+ , createDb = function (location, callback) {
+ levelup(location, { createIfMissing: true, errorIfExists: true }, function (err, db) {
+ setTimeout(callback.bind(null, err, db), 50)
+ })
+ }
+
+ , closeDb = function (db, callback) {
+ db.close(callback)
+ }
+
+module.exports = {
+ createDb : createDb
+ , closeDb : closeDb
+}
\ No newline at end of file
diff --git a/test/benchmarks/index.js b/test/benchmarks/index.js
index 48826b9..f45a8fc 100644
--- a/test/benchmarks/index.js
+++ b/test/benchmarks/index.js
@@ -1,66 +1,82 @@
-var Benchmark = require('benchmark')
+const DB_ROOT = __dirname
+
+var path = require('path')
+ , Benchmark = require('benchmark')
, rimraf = require('rimraf')
, async = require('async')
- , colors = require('colors')
- , levelup = require('../../')
- , benchmarks = require('./benchmarks')
+ , engines = require('./engines/')
+ , tests = require('./tests/')
+
, dbidx = 0
- , K = function (db, cb) { cb() }
+ , printableEngineName = function (engineName) {
+ var len = Object.keys(engines).reduce(function (m, c) { return Math.max(c.length, m) }, 0)
+ while (engineName.length < len) engineName += ' '
+ return engineName
+ }
- , makedb = function (cb) {
- levelup('./bench_' + (dbidx++) + '.db', { createIfMissing: true, errorIfExists: true }, function (err, db) {
- if (err) throw err
- cb(db)
- })
+ , mklocation = function () {
+ return path.join(DB_ROOT, '_benchdb_' + dbidx++)
}
- , rmdb = function (db, cb) {
- rimraf(db._location, cb)
+ , mkdb = function (engine, location, callback) {
+ rimraf(location, engine.createDb.bind(null, location, callback))
}
- , run = function (name, setup, fn, cb) {
- function exec (db, cb) {
- new Benchmark(name, {
- 'defer': true,
- 'fn': function (deferred) {
- fn(db, deferred.resolve.bind(deferred))
- }
- })
- /*.on('cycle', function(event) {
- console.log(String(event.target))
- })*/
- .on('complete', function(event) {
- console.log(String(event.target).green.bold)
- cb()
- })
- .run({ async: true })
- }
+ , rmdb = function (engine, db, location, callback) {
+ engine.closeDb(db, rimraf.bind(null, location, callback))
+ }
- makedb(function (db) {
- setup(db, function () {
- exec(db, rmdb.bind(null, db, cb))
- })
+ , run = function (db, name, fn, color, cb) {
+ new Benchmark(name, {
+ 'defer': true,
+ 'fn': function (deferred) {
+ fn(db, deferred.resolve.bind(deferred))
+ }
+ })
+ .on('complete', function(event) {
+ console.log(String(event.target)[color].bold)
+ cb()
})
+ .run({ async: true })
}
- , focusKey = Object.keys(benchmarks).filter(function (k) { return (/\=>/).test(k) })
+ , runTest = function (testName, callback) {
+ async.forEachSeries(
+ Object.keys(engines)
+ , function (engineKey, callback) {
+ var engine = engines[engineKey]
+ var location = mklocation()
+ mkdb(engine, location, function (err, db) {
+ if (err) return callback(err)
+ if (!tests[testName][engineKey]) { console.log('Skipping for', testName, engineKey); return callback() }
+ run(
+ db
+ , printableEngineName(engineKey) + ' ' + testName
+ , tests[testName][engineKey]
+ , engine.color
+ , function (err) {
+ rmdb(engine, db, location, function (_err) {
+ callback(err || _err)
+ })
+ }
+ )
+ })
+ }
+ , function () {
+ console.log()
+ callback.apply(null, arguments)
+ }
+ )
+ }
+
+ , focusKey = Object.keys(tests).filter(function (k) { return (/\=>/).test(k) })
if (focusKey.length) {
- var focusBenchmark = benchmarks[focusKey[0]]
- benchmarks = {}
- benchmarks[focusKey[0]] = focusBenchmark
+ var focusTest = tests[focusKey[0]]
+ tests = {}
+ tests[focusKey[0]] = focusTest
}
-async.forEachSeries(
- Object.keys(benchmarks)
- , function (name, cb) {
- var setup = typeof benchmarks[name] == 'function' ? K : benchmarks[name].setup
- , fn = typeof benchmarks[name] == 'function' ? benchmarks[name] : benchmarks[name].fn
-
- run(name, setup, fn, cb)
- }
- , function () {
- //console.log('Done!')
- }
-)
\ No newline at end of file
+require('colors')
+async.forEachSeries(Object.keys(tests), runTest)
\ No newline at end of file
diff --git a/test/benchmarks/package.json b/test/benchmarks/package.json
index cae7b2e..f95f8af 100644
--- a/test/benchmarks/package.json
+++ b/test/benchmarks/package.json
@@ -1,13 +1,15 @@
{
- "name": "levelup-benchmarks",
- "version": "0.0.0",
- "description": "benchmarks for LevelUP",
- "main": "index.js",
- "private": true,
- "dependencies": {
- "benchmark": "~1.0.0",
- "colors": "~0.6.0-1",
- "rimraf": "~2.0.2",
- "async": "~0.1.22"
- }
+ "name": "levelup-benchmarks"
+ , "version": "0.0.0"
+ , "description": "benchmarks for LevelUP"
+ , "main": "index.js"
+ , "private": true
+ , "dependencies": {
+ "benchmark": "~1.0.0"
+ , "colors": "~0.6.0-1"
+ , "rimraf": "~2.0.2"
+ , "async": "~0.1.22"
+ , "levelup": "*"
+ , "leveled": "*"
+ }
}
diff --git a/test/benchmarks/tests/batch_int_string_x100000_leveled.js b/test/benchmarks/tests/batch_int_string_x100000_leveled.js
new file mode 100644
index 0000000..5b74c81
--- /dev/null
+++ b/test/benchmarks/tests/batch_int_string_x100000_leveled.js
@@ -0,0 +1 @@
+module.exports = require('./batch_int_string_x1000_leveled').fn.bind(null, 100000)
\ No newline at end of file
diff --git a/test/benchmarks/tests/batch_int_string_x100000_levelup.js b/test/benchmarks/tests/batch_int_string_x100000_levelup.js
new file mode 100644
index 0000000..cd8e481
--- /dev/null
+++ b/test/benchmarks/tests/batch_int_string_x100000_levelup.js
@@ -0,0 +1 @@
+module.exports = require('./batch_int_string_x1000_levelup').fn.bind(null, 100000)
\ No newline at end of file
diff --git a/test/benchmarks/tests/batch_int_string_x1000_leveled.js b/test/benchmarks/tests/batch_int_string_x1000_leveled.js
new file mode 100644
index 0000000..85e856b
--- /dev/null
+++ b/test/benchmarks/tests/batch_int_string_x1000_leveled.js
@@ -0,0 +1,21 @@
+var fn = function (puts, db, cb) {
+ var received = 0
+ , after = function (err) {
+ if (err) throw err
+ if (++received == puts) cb()
+ }
+ , batch = db.batch()
+
+ if (this.cycle == null) this.cycle = 0
+ else this.cycle++
+
+ for (var i = 0; i < puts; i++)
+ batch.put(
+ String(this.cycle * puts + i)
+ , "It'll be top end no worries stands out like a bushie. It'll be cream no dramas flat out like a rotten. As busy as a slabs bloody built like a stonkered. Get a dog up ya oldies no dramas lets get some bottle-o. Built like a schooner as busy as a big smoke. You little ripper ute my you little ripper dag."
+ )
+ batch.write(after)
+}
+
+module.exports = fn.bind(null, 1000)
+module.exports.fn = fn
\ No newline at end of file
diff --git a/test/benchmarks/tests/batch_int_string_x1000_levelup.js b/test/benchmarks/tests/batch_int_string_x1000_levelup.js
new file mode 100644
index 0000000..80f401f
--- /dev/null
+++ b/test/benchmarks/tests/batch_int_string_x1000_levelup.js
@@ -0,0 +1,23 @@
+var fn = function (puts, db, cb) {
+ var received = 0
+ , after = function (err) {
+ if (err) throw err
+ if (++received == puts) cb()
+ }
+
+ if (this.cycle == null) this.cycle = 0
+ else this.cycle++
+
+ for (var i = 0; i < puts; i++)
+ db.batch(
+ [{
+ type: 'put'
+ , key: this.cycle * puts + i
+ , value: "It'll be top end no worries stands out like a bushie. It'll be cream no dramas flat out like a rotten. As busy as a slabs bloody built like a stonkered. Get a dog up ya oldies no dramas lets get some bottle-o. Built like a schooner as busy as a big smoke. You little ripper ute my you little ripper dag."
+ }]
+ , after
+ )
+}
+
+module.exports = fn.bind(null, 1000)
+module.exports.fn = fn
\ No newline at end of file
diff --git a/test/benchmarks/tests/index.js b/test/benchmarks/tests/index.js
new file mode 100644
index 0000000..ffef66d
--- /dev/null
+++ b/test/benchmarks/tests/index.js
@@ -0,0 +1,29 @@
+/*
+ * Prefix a test name with '=>' to have only that test run
+ */
+
+module.exports = {
+ 'put(int, string) x 1000': {
+ 'LevelUP' : require('./put_int_string_x1000_levelup')
+ , 'LevelUP (release)' : require('./put_int_string_x1000_levelup')
+ , 'Leveled' : require('./put_int_string_x1000_leveled')
+ }
+
+ , 'put(int, string) x 100,000': {
+ 'LevelUP' : require('./put_int_string_x100000_levelup')
+ , 'LevelUP (release)' : require('./put_int_string_x100000_levelup')
+ , 'Leveled' : require('./put_int_string_x100000_leveled')
+ }
+
+ , 'batch(int, string) x 1000': {
+ 'LevelUP' : require('./batch_int_string_x1000_levelup')
+ , 'LevelUP (release)' : require('./batch_int_string_x1000_levelup')
+ , 'Leveled' : require('./batch_int_string_x1000_leveled')
+ }
+
+ , 'batch(int, string) x 100,000': {
+ 'LevelUP' : require('./batch_int_string_x100000_levelup')
+ , 'LevelUP (release)' : require('./batch_int_string_x100000_levelup')
+ , 'Leveled' : require('./batch_int_string_x100000_leveled')
+ }
+}
\ No newline at end of file
diff --git a/test/benchmarks/tests/put_int_string_x100000_leveled.js b/test/benchmarks/tests/put_int_string_x100000_leveled.js
new file mode 100644
index 0000000..31c20b3
--- /dev/null
+++ b/test/benchmarks/tests/put_int_string_x100000_leveled.js
@@ -0,0 +1 @@
+module.exports = require('./put_int_string_x100000_levelup')
\ No newline at end of file
diff --git a/test/benchmarks/tests/put_int_string_x100000_levelup.js b/test/benchmarks/tests/put_int_string_x100000_levelup.js
new file mode 100644
index 0000000..2fa883d
--- /dev/null
+++ b/test/benchmarks/tests/put_int_string_x100000_levelup.js
@@ -0,0 +1 @@
+module.exports = require('./put_int_string_x1000_levelup').fn.bind(null, 100000)
\ No newline at end of file
diff --git a/test/benchmarks/tests/put_int_string_x1000_leveled.js b/test/benchmarks/tests/put_int_string_x1000_leveled.js
new file mode 100644
index 0000000..dcbe622
--- /dev/null
+++ b/test/benchmarks/tests/put_int_string_x1000_leveled.js
@@ -0,0 +1 @@
+module.exports = require('./put_int_string_x1000_levelup')
\ No newline at end of file
diff --git a/test/benchmarks/tests/put_int_string_x1000_levelup.js b/test/benchmarks/tests/put_int_string_x1000_levelup.js
new file mode 100644
index 0000000..2525ccd
--- /dev/null
+++ b/test/benchmarks/tests/put_int_string_x1000_levelup.js
@@ -0,0 +1,20 @@
+var fn = function (puts, db, cb) {
+ var received = 0
+ , after = function (err) {
+ if (err) throw err
+ if (++received == puts) cb()
+ }
+
+ if (this.cycle == null) this.cycle = 0
+ else this.cycle++
+
+ for (var i = 0; i < puts; i++)
+ db.put(
+ String(this.cycle * puts + i)
+ , "It'll be top end no worries stands out like a bushie. It'll be cream no dramas flat out like a rotten. As busy as a slabs bloody built like a stonkered. Get a dog up ya oldies no dramas lets get some bottle-o. Built like a schooner as busy as a big smoke. You little ripper ute my you little ripper dag."
+ , after
+ )
+}
+
+module.exports = fn.bind(null, 1000)
+module.exports.fn = fn
\ No newline at end of file
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-leveldown.git
More information about the Pkg-javascript-commits
mailing list