chore[test]: add bench for scan slice

This commit is contained in:
Melbex De Leon 2022-05-30 22:53:47 +08:00
parent 153d0b76b2
commit 751467c1df
No known key found for this signature in database
GPG Key ID: 9A664266F44E5B74

View File

@ -1,6 +1,7 @@
package tests_test
import (
"fmt"
"testing"
. "gorm.io/gorm/utils/tests"
@ -25,7 +26,7 @@ func BenchmarkFind(b *testing.B) {
}
func BenchmarkScan(b *testing.B) {
user := *GetUser("find", Config{})
user := *GetUser("scan", Config{})
DB.Create(&user)
var u User
@ -34,6 +35,18 @@ func BenchmarkScan(b *testing.B) {
}
}
func BenchmarkScanSlice(b *testing.B) {
for i := 0; i < 10_000; i++ {
user := *GetUser(fmt.Sprintf("scan-%d", i), Config{})
DB.Create(&user)
}
var u []User
for x := 0; x < b.N; x++ {
DB.Raw("select * from users").Scan(&u)
}
}
func BenchmarkUpdate(b *testing.B) {
user := *GetUser("find", Config{})
DB.Create(&user)