2023-11-08 16:24:27 -08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-12-05 14:42:57 -08:00
|
|
|
"errors"
|
2023-12-05 15:27:40 -08:00
|
|
|
"io"
|
2023-11-08 16:24:27 -08:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"git.nicholasnovak.io/nnovak/spatial-db/storage"
|
|
|
|
"git.nicholasnovak.io/nnovak/spatial-db/world"
|
|
|
|
)
|
|
|
|
|
2023-12-05 15:27:40 -08:00
|
|
|
var server storage.InMemoryServer
|
2023-11-08 16:24:27 -08:00
|
|
|
|
2023-11-18 19:47:09 -08:00
|
|
|
func init() {
|
|
|
|
server.SetStorageRoot("skygrid-save")
|
|
|
|
}
|
2023-11-08 16:24:27 -08:00
|
|
|
|
2023-12-05 14:42:57 -08:00
|
|
|
func readBlockTemplate(rootDir string, b *testing.B, pointSpread int) {
|
2023-11-08 16:24:27 -08:00
|
|
|
b.ResetTimer()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
2023-11-13 19:46:22 -08:00
|
|
|
pos := world.RandomBlockPosWithRange(float64(pointSpread))
|
2023-12-05 14:42:57 -08:00
|
|
|
if _, err := server.ReadBlockAt(pos); err != nil {
|
2023-12-05 15:27:40 -08:00
|
|
|
if errors.Is(err, storage.ChunkNotFoundError) || errors.Is(err, io.EOF) {
|
2023-12-05 14:42:57 -08:00
|
|
|
continue
|
|
|
|
} else {
|
|
|
|
b.Error(err)
|
|
|
|
}
|
2023-11-08 16:24:27 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-12 12:33:39 -08:00
|
|
|
|
2023-11-13 16:22:46 -08:00
|
|
|
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
|
|
|
|
|
2023-12-05 14:42:57 -08:00
|
|
|
func BenchmarkReadClusteredPoints(b *testing.B) {
|
|
|
|
readBlockTemplate("skygrid-test", b, 128)
|
2023-11-13 16:22:46 -08:00
|
|
|
}
|
|
|
|
|
2023-12-05 14:42:57 -08:00
|
|
|
func BenchmarkReadSparserPoints(b *testing.B) {
|
|
|
|
readBlockTemplate("skygrid-test", b, 2048)
|
2023-11-13 16:22:46 -08:00
|
|
|
}
|
2023-12-05 15:27:40 -08:00
|
|
|
|
|
|
|
func BenchmarkReadSparserPoints1(b *testing.B) {
|
|
|
|
readBlockTemplate("skygrid-test", b, 65536)
|
|
|
|
}
|