-
Notifications
You must be signed in to change notification settings - Fork 0
/
batch_bench_test.go
51 lines (39 loc) · 1008 Bytes
/
batch_bench_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// (c) 2022 Jacek Olszak
// This code is licensed under MIT license (see LICENSE for details)
package batch_test
import (
"context"
"strconv"
"sync"
"testing"
"github.com/elgopher/batch"
"github.com/stretchr/testify/require"
)
func BenchmarkProcessor_Run(b *testing.B) {
resources := []int{
1, 8, 64, 512, 4096, 32768, 262144, 2097152,
}
for _, resourceCount := range resources {
b.Run(strconv.Itoa(resourceCount), func(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
processor := batch.StartProcessor(batch.Options[empty]{})
defer processor.Stop()
var allOperationsFinished sync.WaitGroup
allOperationsFinished.Add(b.N)
b.ResetTimer()
for i := 0; i < b.N; i++ {
key := strconv.Itoa(i % resourceCount)
go func() {
// when
err := processor.Run(context.Background(), key, operation)
require.NoError(b, err)
allOperationsFinished.Done()
}()
}
b.StopTimer()
allOperationsFinished.Wait()
})
}
}
func operation(empty) {}