-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache_test.go
44 lines (36 loc) · 865 Bytes
/
cache_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
package main
import (
"fmt"
"math/rand"
"testing"
"time"
"github.com/jmoiron/sqlx"
)
func generateItemIds(size int) []int {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
var tradeableItemIds []int
for i := 0; i < size; i++ {
tradeableItemIds = append(tradeableItemIds, r.Intn(10000))
}
return tradeableItemIds
}
func BenchmarkUpdateTradeableItemsCache(b *testing.B) {
db, err := sqlx.Connect("sqlite3", ":memory:")
if err != nil {
b.Fatal(err)
}
defer db.Close()
// Test performance for different batch sizes
for _, size := range []int{100, 1000, 10000} {
tradeableItemIds := generateItemIds(size)
b.Run(fmt.Sprintf("BatchSize-%d", size), func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
err := updateTradeableItemsCache(db, tradeableItemIds)
if err != nil {
b.Fatal(err)
}
}
})
}
}