From f401f5cf5bc0255287dd109fc645e1f3a6918fd2 Mon Sep 17 00:00:00 2001 From: shilangyu Date: Sat, 25 Jul 2020 21:42:18 +0200 Subject: [PATCH] =?UTF-8?q?locking=20AFTER=20expensive=20computation=20?= =?UTF-8?q?=F0=9F=A4=A6=E2=80=8D=E2=99=80=EF=B8=8F=201.65=20times=20faster?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 ++++++------ main.go | 24 +++++++++++++++++++++++- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index dc03dc3..f91a59f 100644 --- a/README.md +++ b/README.md @@ -33,21 +33,21 @@ Behaves just like `scoop search` and returns [almost](https://github. ## Benchmarks -Done with [hyperfine](https://github.com/sharkdp/hyperfine). `scoop-search` is on average 30 times faster. +Done with [hyperfine](https://github.com/sharkdp/hyperfine). `scoop-search` is on average 50 times faster. ```sh ❯ hyperfine --warmup 1 'scoop-search google' 'scoop search google' Benchmark #1: scoop-search google - Time (mean ± σ): 124.9 ms ± 2.2 ms [User: 2.6 ms, System: 2.8 ms] - Range (min … max): 122.8 ms … 131.4 ms 23 runs + Time (mean ± σ): 76.1 ms ± 1.9 ms [User: 0.8 ms, System: 5.8 ms] + Range (min … max): 73.4 ms … 82.7 ms 37 runs Benchmark #2: scoop search google - Time (mean ± σ): 3.862 s ± 0.006 s [User: 7.4 ms, System: 5.2 ms] - Range (min … max): 3.852 s … 3.873 s 10 runs + Time (mean ± σ): 3.910 s ± 0.015 s [User: 1.4 ms, System: 7.9 ms] + Range (min … max): 3.888 s … 3.928 s 10 runs Summary 'scoop-search google' ran - 30.93 ± 0.55 times faster than 'scoop search google' + 51.37 ± 1.31 times faster than 'scoop search google' ``` _ran on AMD Ryzen 5 3600 @ 3.6GHz_ diff --git a/main.go b/main.go index 0fb6602..979ade8 100644 --- a/main.go +++ b/main.go @@ -48,8 +48,9 @@ func main() { for _, bucket := range buckets { wg.Add(1) go func(file os.FileInfo) { + res := matchingManifests(bucketsPath+"\\"+file.Name()+"\\bucket", args.query) matches.Lock() - matches.data[file.Name()] = matchingManifests(bucketsPath+"\\"+file.Name()+"\\bucket", args.query) + matches.data[file.Name()] = res matches.Unlock() wg.Done() }(bucket) @@ -133,6 +134,27 @@ func matchingManifests(path string, term string) (res []match) { return strings.ToLower(res[i].name) < strings.ToLower(res[j].name) }) + // sort.SliceStable(res, func(i, j int) bool { + // s1, _ := strings.ToLower(res[i].name), len(res[i].name) + // s2, l2 := strings.ToLower(res[j].name), len(res[j].name) + + // for k := range res[i].name { + // if k == l2 { + // return true + // } + // if s1[k] == '-' && s2[k] != '-' { + // return true + // } + // if s2[k] == '-' && s1[k] != '-' { + // return false + // } + // if s1[k] != s2[k] { + // return s1[k] < s2[k] + // } + // } + // return true + // }) + return }