Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
benchmark: add sqlite prepare select all
  • Loading branch information
H4ad committed Apr 26, 2025
commit 7d1a43bd80b27c76b7e14fe767183429b88c8d25
61 changes: 61 additions & 0 deletions benchmark/sqlite/sqlite-prepare-select-all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
'use strict';
const common = require('../common.js');
const sqlite = require('node:sqlite');
const assert = require('assert');

const bench = common.createBenchmark(main, {
n: [1e5],
tableSeedSize: [1e5],
statement: [
'SELECT 1',
'SELECT * FROM foo LIMIT 1',
'SELECT * FROM foo LIMIT 100',
'SELECT text_column FROM foo LIMIT 1',
'SELECT text_column FROM foo LIMIT 100',
'SELECT text_column, integer_column FROM foo LIMIT 1',
'SELECT text_column, integer_column FROM foo LIMIT 100',
'SELECT text_column, integer_column, real_column FROM foo LIMIT 1',
'SELECT text_column, integer_column, real_column FROM foo LIMIT 100',
'SELECT text_column, integer_column, real_column, blob_column FROM foo LIMIT 1',
'SELECT text_column, integer_column, real_column, blob_column FROM foo LIMIT 100',
'SELECT text_8kb_column FROM foo_large LIMIT 1',
'SELECT text_8kb_column FROM foo_large LIMIT 100',
],
});

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)');
const fooInsertStatement = db.prepare(
'INSERT INTO foo (text_column, integer_column, real_column, blob_column) VALUES (?, ?, ?, ?)',
);

for (let i = 0; i < conf.tableSeedSize; i++) {
fooInsertStatement.run(
crypto.randomUUID(),
Math.floor(Math.random() * 100),
Math.random(),
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;
let deadCodeElimination;

const stmt = db.prepare(conf.statement);

bench.start();
for (i = 0; i < conf.n; i += 1)
deadCodeElimination = stmt.all();
bench.end(conf.n);

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