-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgorm_cockroach_test.go.txt
89 lines (81 loc) · 1.91 KB
/
gorm_cockroach_test.go.txt
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package gorm_vs_korm
import (
"testing"
"github.com/kokizzu/gotro/S"
"github.com/sourcegraph/conc/pool"
"github.com/zeebo/assert"
"gorm.io/gorm"
)
var gormCockroach *gorm.DB
func BenchmarkInsertS_Cockroach_Gorm(b *testing.B) {
if done() {
b.SkipNow()
return
}
defer timing()()
err := gormCockroach.Exec(`TRUNCATE TABLE ` + gormTestTableName).Error
assert.Nil(b, err)
b.N = total
p := pool.New().WithMaxGoroutines(cores)
for z := uint64(1); z <= total; z++ {
z := z
p.Go(func() {
err := gormCockroach.Create(&GormTestTable{
ID: z,
Content: S.EncodeCB63(z, 0),
}).Error
assert.Nil(b, err)
})
}
p.Wait()
}
func BenchmarkGetAllS_Cockroach_Gorm(b *testing.B) {
p := pool.New().WithMaxGoroutines(cores)
for i := uint64(1); i <= uint64(b.N); i++ {
p.Go(func() {
a := []GormTestTable{}
err := gormCockroach.Limit(limit).Find(&a).Error
assert.Nil(b, err)
})
}
p.Wait()
}
func BenchmarkGetAllM_Cockroach_Gorm(b *testing.B) {
a := []map[string]any{}
p := pool.New().WithMaxGoroutines(cores)
for i := uint64(1); i <= uint64(b.N); i++ {
p.Go(func() {
err := gormCockroach.Limit(limit).Find(&GormTestTable{}).Scan(&a).Error
assert.Nil(b, err)
})
}
p.Wait()
}
func BenchmarkGetRowS_Cockroach_Gorm(b *testing.B) {
p := pool.New().WithMaxGoroutines(cores)
for i := uint64(1); i <= uint64(b.N); i++ {
i := i
p.Go(func() {
u := GormTestTable{}
err := gormCockroach.Where(&GormTestTable{
Content: S.EncodeCB63(1+uint64(i)%total, 0),
}).First(&u).Error
assert.Nil(b, err)
})
}
p.Wait()
}
func BenchmarkGetRowM_Cockroach_Gorm(b *testing.B) {
p := pool.New().WithMaxGoroutines(cores)
for i := uint64(1); i <= uint64(b.N); i++ {
i := i
p.Go(func() {
u := map[string]any{}
err := gormCockroach.Model(&GormTestTable{}).Where(&GormTestTable{
Content: S.EncodeCB63(1+uint64(i)%total, 0),
}).First(&u).Error
assert.Nil(b, err)
})
}
p.Wait()
}