Skip to content

Commit 652c41a

Browse files
committed
add benchmark drainer vs regular append
1 parent 5cc3769 commit 652c41a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

drain_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gopool_test
22

33
import (
4+
"fmt"
45
"testing"
56

67
gopool "github.com/rubengp99/go-pool"
@@ -20,3 +21,21 @@ func TestDrainer(t *testing.T) {
2021
assert.Equal(t, 3, len(results))
2122
})
2223
}
24+
25+
func BenchmarkDrainerVsAppend(b *testing.B) {
26+
b.Run("drainer", func(b *testing.B) {
27+
drainer := gopool.NewDrainer[typeA]()
28+
for i := 0; i < b.N; i++ {
29+
drainer.Send(typeA{value: fmt.Sprint(i)})
30+
}
31+
32+
})
33+
34+
b.Run("slice", func(b *testing.B) {
35+
slice := make([]typeA, 0)
36+
37+
for i := 0; i < b.N; i++ {
38+
slice = append(slice, typeA{value: fmt.Sprint(i)})
39+
}
40+
})
41+
}

0 commit comments

Comments
 (0)