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

Commit 7460209

Browse files
committed
fix stream-bench.js
1 parent 681c6ce commit 7460209

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

test/benchmarks/stream-bench.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const levelup = require(process.argv[2] || '../../')
22
, crypto = require('crypto')
33
, srcdb = levelup('/tmp/source.db')
4-
, dstdb = levelup('/tmp/destination.db')
54

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

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

32-
console.log('--------------------------------------------------------------')
33-
console.log('Filled source! Took', batchTime + 'ms, streaming to destination...')
34-
35-
start = Date.now()
36-
srcdb.createReadStream()
37-
.on('end', function () {
38-
var copyTime = Date.now() - start
39-
console.log('Done! Took', copyTime + 'ms,', Math.round((copyTime / batchTime) * 100) + '% of batch time')
32+
run(function () {
33+
run(function () {
34+
run()
4035
})
41-
.pipe(dstdb.createWriteStream())
36+
})
4237
})
4338
})
39+
40+
function run (cb) {
41+
stream({}, function () {
42+
stream({ keys: true }, function () {
43+
stream({ values: true }, function () {
44+
stream({ keys: true, values: true }, cb)
45+
})
46+
})
47+
})
48+
}
49+
50+
function stream (opts, cb) {
51+
var start = Date.now()
52+
srcdb.createReadStream()
53+
.on('end', function () {
54+
var copyTime = Date.now() - start
55+
console.log('Done! Took %sms with %j', copyTime, opts)
56+
if (cb) cb()
57+
})
58+
.on('data', function(){})
59+
}

0 commit comments

Comments
 (0)