Skip to content

Commit 442b416

Browse files
H4adRafaelGSS
authored andcommitted
benchmark: add sqlite prepare select get
PR-URL: #58040 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
1 parent 2d894ea commit 442b416

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy