Skip to content

Commit

Permalink
added benchmark function
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscar Franzen committed Mar 16, 2017
1 parent c8df852 commit 5f07239
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions hnsw.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,26 @@ func (h *Hnsw) SearchBrute(q *Point, K int) *distqueue.DistQueueClosestLast {
return resultSet
}

// Benchmark test precision by comparing the results of SearchBrute and Search
func (h *Hnsw) Benchmark(q *Point, ef int, K int) float64 {
result := h.Search(q, ef, K)
groundTruth := h.SearchBrute(q, K)
truth := make([]uint32, 0)
for groundTruth.Len() > 0 {
truth = append(truth, groundTruth.Pop().ID)
}
p := 0
for result.Len() > 0 {
i := result.Pop()
for j := 0; j < K; j++ {
if truth[j] == i.ID {
p++
}
}
}
return float64(p) / float64(K)
}

func (h *Hnsw) Search(q *Point, ef int, K int) *distqueue.DistQueueClosestLast {

h.RLock()
Expand Down

0 comments on commit 5f07239

Please sign in to comment.