52 lines
1020 B
Go
52 lines
1020 B
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"git.nicholasnovak.io/nnovak/spatial-db/storage"
|
|
"git.nicholasnovak.io/nnovak/spatial-db/world"
|
|
)
|
|
|
|
var server storage.SimpleServer
|
|
|
|
func init() {
|
|
server.SetStorageRoot("skygrid-save")
|
|
}
|
|
|
|
func readBlockTemplate(rootDir string, b *testing.B, pointSpread int) {
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
pos := world.RandomBlockPosWithRange(float64(pointSpread))
|
|
if _, err := server.ReadBlockAt(pos); err != nil {
|
|
if errors.Is(err, storage.ChunkNotFoundError) {
|
|
continue
|
|
} else {
|
|
b.Error(err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func fetchChunkTemplate(testDir string, b *testing.B) {
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
pos := world.RandomBlockPosWithRange(2048).ToChunkPos()
|
|
if _, err := server.ReadChunkAt(pos); err != nil {
|
|
b.Error(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Insert blocks
|
|
|
|
func BenchmarkReadClusteredPoints(b *testing.B) {
|
|
readBlockTemplate("skygrid-test", b, 128)
|
|
}
|
|
|
|
func BenchmarkReadSparserPoints(b *testing.B) {
|
|
readBlockTemplate("skygrid-test", b, 2048)
|
|
}
|