2019-07-31 13:00:27 +03:00
|
|
|
package mapblockrenderer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"mapserver/db/sqlite"
|
|
|
|
"mapserver/mapblockaccessor"
|
|
|
|
"mapserver/testutils"
|
2023-12-29 18:00:11 +03:00
|
|
|
"mapserver/types"
|
2019-07-31 13:00:27 +03:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2023-01-20 19:44:59 +03:00
|
|
|
"github.com/minetest-go/colormapping"
|
|
|
|
|
2019-07-31 13:00:27 +03:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2019-07-31 14:32:09 +03:00
|
|
|
type callback func()
|
|
|
|
|
|
|
|
func createRenderer(b *testing.B) (*MapBlockRenderer, callback) {
|
|
|
|
logrus.SetLevel(logrus.PanicLevel)
|
2019-07-31 13:00:27 +03:00
|
|
|
|
|
|
|
tmpfile, err := ioutil.TempFile("", "TestMigrate.*.sqlite")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2019-07-31 14:32:09 +03:00
|
|
|
cleanup := func() {
|
|
|
|
os.Remove(tmpfile.Name())
|
|
|
|
}
|
|
|
|
|
2019-07-31 13:00:27 +03:00
|
|
|
testutils.CreateTestDatabase(tmpfile.Name())
|
|
|
|
|
|
|
|
a, err := sqlite.New(tmpfile.Name())
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = a.Migrate()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cache := mapblockaccessor.NewMapBlockAccessor(a, 500*time.Millisecond, 1000*time.Millisecond, 1000)
|
|
|
|
c := colormapping.NewColorMapping()
|
2023-01-20 20:02:37 +03:00
|
|
|
err = c.LoadDefaults()
|
2019-07-31 13:00:27 +03:00
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
r := NewMapBlockRenderer(cache, c)
|
|
|
|
b.ResetTimer()
|
2019-07-31 14:32:09 +03:00
|
|
|
|
|
|
|
return r, cleanup
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkRenderEmptySingle(b *testing.B) {
|
|
|
|
r, cleanup := createRenderer(b)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
for n := 0; n < b.N; n++ {
|
|
|
|
|
2023-12-29 18:00:11 +03:00
|
|
|
pos1 := types.NewMapBlockCoords(10, 0, 10)
|
|
|
|
pos2 := types.NewMapBlockCoords(10, 0, 10)
|
2019-07-31 14:32:09 +03:00
|
|
|
|
|
|
|
_, err := r.Render(pos1, pos2)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkRenderSingle(b *testing.B) {
|
|
|
|
r, cleanup := createRenderer(b)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
for n := 0; n < b.N; n++ {
|
|
|
|
|
2023-12-29 18:00:11 +03:00
|
|
|
pos1 := types.NewMapBlockCoords(0, 0, 0)
|
|
|
|
pos2 := types.NewMapBlockCoords(0, 0, 0)
|
2019-07-31 14:32:09 +03:00
|
|
|
|
|
|
|
_, err := r.Render(pos1, pos2)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkRenderStride(b *testing.B) {
|
|
|
|
r, cleanup := createRenderer(b)
|
|
|
|
defer cleanup()
|
|
|
|
|
2019-07-31 13:00:27 +03:00
|
|
|
for n := 0; n < b.N; n++ {
|
|
|
|
|
2023-12-29 18:00:11 +03:00
|
|
|
pos1 := types.NewMapBlockCoords(0, 10, 0)
|
|
|
|
pos2 := types.NewMapBlockCoords(0, -1, 0)
|
2019-07-31 13:00:27 +03:00
|
|
|
|
2019-07-31 13:55:08 +03:00
|
|
|
_, err := r.Render(pos1, pos2)
|
2019-07-31 13:00:27 +03:00
|
|
|
|
2019-07-31 13:55:08 +03:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
2019-07-31 13:00:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-31 14:32:09 +03:00
|
|
|
func BenchmarkRenderBigStride(b *testing.B) {
|
|
|
|
r, cleanup := createRenderer(b)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
for n := 0; n < b.N; n++ {
|
|
|
|
|
2023-12-29 18:00:11 +03:00
|
|
|
pos1 := types.NewMapBlockCoords(0, 1000, 0)
|
|
|
|
pos2 := types.NewMapBlockCoords(0, -1000, 0)
|
2019-07-31 14:32:09 +03:00
|
|
|
|
|
|
|
_, err := r.Render(pos1, pos2)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|