|
| 1 | +'use strict'; |
| 2 | +const common = require('../common.js'); |
| 3 | +const sqlite = require('node:sqlite'); |
| 4 | +const assert = require('assert'); |
| 5 | + |
| 6 | +const bench = common.createBenchmark(main, { |
| 7 | + n: [1e5], |
| 8 | + tableSeedSize: [1e5], |
| 9 | + statement: [ |
| 10 | + 'SELECT 1', |
| 11 | + 'SELECT * FROM foo LIMIT 1', |
| 12 | + 'SELECT text_column FROM foo LIMIT 1', |
| 13 | + 'SELECT text_column, integer_column FROM foo LIMIT 1', |
| 14 | + 'SELECT text_column, integer_column, real_column FROM foo LIMIT 1', |
| 15 | + 'SELECT text_column, integer_column, real_column, blob_column FROM foo LIMIT 1', |
| 16 | + 'SELECT text_8kb_column FROM foo_large LIMIT 1', |
| 17 | + ], |
| 18 | +}); |
| 19 | + |
| 20 | +function main(conf) { |
| 21 | + const db = new sqlite.DatabaseSync(':memory:'); |
| 22 | + |
| 23 | + db.exec('CREATE TABLE foo (text_column TEXT, integer_column INTEGER, real_column REAL, blob_column BLOB)'); |
| 24 | + const fooInsertStatement = db.prepare( |
| 25 | + 'INSERT INTO foo (text_column, integer_column, real_column, blob_column) VALUES (?, ?, ?, ?)', |
| 26 | + ); |
| 27 | + |
| 28 | + for (let i = 0; i < conf.tableSeedSize; i++) { |
| 29 | + fooInsertStatement.run( |
| 30 | + crypto.randomUUID(), |
| 31 | + Math.floor(Math.random() * 100), |
| 32 | + Math.random(), |
| 33 | + Buffer.from('example blob data'), |
| 34 | + ); |
| 35 | + } |
| 36 | + |
| 37 | + db.exec('CREATE TABLE foo_large (text_8kb_column TEXT)'); |
| 38 | + const fooLargeInsertStatement = db.prepare('INSERT INTO foo_large (text_8kb_column) VALUES (?)'); |
| 39 | + const largeText = 'a'.repeat(8 * 1024); |
| 40 | + for (let i = 0; i < conf.tableSeedSize; i++) { |
| 41 | + fooLargeInsertStatement.run(largeText); |
| 42 | + } |
| 43 | + |
| 44 | + let i; |
| 45 | + let deadCodeElimination; |
| 46 | + |
| 47 | + const stmt = db.prepare(conf.statement); |
| 48 | + |
| 49 | + bench.start(); |
| 50 | + for (i = 0; i < conf.n; i += 1) |
| 51 | + deadCodeElimination = stmt.get(); |
| 52 | + bench.end(conf.n); |
| 53 | + |
| 54 | + assert.ok(deadCodeElimination !== undefined); |
| 55 | +} |
0 commit comments