Skip to content

Commit

Permalink
Problem: no benchmarks
Browse files Browse the repository at this point in the history
Solution: add a single one

```sh
goos: linux
goarch: amd64
pkg: github.com/gomoni/it
cpu: AMD Ryzen 7 PRO 5850U with Radeon Graphics
BenchmarkRangeFilter
BenchmarkRangeFilter-16              448           2677041 ns/op
BenchmarkRangeFilter-16              435           2665242 ns/op
BenchmarkRangeFilter-16              442           2674867 ns/op
BenchmarkRangeFilter-16              432           2718882 ns/op
BenchmarkRangeFilter-16              408           2732315 ns/op
BenchmarkItFilterSlice
BenchmarkItFilterSlice-16             12          89357678 ns/op
BenchmarkItFilterSlice-16             12          89829099 ns/op
BenchmarkItFilterSlice-16             12          90112402 ns/op
BenchmarkItFilterSlice-16             12          89383558 ns/op
BenchmarkItFilterSlice-16             12          90150032 ns/op
BenchmarkItFilterFor
BenchmarkItFilterFor-16               19          58248848 ns/op
BenchmarkItFilterFor-16               19          58173282 ns/op
BenchmarkItFilterFor-16               18          58722532 ns/op
BenchmarkItFilterFor-16               19          58333300 ns/op
BenchmarkItFilterFor-16               19          58699434 ns/op
PASS
ok      github.com/gomoni/it    19.939s
michal@90michal:~/projects/gomoni/it>
```
  • Loading branch information
vyskocilm committed Feb 27, 2024
1 parent 14b7781 commit 8398220
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package it_test

import (
"testing"

"github.com/gomoni/it"
)

var in1M []int

func init() {
in1M = make([]int, 1024*1024)
for idx := range in1M {
in1M[idx] = idx
}
}

func rangeFilter(in []int, filterFunc it.FilterFunc[int]) []int {
ret := make([]int, 0, len(in))
for _, i := range in {
if filterFunc(i) {
ret = append(ret, i)
}
}
return ret
}

func BenchmarkRangeFilter(b *testing.B) {
for range b.N {
rangeFilter(in1M, func(i int) bool { return i%2 == 0 })
}
}

func BenchmarkItFilterSlice(b *testing.B) {
for range b.N {
seq0 := it.Filter(it.FromSlice(in1M), func(i int) bool { return i%2 == 0 })
it.AsSlice(seq0)
}
}

func BenchmarkItFilterFor(b *testing.B) {
for range b.N {
seq0 := it.Filter(it.FromSlice(in1M), func(i int) bool { return i%2 == 0 })
cnt := 0
for value := range seq0 {
cnt += value
}
}
}

0 comments on commit 8398220

Please sign in to comment.