Skip to content

Commit 2d894ea

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

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
'use strict';
2+
constcommon=require('../common.js');
3+
constsqlite=require('node:sqlite');
4+
constassert=require('assert');
5+
6+
constbench=common.createBenchmark(main,{
7+
n: [1e5],
8+
tableSeedSize: [1e5],
9+
statement: [
10+
'SELECT 1',
11+
'SELECT * FROM foo LIMIT 1',
12+
'SELECT * FROM foo LIMIT 100',
13+
'SELECT text_column FROM foo LIMIT 1',
14+
'SELECT text_column FROM foo LIMIT 100',
15+
'SELECT text_column, integer_column FROM foo LIMIT 1',
16+
'SELECT text_column, integer_column FROM foo LIMIT 100',
17+
'SELECT text_column, integer_column, real_column FROM foo LIMIT 1',
18+
'SELECT text_column, integer_column, real_column FROM foo LIMIT 100',
19+
'SELECT text_column, integer_column, real_column, blob_column FROM foo LIMIT 1',
20+
'SELECT text_column, integer_column, real_column, blob_column FROM foo LIMIT 100',
21+
'SELECT text_8kb_column FROM foo_large LIMIT 1',
22+
'SELECT text_8kb_column FROM foo_large LIMIT 100',
23+
],
24+
});
25+
26+
functionmain(conf){
27+
constdb=newsqlite.DatabaseSync(':memory:');
28+
29+
db.exec('CREATE TABLE foo (text_column TEXT, integer_column INTEGER, real_column REAL, blob_column BLOB)');
30+
constfooInsertStatement=db.prepare(
31+
'INSERT INTO foo (text_column, integer_column, real_column, blob_column) VALUES (?, ?, ?, ?)',
32+
);
33+
34+
for(leti=0;i<conf.tableSeedSize;i++){
35+
fooInsertStatement.run(
36+
crypto.randomUUID(),
37+
Math.floor(Math.random()*100),
38+
Math.random(),
39+
Buffer.from('example blob data'),
40+
);
41+
}
42+
43+
db.exec('CREATE TABLE foo_large (text_8kb_column TEXT)');
44+
constfooLargeInsertStatement=db.prepare('INSERT INTO foo_large (text_8kb_column) VALUES (?)');
45+
constlargeText='a'.repeat(8*1024);
46+
for(leti=0;i<conf.tableSeedSize;i++){
47+
fooLargeInsertStatement.run(largeText);
48+
}
49+
50+
leti;
51+
letdeadCodeElimination;
52+
53+
conststmt=db.prepare(conf.statement);
54+
55+
bench.start();
56+
for(i=0;i<conf.n;i+=1)
57+
deadCodeElimination=stmt.all();
58+
bench.end(conf.n);
59+
60+
assert.ok(deadCodeElimination!==undefined);
61+
}

0 commit comments

Comments
 (0)