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

Commit

Permalink
fix stream-bench.js
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangruber committed Apr 20, 2015
1 parent 681c6ce commit 7460209
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions test/benchmarks/stream-bench.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const levelup = require(process.argv[2] || '../../')
, crypto = require('crypto')
, srcdb = levelup('/tmp/source.db')
, dstdb = levelup('/tmp/destination.db')

, batch = 10000
, total = 200000
Expand All @@ -28,16 +27,33 @@ srcdb.on('ready', function () {

populate(0, function () {
var batchTime = Date.now() - start
console.log('Filled source! Took %sms, reading data now...', batchTime)

console.log('--------------------------------------------------------------')
console.log('Filled source! Took', batchTime + 'ms, streaming to destination...')

start = Date.now()
srcdb.createReadStream()
.on('end', function () {
var copyTime = Date.now() - start
console.log('Done! Took', copyTime + 'ms,', Math.round((copyTime / batchTime) * 100) + '% of batch time')
run(function () {
run(function () {
run()
})
.pipe(dstdb.createWriteStream())
})
})
})

function run (cb) {
stream({}, function () {
stream({ keys: true }, function () {
stream({ values: true }, function () {
stream({ keys: true, values: true }, cb)
})
})
})
}

function stream (opts, cb) {
var start = Date.now()
srcdb.createReadStream()
.on('end', function () {
var copyTime = Date.now() - start
console.log('Done! Took %sms with %j', copyTime, opts)
if (cb) cb()
})
.on('data', function(){})
}

0 comments on commit 7460209

Please sign in to comment.