change: Updated benchmarks for scaling

This commit is contained in:
Nicholas Novak 2023-11-12 12:33:39 -08:00
parent 1766cd4f48
commit 822bda68d6
2 changed files with 88 additions and 10 deletions

View File

@ -1,19 +1,47 @@
package main
import (
"errors"
"io/fs"
"math/rand"
"os"
"time"
log "github.com/sirupsen/logrus"
"git.nicholasnovak.io/nnovak/spatial-db/storage"
"git.nicholasnovak.io/nnovak/spatial-db/world"
)
func populateStorageDir(dir string, maxSpread float64, numPoints int) string {
func populateStorageDir(
dirName string,
maxSpread float64,
numPoints int,
cleanup bool,
) {
log.Debug("Generating new storage directory")
// Make sure that another directory is not already at that location
if _, err := os.Stat(dirName); err != nil {
if errors.Is(err, fs.ErrNotExist) {
log.Debugf("Making new directory at %s", dirName)
if err := os.Mkdir(dirName, 0755); err != nil {
panic(err)
}
} else {
panic(err)
}
} else {
log.Debug("Directory already exists, skipping generation")
return
}
var server storage.SimpleServer
server.StorageDir = dir
defer os.RemoveAll(server.StorageDir)
server.StorageDir = dirName
if cleanup {
defer os.RemoveAll(server.StorageDir)
}
points := make([]world.BlockPos, numPoints)
@ -32,8 +60,7 @@ func populateStorageDir(dir string, maxSpread float64, numPoints int) string {
panic(err)
}
}
return server.StorageDir
log.Info("Done generating")
}
// func BenchmarkInsertSomePoints(b *testing.B) {

View File

@ -7,16 +7,43 @@ import (
"git.nicholasnovak.io/nnovak/spatial-db/world"
)
func BenchmarkInsertSparsePoints(b *testing.B) {
var (
emptyDir = "./empty"
smallSparseDir = "./small-sparse"
medSparseDir = "./med-sparse"
largeSparseDir = "./lg-sparse"
smallDenseDir = "./small-dense"
medDenseDir = "./med-dense"
largeDenseDir = "./lg-dense"
)
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)
}
}
}
func insertPointTemplate(testDir string, b *testing.B) {
var server storage.SimpleServer
tempDir := "./data"
server.StorageDir = testDir
server.StorageDir = populateStorageDir(tempDir, 2048, 1_000)
b.ResetTimer()
b.Log("Finished generating directory")
for i := 0; i < b.N; i++ {
pos := world.RandomBlockPosWithRange(2048)
if err := server.ChangeBlock(pos, world.Generic); err != nil {
@ -24,3 +51,27 @@ func BenchmarkInsertSparsePoints(b *testing.B) {
}
}
}
func BenchmarkSmallSparse(b *testing.B) {
insertPointTemplate(smallSparseDir, b)
}
func BenchmarkMedSparse(b *testing.B) {
insertPointTemplate(medSparseDir, b)
}
func BenchmarkLgSparse(b *testing.B) {
insertPointTemplate(largeSparseDir, b)
}
func BenchmarkSmallDense(b *testing.B) {
insertPointTemplate(smallDenseDir, b)
}
func BenchmarkMedDense(b *testing.B) {
insertPointTemplate(medDenseDir, b)
}
func BenchmarkLgDense(b *testing.B) {
insertPointTemplate(largeDenseDir, b)
}