-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.ts
44 lines (38 loc) · 998 Bytes
/
bench.ts
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { run, bench, compact, summary } from "mitata";
import { Database } from "bun:sqlite";
import { LoremIpsum } from "lorem-ipsum";
const lorem = new LoremIpsum({
sentencesPerParagraph: {
max: 15,
min: 10,
},
wordsPerSentence: {
max: 50,
min: 20,
},
});
const text = lorem.generateParagraphs(100);
function initDatabase() {
const db = new Database(":memory:");
db.loadExtension("./dist/better-trigram.so");
return db;
}
const db = initDatabase();
db.query(
`CREATE VIRTUAL TABLE bt1 USING fts5(y, tokenize='better_trigram');`
).run();
db.query(`CREATE VIRTUAL TABLE t1 USING fts5(y, tokenize='trigram');`).run();
const btQuery = db.query(`INSERT INTO bt1 VALUES( ? );`);
const tQuery = db.query(`INSERT INTO t1 VALUES( ? );`);
console.log("Text length:", text.length);
compact(() => {
summary(() => {
bench("better-trigram", () => {
btQuery.run(text);
});
bench("trigram", () => {
tQuery.run(text);
});
});
});
await run();