Skip to content

Commit 7d1a43b

Browse files
committed
benchmark: add sqlite prepare select all
1 parent 6174ff6 commit 7d1a43b

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const sqlite = require('node:sqlite');
4+
const assert = require('assert');
5+
6+
const bench = common.createBenchmark(main, {
7+
n: [1e5],
8+
tableSeedSize: [1e5],
9+
statement: [
10+
'SELECT 1',
11+
'SELECT * FROM foo LIMIT 1',
12+
'SELECT * FROM foo LIMIT 100',
13+
'SELECT text_column FROM foo LIMIT 1',
14+
'SELECT text_column FROM foo LIMIT 100',
15+
'SELECT text_column, integer_column FROM foo LIMIT 1',
16+
'SELECT text_column, integer_column FROM foo LIMIT 100',
17+
'SELECT text_column, integer_column, real_column FROM foo LIMIT 1',
18+
'SELECT text_column, integer_column, real_column FROM foo LIMIT 100',
19+
'SELECT text_column, integer_column, real_column, blob_column FROM foo LIMIT 1',
20+
'SELECT text_column, integer_column, real_column, blob_column FROM foo LIMIT 100',
21+
'SELECT text_8kb_column FROM foo_large LIMIT 1',
22+
'SELECT text_8kb_column FROM foo_large LIMIT 100',
23+
],
24+
});
25+
26+
function main(conf) {
27+
const db = new sqlite.DatabaseSync(':memory:');
28+
29+
db.exec('CREATE TABLE foo (text_column TEXT, integer_column INTEGER, real_column REAL, blob_column BLOB)');
30+
const fooInsertStatement = db.prepare(
31+
'INSERT INTO foo (text_column, integer_column, real_column, blob_column) VALUES (?, ?, ?, ?)',
32+
);
33+
34+
for (let i = 0; i < conf.tableSeedSize; i++) {
35+
fooInsertStatement.run(
36+
crypto.randomUUID(),
37+
Math.floor(Math.random() * 100),
38+
Math.random(),
39+
Buffer.from('example blob data'),
40+
);
41+
}
42+
43+
db.exec('CREATE TABLE foo_large (text_8kb_column TEXT)');
44+
const fooLargeInsertStatement = db.prepare('INSERT INTO foo_large (text_8kb_column) VALUES (?)');
45+
const largeText = 'a'.repeat(8 * 1024);
46+
for (let i = 0; i < conf.tableSeedSize; i++) {
47+
fooLargeInsertStatement.run(largeText);
48+
}
49+
50+
let i;
51+
let deadCodeElimination;
52+
53+
const stmt = db.prepare(conf.statement);
54+
55+
bench.start();
56+
for (i = 0; i < conf.n; i += 1)
57+
deadCodeElimination = stmt.all();
58+
bench.end(conf.n);
59+
60+
assert.ok(deadCodeElimination !== undefined);
61+
}

0 commit comments

Comments
 (0)