Skip to content

Commit 9d2cfe3

Browse files
committed
benchmark: sqlite prevent create both tables on prepare selects
1 parent b0ce28e commit 9d2cfe3

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

benchmark/sqlite/sqlite-prepare-select-all.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const bench = common.createBenchmark(main, {
2626
function main(conf) {
2727
const db = new sqlite.DatabaseSync(':memory:');
2828

29-
// check which table is used, to just create the necessary table for each type of bench
29+
// Create only the necessary table for the benchmark type.
30+
// If the statement includes 'foo_large', create the foo_large table; otherwise, create the foo table.
3031
if (conf.statement.includes('foo_large')) {
3132
db.exec('CREATE TABLE foo_large (text_8kb_column TEXT)');
3233
const fooLargeInsertStatement = db.prepare(

benchmark/sqlite/sqlite-prepare-select-get.js

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,33 @@ const bench = common.createBenchmark(main, {
2020
function main(conf) {
2121
const db = new sqlite.DatabaseSync(':memory:');
2222

23-
db.exec('CREATE TABLE foo (text_column TEXT, integer_column INTEGER, real_column REAL, blob_column BLOB)');
24-
const fooInsertStatement = db.prepare(
25-
'INSERT INTO foo (text_column, integer_column, real_column, blob_column) VALUES (?, ?, ?, ?)',
26-
);
27-
28-
for (let i = 0; i < conf.tableSeedSize; i++) {
29-
fooInsertStatement.run(
30-
crypto.randomUUID(),
31-
Math.floor(Math.random() * 100),
32-
Math.random(),
33-
Buffer.from('example blob data'),
23+
// Create only the necessary table for the benchmark type.
24+
// If the statement includes 'foo_large', create the foo_large table; otherwise, create the foo table.
25+
if (conf.statment.includes('foo_large')) {
26+
db.exec('CREATE TABLE foo_large (text_8kb_column TEXT)');
27+
const fooLargeInsertStatement = db.prepare(
28+
'INSERT INTO foo_large (text_8kb_column) VALUES (?)',
29+
);
30+
const largeText = 'a'.repeat(8 * 1024);
31+
for (let i = 0; i < conf.tableSeedSize; i++) {
32+
fooLargeInsertStatement.run(largeText);
33+
}
34+
} else {
35+
db.exec(
36+
'CREATE TABLE foo (text_column TEXT, integer_column INTEGER, real_column REAL, blob_column BLOB)',
37+
);
38+
const fooInsertStatement = db.prepare(
39+
'INSERT INTO foo (text_column, integer_column, real_column, blob_column) VALUES (?, ?, ?, ?)',
3440
);
35-
}
3641

37-
db.exec('CREATE TABLE foo_large (text_8kb_column TEXT)');
38-
const fooLargeInsertStatement = db.prepare('INSERT INTO foo_large (text_8kb_column) VALUES (?)');
39-
const largeText = 'a'.repeat(8 * 1024);
40-
for (let i = 0; i < conf.tableSeedSize; i++) {
41-
fooLargeInsertStatement.run(largeText);
42+
for (let i = 0; i < conf.tableSeedSize; i++) {
43+
fooInsertStatement.run(
44+
crypto.randomUUID(),
45+
Math.floor(Math.random() * 100),
46+
Math.random(),
47+
Buffer.from('example blob data'),
48+
);
49+
}
4250
}
4351

4452
let i;
@@ -47,8 +55,7 @@ function main(conf) {
4755
const stmt = db.prepare(conf.statement);
4856

4957
bench.start();
50-
for (i = 0; i < conf.n; i += 1)
51-
deadCodeElimination = stmt.get();
58+
for (i = 0; i < conf.n; i += 1) deadCodeElimination = stmt.get();
5259
bench.end(conf.n);
5360

5461
assert.ok(deadCodeElimination !== undefined);

0 commit comments

Comments
 (0)