2023-10-28 21:40:29 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
2023-10-29 01:23:38 -07:00
|
|
|
"os"
|
2023-10-28 21:40:29 -07:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.nicholasnovak.io/nnovak/spatial-db/storage"
|
|
|
|
"git.nicholasnovak.io/nnovak/spatial-db/world"
|
|
|
|
)
|
|
|
|
|
2023-11-08 16:24:27 -08:00
|
|
|
func populateStorageDir(dir string, maxSpread float64, numPoints int) string {
|
2023-10-28 21:40:29 -07:00
|
|
|
var server storage.SimpleServer
|
|
|
|
|
2023-11-08 16:24:27 -08:00
|
|
|
server.StorageDir = dir
|
|
|
|
defer os.RemoveAll(server.StorageDir)
|
2023-10-29 01:23:38 -07:00
|
|
|
|
2023-11-08 16:24:27 -08:00
|
|
|
points := make([]world.BlockPos, numPoints)
|
2023-10-28 21:40:29 -07:00
|
|
|
|
|
|
|
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
|
|
|
2023-11-08 16:24:27 -08:00
|
|
|
for i := 0; i < numPoints; i++ {
|
2023-10-28 21:40:29 -07:00
|
|
|
points[i] = world.BlockPos{
|
2023-11-08 16:24:27 -08:00
|
|
|
X: int(r.NormFloat64() * maxSpread),
|
|
|
|
Y: uint(r.NormFloat64() * maxSpread),
|
|
|
|
Z: int(r.NormFloat64() * maxSpread),
|
2023-10-28 21:40:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, point := range points {
|
|
|
|
if err := server.ChangeBlock(point, world.Generic); err != nil {
|
2023-11-08 16:24:27 -08:00
|
|
|
panic(err)
|
2023-10-28 21:40:29 -07:00
|
|
|
}
|
|
|
|
}
|
2023-10-29 01:23:38 -07:00
|
|
|
|
2023-11-08 16:24:27 -08:00
|
|
|
return server.StorageDir
|
2023-10-28 21:40:29 -07:00
|
|
|
}
|
2023-11-08 16:24:27 -08:00
|
|
|
|
|
|
|
// func BenchmarkInsertSomePoints(b *testing.B) {
|
|
|
|
// var server storage.SimpleServer
|
|
|
|
//
|
|
|
|
// stdDev := 65536
|
|
|
|
//
|
|
|
|
// storage.ChunkFileDirectory = setupStorageDir()
|
|
|
|
// defer os.RemoveAll(storage.ChunkFileDirectory)
|
|
|
|
//
|
|
|
|
// 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{
|
|
|
|
// X: int(r.NormFloat64() * float64(stdDev)),
|
|
|
|
// Y: uint(r.NormFloat64() * float64(stdDev)),
|
|
|
|
// Z: int(r.NormFloat64() * float64(stdDev)),
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// b.ResetTimer()
|
|
|
|
//
|
|
|
|
// for _, point := range points {
|
|
|
|
// if err := server.ChangeBlock(point, world.Generic); err != nil {
|
|
|
|
// b.Error(err)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// fmt.Println(os.ReadDir(storage.ChunkFileDirectory))
|
|
|
|
// }
|