-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_by_ids_benchmarks_test.go
45 lines (39 loc) · 1.13 KB
/
get_by_ids_benchmarks_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
package orm
import (
"testing"
"github.com/stretchr/testify/assert"
)
// BenchmarkGetByIDsLocalCache-10 1000000 1135 ns/op 80 B/op 1 allocs/op
func BenchmarkGetByIDsLocalCache(b *testing.B) {
benchmarkGetByIDsCache(b, true, false)
}
// BenchmarkGetByIDsRedisCache-10 301 5092551 ns/op 42032 B/op 1118 allocs/op
func BenchmarkGetByIDsRedisCache(b *testing.B) {
benchmarkGetByIDsCache(b, false, true)
}
func benchmarkGetByIDsCache(b *testing.B, local, redis bool) {
entity := &getByIdsEntity{}
registry := NewRegistry()
registry.RegisterLocalCache(DefaultPoolCode, 0)
orm := PrepareTables(nil, registry, entity)
schema := GetEntitySchema[getByIdsEntity](orm)
schema.DisableCache(!local, !redis)
const size = 100
ids := make([]uint64, size)
for i := 0; i < size; i++ {
entity = NewEntity[getByIdsEntity](orm)
entity.Name = "Name"
ids[i] = entity.ID
}
err := orm.Flush()
assert.NoError(b, err)
_ = GetByIDs[getByIdsEntity](orm, ids...)
b.ResetTimer()
b.ReportAllocs()
for n := 0; n < b.N; n++ {
rows := GetByIDs[getByIdsEntity](orm, ids...)
for rows.Next() {
rows.Entity()
}
}
}