2020-06-05 16:23:20 +03:00
|
|
|
package tests_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
. "gorm.io/gorm/utils/tests"
|
|
|
|
)
|
|
|
|
|
|
|
|
func BenchmarkCreate(b *testing.B) {
|
2022-01-06 10:02:53 +03:00
|
|
|
user := *GetUser("bench", Config{})
|
2020-06-05 16:23:20 +03:00
|
|
|
|
|
|
|
for x := 0; x < b.N; x++ {
|
|
|
|
user.ID = 0
|
|
|
|
DB.Create(&user)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkFind(b *testing.B) {
|
2022-01-06 10:02:53 +03:00
|
|
|
user := *GetUser("find", Config{})
|
2020-06-05 16:23:20 +03:00
|
|
|
DB.Create(&user)
|
|
|
|
|
|
|
|
for x := 0; x < b.N; x++ {
|
|
|
|
DB.Find(&User{}, "id = ?", user.ID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkUpdate(b *testing.B) {
|
2022-01-06 10:02:53 +03:00
|
|
|
user := *GetUser("find", Config{})
|
2020-06-05 16:23:20 +03:00
|
|
|
DB.Create(&user)
|
|
|
|
|
|
|
|
for x := 0; x < b.N; x++ {
|
|
|
|
DB.Model(&user).Updates(map[string]interface{}{"Age": x})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkDelete(b *testing.B) {
|
2022-01-06 10:02:53 +03:00
|
|
|
user := *GetUser("find", Config{})
|
2020-06-05 16:23:20 +03:00
|
|
|
|
|
|
|
for x := 0; x < b.N; x++ {
|
|
|
|
user.ID = 0
|
|
|
|
DB.Create(&user)
|
|
|
|
DB.Delete(&user)
|
|
|
|
}
|
|
|
|
}
|