2023-10-28 21:40:29 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-10-29 01:23:38 -07:00
|
|
|
"fmt"
|
2023-10-28 21:40:29 -07:00
|
|
|
"math/rand"
|
2023-10-29 01:23:38 -07:00
|
|
|
"os"
|
2023-10-28 21:40:29 -07:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.nicholasnovak.io/nnovak/spatial-db/storage"
|
|
|
|
"git.nicholasnovak.io/nnovak/spatial-db/world"
|
|
|
|
)
|
|
|
|
|
2023-10-29 01:23:38 -07:00
|
|
|
func setupStorageDir() string {
|
|
|
|
dir, err := os.MkdirTemp("", "spatial-db-persistence")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Temporary directory is at %s\n", dir)
|
|
|
|
|
|
|
|
storage.ChunkFileDirectory = dir
|
|
|
|
|
|
|
|
return dir
|
|
|
|
}
|
|
|
|
|
2023-10-28 21:40:29 -07:00
|
|
|
func BenchmarkInsertSomePoints(b *testing.B) {
|
|
|
|
var server storage.SimpleServer
|
|
|
|
|
2023-10-29 01:23:38 -07:00
|
|
|
stdDev := 65536
|
|
|
|
|
|
|
|
storage.ChunkFileDirectory = setupStorageDir()
|
|
|
|
defer os.RemoveAll(storage.ChunkFileDirectory)
|
|
|
|
|
2023-10-28 21:40:29 -07:00
|
|
|
points := make([]world.BlockPos, b.N)
|
|
|
|
|
|
|
|
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
points[i] = world.BlockPos{
|
2023-10-29 01:23:38 -07:00
|
|
|
X: int(r.NormFloat64() * float64(stdDev)),
|
|
|
|
Y: uint(r.NormFloat64() * float64(stdDev)),
|
|
|
|
Z: int(r.NormFloat64() * float64(stdDev)),
|
2023-10-28 21:40:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
|
|
|
|
for _, point := range points {
|
|
|
|
if err := server.ChangeBlock(point, world.Generic); err != nil {
|
|
|
|
b.Error(err)
|
|
|
|
}
|
|
|
|
}
|
2023-10-29 01:23:38 -07:00
|
|
|
|
|
|
|
fmt.Println(os.ReadDir(storage.ChunkFileDirectory))
|
2023-10-28 21:40:29 -07:00
|
|
|
}
|