-
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathbench_node.js
More file actions
30 lines (23 loc) · 789 Bytes
/
bench_node.js
File metadata and controls
30 lines (23 loc) · 789 Bytes
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
import process from "node:process";
import pkg from "better-sqlite3";
const db = pkg(":memory:");
db.exec("PRAGMA auto_vacuum = none");
db.exec("PRAGMA temp_store = memory");
db.exec("PRAGMA locking_mode = exclusive");
db.exec("PRAGMA user_version = 100");
const sql = "pragma user_version";
function createQuery(sql) {
return db.prepare(sql);
}
let total = parseInt(process.argv[2], 10);
const runs = parseInt(process.argv[3], 10);
function bench(query) {
const start = Date.now();
for (let i = 0; i < runs; i++) query();
const elapsed = Date.now() - start;
const rate = Math.floor(runs / (elapsed / 1000));
console.log(`time ${elapsed} ms rate ${rate}`);
if (--total) process.nextTick(() => bench(query));
}
const query = createQuery(sql);
bench(() => query.get());