Commit 20a6abb
Use newer
The new `slices.Sort` introduced in Go 1.21 [1] is faster than the old
`sort.Slice` approach.
func BenchmarkSort(b *testing.B) {
array := []uint64{0, 42, 10, 8}
b.Run("sort.Slice", func(b *testing.B) {
for i := 0; i < b.N; i++ {
sort.Slice(array, func(i, j int) bool {
return array[i] < array[j]
})
}
})
b.Run("slices.Sort", func(b *testing.B) {
for i := 0; i < b.N; i++ {
slices.Sort(array)
}
})
}
goos: linux
goarch: amd64
pkg: github.com/FastFilter/xorfilter
cpu: AMD Ryzen 7 PRO 4750U with Radeon Graphics
BenchmarkSort/sort.Slice-16 4290086 284.0 ns/op 56 B/op 2 allocs/op
BenchmarkSort/slices.Sort-16 62395050 19.53 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/FastFilter/xorfilter 3.739s
[1]: https://pkg.go.dev/slices#Sort
Signed-off-by: Eng Zer Jun <[email protected]>slices.Sort in pruneDuplicates
1 parent 26c7ccf commit 20a6abb
1 file changed
+2
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
290 | | - | |
291 | | - | |
292 | | - | |
| 290 | + | |
293 | 291 | | |
294 | 292 | | |
295 | 293 | | |
| |||
0 commit comments