Skip to content

Commit 482b256

Browse files
araujoguiaduh95
authored andcommitted
benchmark: add SQLite benchmarks
PR-URL: #61401 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 236d7ee commit 482b256

2 files changed

Lines changed: 101 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)