benchmark: sqlite prevent create both tables on prepare selects

PR-URL: https://github.com/nodejs/node/pull/59709
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
This commit is contained in:
Bruno Rodrigues 2025-09-03 16:18:05 -03:00 committed by GitHub
parent 97df3bb204
commit 5b32bb1573
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 52 additions and 38 deletions

View File

@ -26,7 +26,21 @@ const bench = common.createBenchmark(main, {
function main(conf) {
const db = new sqlite.DatabaseSync(':memory:');
db.exec('CREATE TABLE foo (text_column TEXT, integer_column INTEGER, real_column REAL, blob_column BLOB)');
// Create only the necessary table for the benchmark type.
// If the statement includes 'foo_large', create the foo_large table; otherwise, create the foo table.
if (conf.statement.includes('foo_large')) {
db.exec('CREATE TABLE foo_large (text_8kb_column TEXT)');
const fooLargeInsertStatement = db.prepare(
'INSERT INTO foo_large (text_8kb_column) VALUES (?)',
);
const largeText = 'a'.repeat(8 * 1024);
for (let i = 0; i < conf.tableSeedSize; i++) {
fooLargeInsertStatement.run(largeText);
}
} else {
db.exec(
'CREATE TABLE foo (text_column TEXT, integer_column INTEGER, real_column REAL, blob_column BLOB)',
);
const fooInsertStatement = db.prepare(
'INSERT INTO foo (text_column, integer_column, real_column, blob_column) VALUES (?, ?, ?, ?)',
);
@ -39,12 +53,6 @@ function main(conf) {
Buffer.from('example blob data'),
);
}
db.exec('CREATE TABLE foo_large (text_8kb_column TEXT)');
const fooLargeInsertStatement = db.prepare('INSERT INTO foo_large (text_8kb_column) VALUES (?)');
const largeText = 'a'.repeat(8 * 1024);
for (let i = 0; i < conf.tableSeedSize; i++) {
fooLargeInsertStatement.run(largeText);
}
let i;
@ -53,8 +61,7 @@ function main(conf) {
const stmt = db.prepare(conf.statement);
bench.start();
for (i = 0; i < conf.n; i += 1)
deadCodeElimination = stmt.all();
for (i = 0; i < conf.n; i += 1) deadCodeElimination = stmt.all();
bench.end(conf.n);
assert.ok(deadCodeElimination !== undefined);

View File

@ -20,7 +20,21 @@ const bench = common.createBenchmark(main, {
function main(conf) {
const db = new sqlite.DatabaseSync(':memory:');
db.exec('CREATE TABLE foo (text_column TEXT, integer_column INTEGER, real_column REAL, blob_column BLOB)');
// Create only the necessary table for the benchmark type.
// If the statement includes 'foo_large', create the foo_large table; otherwise, create the foo table.
if (conf.statement.includes('foo_large')) {
db.exec('CREATE TABLE foo_large (text_8kb_column TEXT)');
const fooLargeInsertStatement = db.prepare(
'INSERT INTO foo_large (text_8kb_column) VALUES (?)',
);
const largeText = 'a'.repeat(8 * 1024);
for (let i = 0; i < conf.tableSeedSize; i++) {
fooLargeInsertStatement.run(largeText);
}
} else {
db.exec(
'CREATE TABLE foo (text_column TEXT, integer_column INTEGER, real_column REAL, blob_column BLOB)',
);
const fooInsertStatement = db.prepare(
'INSERT INTO foo (text_column, integer_column, real_column, blob_column) VALUES (?, ?, ?, ?)',
);
@ -33,12 +47,6 @@ function main(conf) {
Buffer.from('example blob data'),
);
}
db.exec('CREATE TABLE foo_large (text_8kb_column TEXT)');
const fooLargeInsertStatement = db.prepare('INSERT INTO foo_large (text_8kb_column) VALUES (?)');
const largeText = 'a'.repeat(8 * 1024);
for (let i = 0; i < conf.tableSeedSize; i++) {
fooLargeInsertStatement.run(largeText);
}
let i;
@ -47,8 +55,7 @@ function main(conf) {
const stmt = db.prepare(conf.statement);
bench.start();
for (i = 0; i < conf.n; i += 1)
deadCodeElimination = stmt.get();
for (i = 0; i < conf.n; i += 1) deadCodeElimination = stmt.get();
bench.end(conf.n);
assert.ok(deadCodeElimination !== undefined);