change: Updated benchmarks to only use reads

This commit is contained in:
Nicholas Novak 2023-12-05 14:42:57 -08:00
parent a4620b99ce
commit 93c7564c43

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"errors"
"testing" "testing"
"git.nicholasnovak.io/nnovak/spatial-db/storage" "git.nicholasnovak.io/nnovak/spatial-db/storage"
@ -13,17 +14,20 @@ func init() {
server.SetStorageRoot("skygrid-save") server.SetStorageRoot("skygrid-save")
} }
// insertPointTemplate inserts a configurable variety of points into the server func readBlockTemplate(rootDir string, b *testing.B, pointSpread int) {
func insertPointTemplate(testDir string, b *testing.B, pointSpread int) {
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
pos := world.RandomBlockPosWithRange(float64(pointSpread)) pos := world.RandomBlockPosWithRange(float64(pointSpread))
if err := server.ChangeBlock(pos, world.Generic); err != nil { if _, err := server.ReadBlockAt(pos); err != nil {
if errors.Is(err, storage.ChunkNotFoundError) {
continue
} else {
b.Error(err) b.Error(err)
} }
} }
} }
}
func fetchChunkTemplate(testDir string, b *testing.B) { func fetchChunkTemplate(testDir string, b *testing.B) {
b.ResetTimer() b.ResetTimer()
@ -38,10 +42,10 @@ func fetchChunkTemplate(testDir string, b *testing.B) {
// Insert blocks // Insert blocks
func BenchmarkInsertClusteredPoints(b *testing.B) { func BenchmarkReadClusteredPoints(b *testing.B) {
insertPointTemplate("imperial-test", b, 128) readBlockTemplate("skygrid-test", b, 128)
} }
func BenchmarkInsertSparserPoints(b *testing.B) { func BenchmarkReadSparserPoints(b *testing.B) {
insertPointTemplate("imperial-test", b, 2048) readBlockTemplate("skygrid-test", b, 2048)
} }