2023-07-19 11:52:13 +02:00

78 lines
1.1 KiB
Go

package data_test
import (
"testing"
"git.akyoto.dev/go/assert"
"git.akyoto.dev/go/data"
)
func BenchmarkGet(b *testing.B) {
users, err := data.New[User]("test", nil)
assert.Nil(b, err)
defer users.Sync()
defer users.Clear()
users.Set("1", &User{Name: "User 1"})
b.ReportAllocs()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_, _ = users.Get("1")
}
})
b.StopTimer()
}
func BenchmarkSet(b *testing.B) {
users, err := data.New[User]("test", nil)
assert.Nil(b, err)
defer users.Sync()
defer users.Clear()
user := &User{Name: "User 1"}
b.ReportAllocs()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
users.Set("1", user)
}
})
b.StopTimer()
}
func BenchmarkDelete(b *testing.B) {
users, err := data.New[User]("test", nil)
assert.Nil(b, err)
defer users.Sync()
defer users.Clear()
b.ReportAllocs()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
users.Delete("1")
}
})
b.StopTimer()
}
func BenchmarkNew(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_, _ = data.New[User]("test", nil)
}
})
}