From a9f5a5105c30dc54a1e41d7d56b160b013087192 Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Wed, 31 Jul 2019 13:32:09 +0200 Subject: [PATCH] more benchmarks --- mapblockrenderer/renderer_benchmark_test.go | 75 ++++++++++++++++-- testutils/mapblockaccessor.go | 8 ++ tilerenderer/renderer_benchmark_test.go | 85 +++++++++++++++++++++ 3 files changed, 163 insertions(+), 5 deletions(-) create mode 100644 testutils/mapblockaccessor.go create mode 100644 tilerenderer/renderer_benchmark_test.go diff --git a/mapblockrenderer/renderer_benchmark_test.go b/mapblockrenderer/renderer_benchmark_test.go index f124c39..3678fff 100644 --- a/mapblockrenderer/renderer_benchmark_test.go +++ b/mapblockrenderer/renderer_benchmark_test.go @@ -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) + } + } +} + diff --git a/testutils/mapblockaccessor.go b/testutils/mapblockaccessor.go new file mode 100644 index 0000000..786f4bd --- /dev/null +++ b/testutils/mapblockaccessor.go @@ -0,0 +1,8 @@ +package testutils + +import ( +) + +func CreateMapBlockAccessor() { +} + diff --git a/tilerenderer/renderer_benchmark_test.go b/tilerenderer/renderer_benchmark_test.go new file mode 100644 index 0000000..6670f95 --- /dev/null +++ b/tilerenderer/renderer_benchmark_test.go @@ -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") + } + } + +}