From 482b2568bc90fa9fd681018ac6b9ca954e0abbc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilherme=20Ara=C3=BAjo?= Date: Fri, 23 Jan 2026 15:14:29 -0300 Subject: [PATCH] benchmark: add SQLite benchmarks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/61401 Reviewed-By: Vinícius Lourenço Claro Cardoso Reviewed-By: Antoine du Hamel --- .../sqlite-prepare-select-all-options.js | 51 +++++++++++++++++++ .../sqlite-prepare-select-get-options.js | 50 ++++++++++++++++++ 2 files changed, 101 insertions(+) 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-options.js b/benchmark/sqlite/sqlite-prepare-select-all-options.js new file mode 100644 index 00000000000..336a6b176b0 --- /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 00000000000..eb2e5074151 --- /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); +}