-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathsqlite-prepare-select-all-options.js
More file actions
51 lines (41 loc) · 1.3 KB
/
sqlite-prepare-select-all-options.js
File metadata and controls
51 lines (41 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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);
}