Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9da50a6

Browse filesBrowse files
brunocrohrichardlau
authored andcommitted
benchmark: sqlite prevent create both tables on prepare selects
PR-URL: #59709 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
1 parent d7adf8b commit 9da50a6
Copy full SHA for 9da50a6

File tree

Expand file treeCollapse file tree

2 files changed

+52
-38
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+52
-38
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: benchmark/sqlite/sqlite-prepare-select-all.js
+26-19Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,33 @@ const bench = common.createBenchmark(main, {
2626
function main(conf) {
2727
const db = new sqlite.DatabaseSync(':memory:');
2828

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'),
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.
31+
if (conf.statement.includes('foo_large')) {
32+
db.exec('CREATE TABLE foo_large (text_8kb_column TEXT)');
33+
const fooLargeInsertStatement = db.prepare(
34+
'INSERT INTO foo_large (text_8kb_column) VALUES (?)',
35+
);
36+
const largeText = 'a'.repeat(8 * 1024);
37+
for (let i = 0; i < conf.tableSeedSize; i++) {
38+
fooLargeInsertStatement.run(largeText);
39+
}
40+
} else {
41+
db.exec(
42+
'CREATE TABLE foo (text_column TEXT, integer_column INTEGER, real_column REAL, blob_column BLOB)',
43+
);
44+
const fooInsertStatement = db.prepare(
45+
'INSERT INTO foo (text_column, integer_column, real_column, blob_column) VALUES (?, ?, ?, ?)',
4046
);
41-
}
4247

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+
for (let i = 0; i < conf.tableSeedSize; i++) {
49+
fooInsertStatement.run(
50+
crypto.randomUUID(),
51+
Math.floor(Math.random() * 100),
52+
Math.random(),
53+
Buffer.from('example blob data'),
54+
);
55+
}
4856
}
4957

5058
let i;
@@ -53,8 +61,7 @@ function main(conf) {
5361
const stmt = db.prepare(conf.statement);
5462

5563
bench.start();
56-
for (i = 0; i < conf.n; i += 1)
57-
deadCodeElimination = stmt.all();
64+
for (i = 0; i < conf.n; i += 1) deadCodeElimination = stmt.all();
5865
bench.end(conf.n);
5966

6067
assert.ok(deadCodeElimination !== undefined);
Collapse file

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

Copy file name to clipboardExpand all lines: benchmark/sqlite/sqlite-prepare-select-get.js
+26-19Lines 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.statement.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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.