1
0
forked from MTSR/mapserver

more benchmarks

This commit is contained in:
NatureFreshMilk 2019-07-31 13:32:09 +02:00
parent 0de8ce1791
commit a9f5a5105c
3 changed files with 163 additions and 5 deletions

View File

@ -14,14 +14,19 @@ import (
"github.com/sirupsen/logrus"
)
func BenchmarkRender(b *testing.B) {
logrus.SetLevel(logrus.ErrorLevel)
type callback func()
func createRenderer(b *testing.B) (*MapBlockRenderer, callback) {
logrus.SetLevel(logrus.PanicLevel)
tmpfile, err := ioutil.TempFile("", "TestMigrate.*.sqlite")
if err != nil {
panic(err)
}
defer os.Remove(tmpfile.Name())
cleanup := func() {
os.Remove(tmpfile.Name())
}
testutils.CreateTestDatabase(tmpfile.Name())
a, err := sqlite.New(tmpfile.Name())
@ -42,9 +47,51 @@ func BenchmarkRender(b *testing.B) {
}
r := NewMapBlockRenderer(cache, c)
os.Mkdir("../test-output", 0755)
b.ResetTimer()
return r, cleanup
}
func BenchmarkRenderEmptySingle(b *testing.B) {
r, cleanup := createRenderer(b)
defer cleanup()
for n := 0; n < b.N; n++ {
pos1 := coords.NewMapBlockCoords(10, 0, 10)
pos2 := coords.NewMapBlockCoords(10, 0, 10)
_, 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++ {
pos1 := coords.NewMapBlockCoords(0, 0, 0)
pos2 := coords.NewMapBlockCoords(0, 0, 0)
_, err := r.Render(pos1, pos2)
if err != nil {
panic(err)
}
}
}
func BenchmarkRenderStride(b *testing.B) {
r, cleanup := createRenderer(b)
defer cleanup()
for n := 0; n < b.N; n++ {
pos1 := coords.NewMapBlockCoords(0, 10, 0)
@ -58,3 +105,21 @@ func BenchmarkRender(b *testing.B) {
}
}
func BenchmarkRenderBigStride(b *testing.B) {
r, cleanup := createRenderer(b)
defer cleanup()
for n := 0; n < b.N; n++ {
pos1 := coords.NewMapBlockCoords(0, 1000, 0)
pos2 := coords.NewMapBlockCoords(0, -1000, 0)
_, err := r.Render(pos1, pos2)
if err != nil {
panic(err)
}
}
}

View File

@ -0,0 +1,8 @@
package testutils
import (
)
func CreateMapBlockAccessor() {
}

View File

@ -0,0 +1,85 @@
package tilerenderer
import (
"io/ioutil"
"mapserver/colormapping"
"mapserver/coords"
"mapserver/db/sqlite"
"mapserver/layer"
"mapserver/mapblockaccessor"
"mapserver/mapblockrenderer"
"mapserver/testutils"
"mapserver/tiledb"
"os"
"testing"
"time"
"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()
_, err = c.LoadVFSColors(false, "/colors/vanessa.txt")
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)
layers := []*layer.Layer{
&layer.Layer{
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++ {
data, err := tr.Render(coord)
if err != nil {
panic(err)
}
if data == nil {
panic("no data")
}
}
}