Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #164 from ralphtheninja/fix-bench
Browse files Browse the repository at this point in the history
unbreak benchmarks
  • Loading branch information
juliangruber committed Apr 27, 2015
2 parents 5fa781b + ca91015 commit 91341fd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 42 deletions.
62 changes: 30 additions & 32 deletions bench/db-bench.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,44 @@
#!/usr/bin/env node

const leveldown = require('../')
, fs = require('fs')
, du = require('du')
, rimraf = require('rimraf')
const leveldown = require('../')
, fs = require('fs')
, du = require('du')
, rimraf = require('rimraf')

, argv = require('optimist').argv
, argv = require('optimist').argv

, options = {
, options = {
benchmark : argv.benchmark
, useExisting : argv.use_existing
, db : argv.db
, db : argv.db || __dirname + '/db'
, num : argv.num || 1000000
, concurrency : argv.concurrency || 4
, cacheSize : argv.cacheSize || 8
, writeBufferSize : argv.writeBufferSize || 4
, valueSize : argv.valueSize || 100
, timingOutput : argv.timingOutput
, timingOutput : argv.timingOutput || __dirname + '/timingOutput'
, throughputOutput : argv.throughputOutput
}

, randomData = require('./random-data')()
, keyTmpl = '0000000000000000'
, randomString = require('slump').string
, keyTmpl = '0000000000000000'

if (!options.useExisting) {
leveldown.destroy(options.db, function () {})
}

var db = leveldown(options.db)
, timesStream = options.timingOutput
&& fs.createWriteStream(options.timingOutput, 'utf8')
// , throughputStream = options.throughputOutput
// && fs.createWriteStream(options.throughputOutput, 'utf8')
, timesStream = fs.createWriteStream(options.timingOutput, 'utf8')

// make a 16 char padded key
function makeKey () {
function make16CharPaddedKey () {
var r = Math.floor(Math.random() * options.num)
, k = keyTmpl + r
return k.substr(k.length - 16)
}

timesStream.write('Elapsed (ms), Entries, Bytes, Last 1000 Avg Time, MB/s\n')

setTimeout(function () {
db.open({
errorIfExists : false
, createIfMissing : true
, cacheSize : options.cacheSize << 20
, writeBufferSize : options.writeBufferSize << 20
}, function (err) {

if (err)
throw err

function start () {
var inProgress = 0
, totalWrites = 0
, totalBytes = 0
Expand Down Expand Up @@ -103,24 +89,36 @@ setTimeout(function () {
+ ',' + (Math.floor(((totalBytes / 1048576) / (elapsed / 1000)) * 100) / 100)
+ '\n')
timesAccum = 0
//timesStream.write(writeBuf)
//writeBuf = ''
}

var time = process.hrtime()

db.put(makeKey(), randomData.generate(options.valueSize), function (err) {
db.put(make16CharPaddedKey(), randomString({ length: options.valueSize }), function (err) {
if (err)
throw err

totalBytes += keyTmpl.length + options.valueSize
timesAccum += process.hrtime(time)[1]
//writeBuf += (Date.now() - startTime) + ',' + process.hrtime(time)[1] + '\n'
inProgress--
process.nextTick(write)
})
}

for (var i = 0; i < options.concurrency; i++)
write()
})}, 500)
}

setTimeout(function () {
db.open({
errorIfExists : false
, createIfMissing : true
, cacheSize : options.cacheSize << 20
, writeBufferSize : options.writeBufferSize << 20
}, function (err) {
if (err)
throw err

start()

})
}, 500)
6 changes: 1 addition & 5 deletions bench/write-random.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const leveldown = require('../../lmdb/')
const leveldown = require('../')
, crypto = require('crypto')
, fs = require('fs')
, du = require('du')
Expand Down Expand Up @@ -31,15 +31,12 @@ db.open(function (err) {
var inProgress = 0
, totalWrites = 0
, startTime = Date.now()
//, timesTotal = 0
, writeBuf = ''

function write() {
if (totalWrites % 100000 == 0) console.log(inProgress, totalWrites)

if (totalWrites % 1000 == 0) {
//timesStream.write((Date.now() - startTime) + ',' + Math.floor(timesTotal / 1000) + '\n')
//timesTotal = 0
timesStream.write(writeBuf)
writeBuf = ''
}
Expand All @@ -56,7 +53,6 @@ db.open(function (err) {
db.put(uuid.v4(), data, function (err) {
if (err)
throw err
//timesTotal += process.hrtime(time)[1]
writeBuf += (Date.now() - startTime) + ',' + process.hrtime(time)[1] + '\n'
inProgress--
process.nextTick(write)
Expand Down
6 changes: 1 addition & 5 deletions bench/write-sorted.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@ db.open({ errorIfExists: true, createIfMissing: true }, function (err) {
var inProgress = 0
, totalWrites = 0
, startTime = Date.now()
//, timesTotal = 0
, writeBuf = ''

function write() {
if (totalWrites % 100000 == 0) console.log(inProgress, totalWrites)

if (totalWrites % 1000 == 0) {
//timesStream.write((Date.now() - startTime) + ',' + Math.floor(timesTotal / 1000) + '\n')
//timesTotal = 0
timesStream.write(writeBuf)
writeBuf = ''
}
Expand All @@ -56,7 +53,6 @@ db.open({ errorIfExists: true, createIfMissing: true }, function (err) {
db.put(timestamp(), data, function (err) {
if (err)
throw err
//timesTotal += process.hrtime(time)[1]
writeBuf += (Date.now() - startTime) + ',' + process.hrtime(time)[1] + '\n'
inProgress--
process.nextTick(write)
Expand All @@ -66,4 +62,4 @@ db.open({ errorIfExists: true, createIfMissing: true }, function (err) {
}

write()
})
})
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@
"mkfiletree": "~0.0.1",
"monotonic-timestamp": "~0.0.8",
"node-gyp": "~1.0.1",
"node-uuid": "~1.4.3",
"optimist": "~0.6.1",
"readfiletree": "~0.0.1",
"rimraf": "~2.2.8",
"slump": "~2.0.0",
"tap": "~0.4.12"
},
"scripts": {
Expand Down

0 comments on commit 91341fd

Please sign in to comment.