2023-07-08 20:10:02 +00:00
|
|
|
package ocean_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"git.akyoto.dev/go/assert"
|
|
|
|
"git.akyoto.dev/go/ocean"
|
|
|
|
)
|
|
|
|
|
|
|
|
func BenchmarkGet(b *testing.B) {
|
2023-07-10 14:27:41 +00:00
|
|
|
users, err := ocean.New[User]("test", nil)
|
2023-07-08 20:10:02 +00:00
|
|
|
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() {
|
2023-07-10 14:27:41 +00:00
|
|
|
_, _ = users.Get("1")
|
2023-07-08 20:10:02 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
b.StopTimer()
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkSet(b *testing.B) {
|
2023-07-10 14:27:41 +00:00
|
|
|
users, err := ocean.New[User]("test", nil)
|
2023-07-08 20:10:02 +00:00
|
|
|
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) {
|
2023-07-10 14:27:41 +00:00
|
|
|
users, err := ocean.New[User]("test", nil)
|
2023-07-08 20:10:02 +00:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2023-07-10 14:27:41 +00:00
|
|
|
func BenchmarkNew(b *testing.B) {
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
for pb.Next() {
|
2023-07-12 08:58:20 +00:00
|
|
|
_, _ = ocean.New[User]("test", nil)
|
2023-07-08 20:10:02 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|