Skip to content

Commit

Permalink
locking AFTER expensive computation 🤦‍♀️ 1.65 times faster
Browse files Browse the repository at this point in the history
  • Loading branch information
shilangyu committed Jul 25, 2020
1 parent af09384 commit f401f5c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ Behaves just like `scoop search` and returns [<sub>almost</sub>](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_
24 changes: 23 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit f401f5c

Please sign in to comment.