-
Notifications
You must be signed in to change notification settings - Fork 12
/
linearscan_benchmark_test.go
53 lines (50 loc) · 1.18 KB
/
linearscan_benchmark_test.go
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
53
package lshensemble
import (
"log"
"time"
)
func benchmarkLinearscan(rawDomains []rawDomain, queries []rawDomain,
threshold float64, outputFilename string) {
log.Printf("Start Linear Scan with %d queries", len(queries))
results := make(chan queryResult)
go func() {
for _, query := range queries {
start := time.Now()
r := make([]interface{}, 0)
for _, domain := range rawDomains {
c := computeExactContainment(query.values, domain.values)
if c < threshold {
continue
}
r = append(r, domain.key)
}
d := time.Now().Sub(start)
results <- queryResult{
queryKey: query.key,
duration: d,
candidates: r,
}
}
close(results)
}()
outputQueryResults(results, outputFilename)
log.Printf("Finished Linear Scan, output %s", outputFilename)
}
func computeExactContainment(q, d map[string]bool) float64 {
if len(q) == 0 || len(d) == 0 {
return 0.0
}
var smaller, bigger *(map[string]bool)
if len(q) < len(d) {
smaller, bigger = &(q), &(d)
} else {
bigger, smaller = &(q), &(d)
}
intersection := 0
for v := range *smaller {
if _, exist := (*bigger)[v]; exist {
intersection++
}
}
return float64(intersection) / float64(len(q))
}