-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbenchmark.js
52 lines (45 loc) · 1.91 KB
/
benchmark.js
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
45
46
47
48
49
50
51
52
require("coffeescript/register")
const fs = require("fs")
const path = require("path")
const { start_timer, elapsed_time, doFilterTest } = require("./testutils")
const Zadeh = require("../index")
const legacy = require("fuzzaldrin-plus")
const lines = fs.readFileSync(path.join(__dirname, "data.txt"), "utf8").trim().split("\n")
const forceAllMatch = {
maxInners: -1,
}
const mitigation = {
maxInners: Math.floor(0.2 * lines.length),
}
// warmup + compile
Zadeh.filter(lines, "index", forceAllMatch)
legacy.filter(lines, "index")
doFilterTest("~10% of results are positive, mix exact & fuzzy", lines, "index")
doFilterTest("~10% of results are positive, Fuzzy match", lines, "indx")
doFilterTest("~1% of results are positive, fuzzy", lines, "walkdr")
doFilterTest("~98% of results are positive, mostly Exact match", lines, "node", forceAllMatch)
doFilterTest("~98% of results are positive, Acronym match", lines, "nm")
doFilterTest("~98% of results + Fuzzy match, [Worst case scenario]", lines, "nm", forceAllMatch)
doFilterTest("~98% of results + Fuzzy match, [Mitigation]", lines, "nm", mitigation)
doFilterTest("~98% of results + Fuzzy match, [Worst case but shorter string]", lines, "ndem", forceAllMatch)
const query = "index"
const t1 = start_timer()
const prepared = Zadeh.prepareQuery(query)
for (const line of lines) {
Zadeh.match(line, query, {
preparedQuery: prepared,
})
}
elapsed_time(t1, `Matching ${lines.length} results for 'index' (Prepare in advance)`)
const t2 = start_timer()
for (const line of lines) {
Zadeh.match(line, query)
}
elapsed_time(t2, `Matching ${lines.length} results for 'index' (cache)`)
// replace by 'prepQuery ?= scorer.prepQuery(query)' to test without cache.
const t3 = start_timer()
for (const line of lines) {
legacy.match(line, query)
}
elapsed_time(t3, `Matching ${lines.length} results for 'index' (_legacy_)`)
// replace by `prepQuery ? = scorer.prepQuery(query) to test without cache.