forked from denodrivers/sqlite3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench_deno_wasm.js
More file actions
26 lines (20 loc) · 825 Bytes
/
bench_deno_wasm.js
File metadata and controls
26 lines (20 loc) · 825 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
import { DB } from "https://deno.land/x/sqlite@v3.9.1/mod.ts";
import { nextTick } from "https://deno.land/std@0.126.0/node/_next_tick.ts";
const db = new DB(":memory:");
db.query("PRAGMA auto_vacuum = none");
db.query("PRAGMA temp_store = memory");
db.query("PRAGMA locking_mode = exclusive");
db.query("PRAGMA user_version = 100");
const sql = "pragma user_version";
let total = parseInt(Deno.args[0], 10);
const runs = parseInt(Deno.args[1], 10);
function bench(query) {
const start = performance.now();
for (let i = 0; i < runs; i++) query();
const elapsed = Math.floor(performance.now() - start);
const rate = Math.floor(runs / (elapsed / 1000));
console.log(`time ${elapsed} ms rate ${rate}`);
if (--total) nextTick(() => bench(query));
}
const query = db.prepareQuery(sql);
bench(() => query.one());