Skip to content

Commit

Permalink
Merge pull request #80 from Primetalk/feat-bench
Browse files Browse the repository at this point in the history
feat: benchmark stream Sum
  • Loading branch information
Primetalk committed Sep 11, 2022
2 parents c70c212 + 4374f58 commit 9d1d7d1
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions stream/stream_bench_test.go
@@ -0,0 +1,27 @@
package stream_test

import (
"testing"

"github.com/primetalk/goio/io"
"github.com/primetalk/goio/slice"
"github.com/primetalk/goio/stream"
"github.com/stretchr/testify/assert"
)

func BenchmarkStreamSum(b *testing.B) {
sumIO := stream.Head(stream.Sum(stream.Take(nats, 10000)))
res, err1 := io.UnsafeRunSync(sumIO)
assert.NoError(b, err1)
assert.Equal(b, 50005000, res)
}

var range10000 = func() (res []int) {
res, _ = io.UnsafeRunSync(stream.ToSlice(stream.Take(nats, 10000)))
return
}()

func BenchmarkSliceSum(b *testing.B) {
res := slice.Sum(range10000)
assert.Equal(b, 50005000, res)
}

0 comments on commit 9d1d7d1

Please sign in to comment.