Skip to content

Commit a774b05

Browse files
H4adaduh95
authored andcommitted
benchmark: add sqlite is transaction
PR-URL: #58040 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Edy Silva <[email protected]>
1 parent 0d7a43b commit a774b05

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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: [1e7],
8+
transaction: ['true', 'false'],
9+
});
10+
11+
function main(conf) {
12+
const db = new sqlite.DatabaseSync(':memory:');
13+
14+
if (conf.transaction === 'true') {
15+
db.exec('BEGIN');
16+
}
17+
18+
let i;
19+
let deadCodeElimination;
20+
21+
bench.start();
22+
for (i = 0; i < conf.n; i += 1)
23+
deadCodeElimination &&= db.isTransaction;
24+
bench.end(conf.n);
25+
26+
assert.ok(deadCodeElimination === (conf.transaction === 'true'));
27+
28+
if (conf.transaction === 'true') {
29+
db.exec('ROLLBACK');
30+
}
31+
}

0 commit comments

Comments
 (0)