|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +exports = module.exports = function (ourDb, theirDb, count) { |
| 4 | + function callback0() { |
| 5 | + global.gc(); |
| 6 | + ourTest(ourDb, count, callback1); |
| 7 | + } |
| 8 | + function callback1() { |
| 9 | + global.gc(); |
| 10 | + theirTest(theirDb, count, callback2); |
| 11 | + } |
| 12 | + function callback2() { |
| 13 | + var closedCount = 0; |
| 14 | + ourDb.on('close', closed).close(); |
| 15 | + theirDb.close(closed); |
| 16 | + function closed() { |
| 17 | + ++closedCount === 2 && process.exit(); |
| 18 | + } |
| 19 | + } |
| 20 | + setTimeout(callback0, 100); |
| 21 | +}; |
| 22 | + |
| 23 | +exports.data = undefined; |
| 24 | + |
| 25 | +function ourTest(db, count, done) { |
| 26 | + var t0 = process.hrtime(); |
| 27 | + for (var i=0; i<count; ++i) { |
| 28 | + exports.data = db.prepare('SELECT * FROM entries'); |
| 29 | + } |
| 30 | + var td = process.hrtime(t0); |
| 31 | + report('better-sqlite3', count, td); |
| 32 | + done(); |
| 33 | +} |
| 34 | +function theirTest(db, count, done) { |
| 35 | + var completed = 0; |
| 36 | + var t0 = process.hrtime(); |
| 37 | + for (var i=0; i<count; ++i) { |
| 38 | + db.prepare('SELECT * FROM entries', callback); |
| 39 | + } |
| 40 | + function callback(err, data) { |
| 41 | + exports.data = data; |
| 42 | + if (err) {throw err;} |
| 43 | + if (++completed === count) { |
| 44 | + var td = process.hrtime(t0); |
| 45 | + report('node-sqlite3', count, td); |
| 46 | + done(); |
| 47 | + } |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +function report(name, count, time) { |
| 52 | + var ms = time[0] * 1000 + Math.round(time[1] / 1000000); |
| 53 | + console.log(name + '\t' + count + ' prepared statements in ' + ms + 'ms'); |
| 54 | +} |
0 commit comments