Skip to content

Commit 4a9846d

Browse files
author
Joshua Wise
committed
added benchmarks for creating prepared statements
1 parent 5a73a4e commit 4a9846d

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

benchmark/trials/0.prepare.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'use strict';
2+
require('../get-db')('real-world', function (ourDb, theirDb) {
3+
require('../types/prepare')(ourDb, theirDb, 100000);
4+
});

benchmark/types/prepare.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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

Comments
 (0)