-
Notifications
You must be signed in to change notification settings - Fork 8
/
edit_entity_field_benchmark_test.go
67 lines (55 loc) · 1.54 KB
/
edit_entity_field_benchmark_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package beeorm
import (
"testing"
"github.com/stretchr/testify/assert"
)
type editByFieldAsyncBenchmarkEntity struct {
ID uint64 `orm:"localCache"`
Age int
}
// BenchmarkEditByFieldAsync-10 2966167 406.7 ns/op 536 B/op 9 allocs/op
func BenchmarkEditByFieldAsync(b *testing.B) {
var entity *editByFieldAsyncBenchmarkEntity
orm := PrepareTables(nil, NewRegistry(), entity)
entity = NewEntity[editByFieldAsyncBenchmarkEntity](orm)
entity.Age = 0
assert.NoError(b, orm.Flush())
GetByID[editByFieldAsyncBenchmarkEntity](orm, entity.ID)
field := "Age"
schema := getEntitySchema[editByFieldAsyncBenchmarkEntity](orm)
go func() {
for {
e := schema.asyncTemporaryQueue.Dequeue()
if e == nil {
return
}
}
}()
b.ResetTimer()
b.ReportAllocs()
for n := 0; n < b.N; n++ {
_ = EditEntityField(orm, entity, field, n)
_ = orm.FlushAsync()
}
publishAsyncEvent(schema, nil)
}
// BenchmarkEditByFieldAsyncWithRedis-10 908324 1304 ns/op 688 B/op 13 allocs/op
func BenchmarkEditByFieldAsyncWithRedis(b *testing.B) {
var entity *editByFieldAsyncBenchmarkEntity
orm := PrepareTables(nil, NewRegistry(), entity)
entity = NewEntity[editByFieldAsyncBenchmarkEntity](orm)
entity.Age = 0
assert.NoError(b, orm.Flush())
GetByID[editByFieldAsyncBenchmarkEntity](orm, entity.ID)
field := "Age"
stop := ConsumeAsyncBuffer(orm, func(err error) {
panic(err)
})
b.ResetTimer()
b.ReportAllocs()
for n := 0; n < b.N; n++ {
_ = EditEntityField(orm, entity, field, n)
_ = orm.FlushAsync()
}
stop()
}