1
0
forked from MTSR/mapserver
mapserver/tilerenderer/renderer_benchmark_test.go

84 lines
1.4 KiB
Go
Raw Normal View History

2019-07-31 14:32:09 +03:00
package tilerenderer
import (
"io/ioutil"
"mapserver/coords"
"mapserver/db/sqlite"
"mapserver/mapblockaccessor"
"mapserver/mapblockrenderer"
"mapserver/testutils"
"mapserver/tiledb"
2023-12-29 18:00:11 +03:00
"mapserver/types"
2019-07-31 14:32:09 +03:00
"os"
"testing"
"time"
2023-01-20 19:44:59 +03:00
"github.com/minetest-go/colormapping"
2019-07-31 14:32:09 +03:00
"github.com/sirupsen/logrus"
)
func BenchmarkTileRender(b *testing.B) {
logrus.SetLevel(logrus.PanicLevel)
tmpfile, err := ioutil.TempFile("", "TestTileRender.*.sqlite")
if err != nil {
panic(err)
}
defer os.Remove(tmpfile.Name())
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 14:32:09 +03:00
if err != nil {
b.Fatal(err)
}
r := mapblockrenderer.NewMapBlockRenderer(cache, c)
tiletmpdir, err := ioutil.TempDir("", "TestTileRenderTiles.*.sqlite")
defer os.RemoveAll(tiletmpdir)
tdb, _ := tiledb.New(tiletmpdir)
2023-12-29 18:00:11 +03:00
layers := []*types.Layer{
2023-10-11 18:35:39 +03:00
{
2019-07-31 14:32:09 +03:00
Id: 0,
Name: "Base",
From: -16,
To: 160,
},
}
tr := NewTileRenderer(r, tdb, a, layers)
if tr == nil {
panic("no renderer")
}
coord := coords.NewTileCoords(0, 0, 12, 0)
b.ResetTimer()
for n := 0; n < b.N; n++ {
2019-10-01 09:13:55 +03:00
err := tr.Render(coord)
2019-07-31 14:32:09 +03:00
if err != nil {
panic(err)
}
}
}