2023-11-08 16:24:27 -08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"git.nicholasnovak.io/nnovak/spatial-db/storage"
|
|
|
|
"git.nicholasnovak.io/nnovak/spatial-db/world"
|
|
|
|
)
|
|
|
|
|
2023-11-12 12:33:39 -08:00
|
|
|
var (
|
|
|
|
emptyDir = "./empty"
|
|
|
|
smallSparseDir = "./small-sparse"
|
|
|
|
medSparseDir = "./med-sparse"
|
|
|
|
largeSparseDir = "./lg-sparse"
|
|
|
|
smallDenseDir = "./small-dense"
|
|
|
|
medDenseDir = "./med-dense"
|
|
|
|
largeDenseDir = "./lg-dense"
|
|
|
|
)
|
|
|
|
|
2023-11-13 16:22:46 -08:00
|
|
|
// Point densities
|
2023-11-12 12:33:39 -08:00
|
|
|
const (
|
|
|
|
sparse = 1_000
|
|
|
|
dense = 10_000
|
|
|
|
)
|
|
|
|
|
|
|
|
var pointCounts = []int{200, 1_000, 2_500}
|
|
|
|
|
|
|
|
var dirs = []string{emptyDir, smallSparseDir, medSparseDir, largeSparseDir,
|
|
|
|
smallDenseDir, medDenseDir, largeDenseDir}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
for index, dir := range dirs {
|
|
|
|
if index > 2 {
|
|
|
|
populateStorageDir(dir, sparse, pointCounts[index%3], false)
|
|
|
|
} else {
|
|
|
|
populateStorageDir(dir, dense, pointCounts[index%3], false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-13 16:22:46 -08:00
|
|
|
// insertPointTemplate inserts a configurable variety of points into the server
|
2023-11-12 12:33:39 -08:00
|
|
|
func insertPointTemplate(testDir string, b *testing.B) {
|
2023-11-08 16:24:27 -08:00
|
|
|
var server storage.SimpleServer
|
|
|
|
|
2023-11-13 16:22:46 -08:00
|
|
|
server.SetStorageRoot(testDir)
|
2023-11-08 16:24:27 -08:00
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
pos := world.RandomBlockPosWithRange(2048)
|
|
|
|
if err := server.ChangeBlock(pos, world.Generic); err != nil {
|
|
|
|
b.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-12 12:33:39 -08:00
|
|
|
|
2023-11-13 16:22:46 -08:00
|
|
|
func fetchChunkTemplate(testDir string, b *testing.B) {
|
|
|
|
var server storage.SimpleServer
|
|
|
|
|
|
|
|
server.SetStorageRoot(testDir)
|
|
|
|
|
|
|
|
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 BenchmarkInsertSmallSparse(b *testing.B) {
|
2023-11-12 12:33:39 -08:00
|
|
|
insertPointTemplate(smallSparseDir, b)
|
|
|
|
}
|
|
|
|
|
2023-11-13 16:22:46 -08:00
|
|
|
func BenchmarkInsertMedSparse(b *testing.B) {
|
2023-11-12 12:33:39 -08:00
|
|
|
insertPointTemplate(medSparseDir, b)
|
|
|
|
}
|
|
|
|
|
2023-11-13 16:22:46 -08:00
|
|
|
func BenchmarkInsertLgSparse(b *testing.B) {
|
2023-11-12 12:33:39 -08:00
|
|
|
insertPointTemplate(largeSparseDir, b)
|
|
|
|
}
|
|
|
|
|
2023-11-13 16:22:46 -08:00
|
|
|
func BenchmarkInsertSmallDense(b *testing.B) {
|
2023-11-12 12:33:39 -08:00
|
|
|
insertPointTemplate(smallDenseDir, b)
|
|
|
|
}
|
|
|
|
|
2023-11-13 16:22:46 -08:00
|
|
|
func BenchmarkInsertMedDense(b *testing.B) {
|
2023-11-12 12:33:39 -08:00
|
|
|
insertPointTemplate(medDenseDir, b)
|
|
|
|
}
|
|
|
|
|
2023-11-13 16:22:46 -08:00
|
|
|
func BenchmarkInsertLgDense(b *testing.B) {
|
2023-11-12 12:33:39 -08:00
|
|
|
insertPointTemplate(largeDenseDir, b)
|
|
|
|
}
|
2023-11-13 16:22:46 -08:00
|
|
|
|
|
|
|
// Fetch chunks
|
|
|
|
|
|
|
|
func BenchmarkFetchChunkSmallSparse(b *testing.B) {
|
|
|
|
fetchChunkTemplate(smallSparseDir, b)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkFetchChunkMedSparse(b *testing.B) {
|
|
|
|
fetchChunkTemplate(medSparseDir, b)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkFetchChunkLgSparse(b *testing.B) {
|
|
|
|
fetchChunkTemplate(largeSparseDir, b)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkFetchChunkSmallDense(b *testing.B) {
|
|
|
|
fetchChunkTemplate(smallDenseDir, b)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkFetchChunkMedDense(b *testing.B) {
|
|
|
|
fetchChunkTemplate(medDenseDir, b)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkFetchChunkLgDense(b *testing.B) {
|
|
|
|
fetchChunkTemplate(largeDenseDir, b)
|
|
|
|
}
|