From a30295d2704045e3bfcb2774a42e56c22545e938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilherme=20Ara=C3=BAjo?= Date: Fri, 16 Jan 2026 11:26:27 -0300 Subject: [PATCH 1/4] sqlite: create options benchmarks --- benchmark/sqlite/sqlite-prepare-select-all.js | 8 +++++++- benchmark/sqlite/sqlite-prepare-select-get.js | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/benchmark/sqlite/sqlite-prepare-select-all.js b/benchmark/sqlite/sqlite-prepare-select-all.js index c8487dca471b84..2ad4766a25be74 100644 --- a/benchmark/sqlite/sqlite-prepare-select-all.js +++ b/benchmark/sqlite/sqlite-prepare-select-all.js @@ -21,10 +21,16 @@ const bench = common.createBenchmark(main, { 'SELECT text_8kb_column FROM foo_large LIMIT 1', 'SELECT text_8kb_column FROM foo_large LIMIT 100', ], + options: ['none', 'readBigInts', 'returnArrays', 'readBigInts|returnArrays'], }); function main(conf) { - const db = new sqlite.DatabaseSync(':memory:'); + const optionsObj = conf.options === 'none' ? {} : conf.options.split('|').reduce((acc, key) => { + acc[key] = true; + return acc; + }, {}); + + const db = new sqlite.DatabaseSync(':memory:', optionsObj); // 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. diff --git a/benchmark/sqlite/sqlite-prepare-select-get.js b/benchmark/sqlite/sqlite-prepare-select-get.js index 0fff29ce5686da..8e046e61d63b7a 100644 --- a/benchmark/sqlite/sqlite-prepare-select-get.js +++ b/benchmark/sqlite/sqlite-prepare-select-get.js @@ -15,10 +15,16 @@ const bench = common.createBenchmark(main, { 'SELECT text_column, integer_column, real_column, blob_column FROM foo LIMIT 1', 'SELECT text_8kb_column FROM foo_large LIMIT 1', ], + options: ['none', 'readBigInts', 'returnArrays', 'readBigInts|returnArrays'], }); function main(conf) { - const db = new sqlite.DatabaseSync(':memory:'); + const optionsObj = conf.options === 'none' ? {} : conf.options.split('|').reduce((acc, key) => { + acc[key] = true; + return acc; + }, {}); + + const db = new sqlite.DatabaseSync(':memory:', optionsObj); // 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. From e1646da729b5065162043ed89c0f8f87118cea51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilherme=20Ara=C3=BAjo?= Date: Fri, 16 Jan 2026 15:49:43 -0300 Subject: [PATCH 2/4] sqlite: split benchmarks --- .../sqlite-prepare-select-all-arrays.js | 70 ++++++++++++++++++ ...sqlite-prepare-select-all-bigint-arrays.js | 71 +++++++++++++++++++ .../sqlite-prepare-select-all-bigint.js | 43 +++++++++++ benchmark/sqlite/sqlite-prepare-select-all.js | 8 +-- benchmark/sqlite/sqlite-prepare-select-get.js | 8 +-- 5 files changed, 186 insertions(+), 14 deletions(-) create mode 100644 benchmark/sqlite/sqlite-prepare-select-all-arrays.js create mode 100644 benchmark/sqlite/sqlite-prepare-select-all-bigint-arrays.js create mode 100644 benchmark/sqlite/sqlite-prepare-select-all-bigint.js diff --git a/benchmark/sqlite/sqlite-prepare-select-all-arrays.js b/benchmark/sqlite/sqlite-prepare-select-all-arrays.js new file mode 100644 index 00000000000000..2a3029aeb6b943 --- /dev/null +++ b/benchmark/sqlite/sqlite-prepare-select-all-arrays.js @@ -0,0 +1,70 @@ +'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:', { + returnArrays: true, + }); + + // 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 (?, ?, ?, ?)', + ); + + for (let i = 0; i < conf.tableSeedSize; i++) { + fooInsertStatement.run( + crypto.randomUUID(), + Math.floor(Math.random() * 100), + Math.random(), + Buffer.from('example blob data'), + ); + } + } + + 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); +} diff --git a/benchmark/sqlite/sqlite-prepare-select-all-bigint-arrays.js b/benchmark/sqlite/sqlite-prepare-select-all-bigint-arrays.js new file mode 100644 index 00000000000000..2ec2166696aa9b --- /dev/null +++ b/benchmark/sqlite/sqlite-prepare-select-all-bigint-arrays.js @@ -0,0 +1,71 @@ +'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:', { + returnArrays: true, + readBigInts: true + }); + + // 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 (?, ?, ?, ?)', + ); + + for (let i = 0; i < conf.tableSeedSize; i++) { + fooInsertStatement.run( + crypto.randomUUID(), + Math.floor(Math.random() * 100), + Math.random(), + Buffer.from('example blob data'), + ); + } + } + + 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); +} diff --git a/benchmark/sqlite/sqlite-prepare-select-all-bigint.js b/benchmark/sqlite/sqlite-prepare-select-all-bigint.js new file mode 100644 index 00000000000000..f04ad90691cc28 --- /dev/null +++ b/benchmark/sqlite/sqlite-prepare-select-all-bigint.js @@ -0,0 +1,43 @@ +'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 integer_column FROM foo LIMIT 1', + 'SELECT integer_column FROM foo LIMIT 100', + ], +}); + +function main(conf) { + const db = new sqlite.DatabaseSync(':memory:', { + readBigInts: true + }); + + db.exec('CREATE TABLE foo (integer_column INTEGER)'); + + const fooInsertStatement = db.prepare( + 'INSERT INTO foo (integer_column) VALUES (?)', + ); + + for (let i = 0; i < conf.tableSeedSize; i++) { + fooInsertStatement.run(Math.floor(Math.random() * 100)); + } + + 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); +} diff --git a/benchmark/sqlite/sqlite-prepare-select-all.js b/benchmark/sqlite/sqlite-prepare-select-all.js index 2ad4766a25be74..c8487dca471b84 100644 --- a/benchmark/sqlite/sqlite-prepare-select-all.js +++ b/benchmark/sqlite/sqlite-prepare-select-all.js @@ -21,16 +21,10 @@ const bench = common.createBenchmark(main, { 'SELECT text_8kb_column FROM foo_large LIMIT 1', 'SELECT text_8kb_column FROM foo_large LIMIT 100', ], - options: ['none', 'readBigInts', 'returnArrays', 'readBigInts|returnArrays'], }); function main(conf) { - const optionsObj = conf.options === 'none' ? {} : conf.options.split('|').reduce((acc, key) => { - acc[key] = true; - return acc; - }, {}); - - const db = new sqlite.DatabaseSync(':memory:', optionsObj); + const db = new sqlite.DatabaseSync(':memory:'); // 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. diff --git a/benchmark/sqlite/sqlite-prepare-select-get.js b/benchmark/sqlite/sqlite-prepare-select-get.js index 8e046e61d63b7a..0fff29ce5686da 100644 --- a/benchmark/sqlite/sqlite-prepare-select-get.js +++ b/benchmark/sqlite/sqlite-prepare-select-get.js @@ -15,16 +15,10 @@ const bench = common.createBenchmark(main, { 'SELECT text_column, integer_column, real_column, blob_column FROM foo LIMIT 1', 'SELECT text_8kb_column FROM foo_large LIMIT 1', ], - options: ['none', 'readBigInts', 'returnArrays', 'readBigInts|returnArrays'], }); function main(conf) { - const optionsObj = conf.options === 'none' ? {} : conf.options.split('|').reduce((acc, key) => { - acc[key] = true; - return acc; - }, {}); - - const db = new sqlite.DatabaseSync(':memory:', optionsObj); + const db = new sqlite.DatabaseSync(':memory:'); // 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. From 578173bb43e896f04cdd54b443b31dc0b33836ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilherme=20Ara=C3=BAjo?= Date: Fri, 16 Jan 2026 16:06:16 -0300 Subject: [PATCH 3/4] sqlite: lint benchmarks --- benchmark/sqlite/sqlite-prepare-select-all-bigint-arrays.js | 2 +- benchmark/sqlite/sqlite-prepare-select-all-bigint.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/benchmark/sqlite/sqlite-prepare-select-all-bigint-arrays.js b/benchmark/sqlite/sqlite-prepare-select-all-bigint-arrays.js index 2ec2166696aa9b..f7d10cd602d31d 100644 --- a/benchmark/sqlite/sqlite-prepare-select-all-bigint-arrays.js +++ b/benchmark/sqlite/sqlite-prepare-select-all-bigint-arrays.js @@ -26,7 +26,7 @@ const bench = common.createBenchmark(main, { function main(conf) { const db = new sqlite.DatabaseSync(':memory:', { returnArrays: true, - readBigInts: true + readBigInts: true, }); // Create only the necessary table for the benchmark type. diff --git a/benchmark/sqlite/sqlite-prepare-select-all-bigint.js b/benchmark/sqlite/sqlite-prepare-select-all-bigint.js index f04ad90691cc28..97b9bfe25c99ba 100644 --- a/benchmark/sqlite/sqlite-prepare-select-all-bigint.js +++ b/benchmark/sqlite/sqlite-prepare-select-all-bigint.js @@ -17,7 +17,7 @@ const bench = common.createBenchmark(main, { function main(conf) { const db = new sqlite.DatabaseSync(':memory:', { - readBigInts: true + readBigInts: true, }); db.exec('CREATE TABLE foo (integer_column INTEGER)'); From a4fbd763de39c78296f4338b1c2ea5e7b6c2b191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilherme=20Ara=C3=BAjo?= Date: Sat, 17 Jan 2026 06:05:56 -0300 Subject: [PATCH 4/4] sqlite: unify benchmarks --- .../sqlite-prepare-select-all-arrays.js | 70 ------------------ ...sqlite-prepare-select-all-bigint-arrays.js | 71 ------------------- .../sqlite-prepare-select-all-bigint.js | 43 ----------- .../sqlite-prepare-select-all-options.js | 51 +++++++++++++ .../sqlite-prepare-select-get-options.js | 50 +++++++++++++ 5 files changed, 101 insertions(+), 184 deletions(-) delete mode 100644 benchmark/sqlite/sqlite-prepare-select-all-arrays.js delete mode 100644 benchmark/sqlite/sqlite-prepare-select-all-bigint-arrays.js delete mode 100644 benchmark/sqlite/sqlite-prepare-select-all-bigint.js create mode 100644 benchmark/sqlite/sqlite-prepare-select-all-options.js create mode 100644 benchmark/sqlite/sqlite-prepare-select-get-options.js diff --git a/benchmark/sqlite/sqlite-prepare-select-all-arrays.js b/benchmark/sqlite/sqlite-prepare-select-all-arrays.js deleted file mode 100644 index 2a3029aeb6b943..00000000000000 --- a/benchmark/sqlite/sqlite-prepare-select-all-arrays.js +++ /dev/null @@ -1,70 +0,0 @@ -'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:', { - returnArrays: true, - }); - - // 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 (?, ?, ?, ?)', - ); - - for (let i = 0; i < conf.tableSeedSize; i++) { - fooInsertStatement.run( - crypto.randomUUID(), - Math.floor(Math.random() * 100), - Math.random(), - Buffer.from('example blob data'), - ); - } - } - - 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); -} diff --git a/benchmark/sqlite/sqlite-prepare-select-all-bigint-arrays.js b/benchmark/sqlite/sqlite-prepare-select-all-bigint-arrays.js deleted file mode 100644 index f7d10cd602d31d..00000000000000 --- a/benchmark/sqlite/sqlite-prepare-select-all-bigint-arrays.js +++ /dev/null @@ -1,71 +0,0 @@ -'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:', { - returnArrays: true, - readBigInts: true, - }); - - // 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 (?, ?, ?, ?)', - ); - - for (let i = 0; i < conf.tableSeedSize; i++) { - fooInsertStatement.run( - crypto.randomUUID(), - Math.floor(Math.random() * 100), - Math.random(), - Buffer.from('example blob data'), - ); - } - } - - 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); -} diff --git a/benchmark/sqlite/sqlite-prepare-select-all-bigint.js b/benchmark/sqlite/sqlite-prepare-select-all-bigint.js deleted file mode 100644 index 97b9bfe25c99ba..00000000000000 --- a/benchmark/sqlite/sqlite-prepare-select-all-bigint.js +++ /dev/null @@ -1,43 +0,0 @@ -'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 integer_column FROM foo LIMIT 1', - 'SELECT integer_column FROM foo LIMIT 100', - ], -}); - -function main(conf) { - const db = new sqlite.DatabaseSync(':memory:', { - readBigInts: true, - }); - - db.exec('CREATE TABLE foo (integer_column INTEGER)'); - - const fooInsertStatement = db.prepare( - 'INSERT INTO foo (integer_column) VALUES (?)', - ); - - for (let i = 0; i < conf.tableSeedSize; i++) { - fooInsertStatement.run(Math.floor(Math.random() * 100)); - } - - 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); -} diff --git a/benchmark/sqlite/sqlite-prepare-select-all-options.js b/benchmark/sqlite/sqlite-prepare-select-all-options.js new file mode 100644 index 00000000000000..336a6b176b0d87 --- /dev/null +++ b/benchmark/sqlite/sqlite-prepare-select-all-options.js @@ -0,0 +1,51 @@ +'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 * FROM foo LIMIT 1', + 'SELECT * FROM foo LIMIT 100', + ], + options: ['none', 'readBigInts', 'returnArrays', 'readBigInts|returnArrays'], +}); + +function main(conf) { + const optionsObj = conf.options === 'none' ? {} : conf.options.split('|').reduce((acc, key) => { + acc[key] = true; + return acc; + }, {}); + + const db = new sqlite.DatabaseSync(':memory:', optionsObj); + + 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'), + ); + } + + 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); +} diff --git a/benchmark/sqlite/sqlite-prepare-select-get-options.js b/benchmark/sqlite/sqlite-prepare-select-get-options.js new file mode 100644 index 00000000000000..eb2e5074151af2 --- /dev/null +++ b/benchmark/sqlite/sqlite-prepare-select-get-options.js @@ -0,0 +1,50 @@ +'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 * FROM foo LIMIT 1', + ], + options: ['none', 'readBigInts', 'returnArrays', 'readBigInts|returnArrays'], +}); + +function main(conf) { + const optionsObj = conf.options === 'none' ? {} : conf.options.split('|').reduce((acc, key) => { + acc[key] = true; + return acc; + }, {}); + + const db = new sqlite.DatabaseSync(':memory:', optionsObj); + + 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'), + ); + } + + let i; + let deadCodeElimination; + + const stmt = db.prepare(conf.statement); + + bench.start(); + for (i = 0; i < conf.n; i += 1) deadCodeElimination = stmt.get(); + bench.end(conf.n); + + assert.ok(deadCodeElimination !== undefined); +}