|
| 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 * FROM foo LIMIT 1', |
| 11 | + 'SELECT * FROM foo LIMIT 100', |
| 12 | + ], |
| 13 | + options: ['none', 'readBigInts', 'returnArrays', 'readBigInts|returnArrays'], |
| 14 | +}); |
| 15 | + |
| 16 | +function main(conf) { |
| 17 | + const optionsObj = conf.options === 'none' ? {} : conf.options.split('|').reduce((acc, key) => { |
| 18 | + acc[key] = true; |
| 19 | + return acc; |
| 20 | + }, {}); |
| 21 | + |
| 22 | + const db = new sqlite.DatabaseSync(':memory:', optionsObj); |
| 23 | + |
| 24 | + db.exec( |
| 25 | + 'CREATE TABLE foo (text_column TEXT, integer_column INTEGER, real_column REAL, blob_column BLOB)', |
| 26 | + ); |
| 27 | + |
| 28 | + const fooInsertStatement = db.prepare( |
| 29 | + 'INSERT INTO foo (text_column, integer_column, real_column, blob_column) VALUES (?, ?, ?, ?)', |
| 30 | + ); |
| 31 | + |
| 32 | + for (let i = 0; i < conf.tableSeedSize; i++) { |
| 33 | + fooInsertStatement.run( |
| 34 | + crypto.randomUUID(), |
| 35 | + Math.floor(Math.random() * 100), |
| 36 | + Math.random(), |
| 37 | + Buffer.from('example blob data'), |
| 38 | + ); |
| 39 | + } |
| 40 | + |
| 41 | + let i; |
| 42 | + let deadCodeElimination; |
| 43 | + |
| 44 | + const stmt = db.prepare(conf.statement); |
| 45 | + |
| 46 | + bench.start(); |
| 47 | + for (i = 0; i < conf.n; i += 1) deadCodeElimination = stmt.all(); |
| 48 | + bench.end(conf.n); |
| 49 | + |
| 50 | + assert.ok(deadCodeElimination !== undefined); |
| 51 | +} |
0 commit comments