mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01:00
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:
parent
97df3bb204
commit
5b32bb1573
|
|
@ -26,25 +26,33 @@ const bench = common.createBenchmark(main, {
|
||||||
function main(conf) {
|
function main(conf) {
|
||||||
const db = new sqlite.DatabaseSync(':memory:');
|
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.
|
||||||
const fooInsertStatement = db.prepare(
|
// If the statement includes 'foo_large', create the foo_large table; otherwise, create the foo table.
|
||||||
'INSERT INTO foo (text_column, integer_column, real_column, blob_column) VALUES (?, ?, ?, ?)',
|
if (conf.statement.includes('foo_large')) {
|
||||||
);
|
db.exec('CREATE TABLE foo_large (text_8kb_column TEXT)');
|
||||||
|
const fooLargeInsertStatement = db.prepare(
|
||||||
for (let i = 0; i < conf.tableSeedSize; i++) {
|
'INSERT INTO foo_large (text_8kb_column) VALUES (?)',
|
||||||
fooInsertStatement.run(
|
);
|
||||||
crypto.randomUUID(),
|
const largeText = 'a'.repeat(8 * 1024);
|
||||||
Math.floor(Math.random() * 100),
|
for (let i = 0; i < conf.tableSeedSize; i++) {
|
||||||
Math.random(),
|
fooLargeInsertStatement.run(largeText);
|
||||||
Buffer.from('example blob data'),
|
}
|
||||||
|
} 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 (?, ?, ?, ?)',
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
db.exec('CREATE TABLE foo_large (text_8kb_column TEXT)');
|
for (let i = 0; i < conf.tableSeedSize; i++) {
|
||||||
const fooLargeInsertStatement = db.prepare('INSERT INTO foo_large (text_8kb_column) VALUES (?)');
|
fooInsertStatement.run(
|
||||||
const largeText = 'a'.repeat(8 * 1024);
|
crypto.randomUUID(),
|
||||||
for (let i = 0; i < conf.tableSeedSize; i++) {
|
Math.floor(Math.random() * 100),
|
||||||
fooLargeInsertStatement.run(largeText);
|
Math.random(),
|
||||||
|
Buffer.from('example blob data'),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let i;
|
let i;
|
||||||
|
|
@ -53,8 +61,7 @@ function main(conf) {
|
||||||
const stmt = db.prepare(conf.statement);
|
const stmt = db.prepare(conf.statement);
|
||||||
|
|
||||||
bench.start();
|
bench.start();
|
||||||
for (i = 0; i < conf.n; i += 1)
|
for (i = 0; i < conf.n; i += 1) deadCodeElimination = stmt.all();
|
||||||
deadCodeElimination = stmt.all();
|
|
||||||
bench.end(conf.n);
|
bench.end(conf.n);
|
||||||
|
|
||||||
assert.ok(deadCodeElimination !== undefined);
|
assert.ok(deadCodeElimination !== undefined);
|
||||||
|
|
|
||||||
|
|
@ -20,25 +20,33 @@ const bench = common.createBenchmark(main, {
|
||||||
function main(conf) {
|
function main(conf) {
|
||||||
const db = new sqlite.DatabaseSync(':memory:');
|
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.
|
||||||
const fooInsertStatement = db.prepare(
|
// If the statement includes 'foo_large', create the foo_large table; otherwise, create the foo table.
|
||||||
'INSERT INTO foo (text_column, integer_column, real_column, blob_column) VALUES (?, ?, ?, ?)',
|
if (conf.statement.includes('foo_large')) {
|
||||||
);
|
db.exec('CREATE TABLE foo_large (text_8kb_column TEXT)');
|
||||||
|
const fooLargeInsertStatement = db.prepare(
|
||||||
for (let i = 0; i < conf.tableSeedSize; i++) {
|
'INSERT INTO foo_large (text_8kb_column) VALUES (?)',
|
||||||
fooInsertStatement.run(
|
);
|
||||||
crypto.randomUUID(),
|
const largeText = 'a'.repeat(8 * 1024);
|
||||||
Math.floor(Math.random() * 100),
|
for (let i = 0; i < conf.tableSeedSize; i++) {
|
||||||
Math.random(),
|
fooLargeInsertStatement.run(largeText);
|
||||||
Buffer.from('example blob data'),
|
}
|
||||||
|
} 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 (?, ?, ?, ?)',
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
db.exec('CREATE TABLE foo_large (text_8kb_column TEXT)');
|
for (let i = 0; i < conf.tableSeedSize; i++) {
|
||||||
const fooLargeInsertStatement = db.prepare('INSERT INTO foo_large (text_8kb_column) VALUES (?)');
|
fooInsertStatement.run(
|
||||||
const largeText = 'a'.repeat(8 * 1024);
|
crypto.randomUUID(),
|
||||||
for (let i = 0; i < conf.tableSeedSize; i++) {
|
Math.floor(Math.random() * 100),
|
||||||
fooLargeInsertStatement.run(largeText);
|
Math.random(),
|
||||||
|
Buffer.from('example blob data'),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let i;
|
let i;
|
||||||
|
|
@ -47,8 +55,7 @@ function main(conf) {
|
||||||
const stmt = db.prepare(conf.statement);
|
const stmt = db.prepare(conf.statement);
|
||||||
|
|
||||||
bench.start();
|
bench.start();
|
||||||
for (i = 0; i < conf.n; i += 1)
|
for (i = 0; i < conf.n; i += 1) deadCodeElimination = stmt.get();
|
||||||
deadCodeElimination = stmt.get();
|
|
||||||
bench.end(conf.n);
|
bench.end(conf.n);
|
||||||
|
|
||||||
assert.ok(deadCodeElimination !== undefined);
|
assert.ok(deadCodeElimination !== undefined);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user