From dc2ce52a6e2b83be1a599602c3536e3f902acf00 Mon Sep 17 00:00:00 2001 From: Ben Boyter Date: Wed, 20 May 2020 17:35:57 +1000 Subject: [PATCH] comments about speed --- string/index.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/string/index.go b/string/index.go index 82a8c36..3e8ac9b 100644 --- a/string/index.go +++ b/string/index.go @@ -143,11 +143,15 @@ func IndexAllIgnoreCaseUnicode(haystack string, needle string, limit int) [][]in } __permuteCacheLock.Unlock() - // TODO - Investigate // This is using IndexAll in a loop which was faster than // any implementation of Aho-Corasick or Boyer-Moore I tried // but in theory Aho-Corasick / Rabin-Karp or even a modified - // version of Boyer-Moore should be faster than this + // version of Boyer-Moore should be faster than this. + // Especially since they should be able to do multiple comparisons + // at the same time. + // However after some investigation it turns out that this turns + // into a fancy vector instruction on AMD64 (which is all we care about) + // and as such its pretty hard to beat. for _, term := range searchTerms { locs = append(locs, IndexAll(haystack, term, limit)...) @@ -173,11 +177,15 @@ func IndexAllIgnoreCaseUnicode(haystack string, needle string, limit int) [][]in } __permuteCacheLock.Unlock() - // TODO - Investigate // This is using IndexAll in a loop which was faster than // any implementation of Aho-Corasick or Boyer-Moore I tried // but in theory Aho-Corasick / Rabin-Karp or even a modified - // version of Boyer-Moore should be faster than this + // version of Boyer-Moore should be faster than this. + // Especially since they should be able to do multiple comparisons + // at the same time. + // However after some investigation it turns out that this turns + // into a fancy vector instruction on AMD64 (which is all we care about) + // and as such its pretty hard to beat. for _, term := range searchTerms { potentialMatches := IndexAll(haystack, term, -1)