From cdd75e573e082524eb19013cc66f28b96b0f0cc0 Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Wed, 31 Jul 2019 12:00:27 +0200 Subject: [PATCH] add benchmark --- mapblockrenderer/renderer_benchmark_test.go | 97 +++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 mapblockrenderer/renderer_benchmark_test.go diff --git a/mapblockrenderer/renderer_benchmark_test.go b/mapblockrenderer/renderer_benchmark_test.go new file mode 100644 index 0000000..edd183d --- /dev/null +++ b/mapblockrenderer/renderer_benchmark_test.go @@ -0,0 +1,97 @@ +package mapblockrenderer + +import ( + "fmt" + "io/ioutil" + "mapserver/colormapping" + "mapserver/coords" + "mapserver/db/sqlite" + "mapserver/layer" + "mapserver/mapblockaccessor" + "mapserver/testutils" + "os" + "testing" + "time" + + "github.com/sirupsen/logrus" +) + +func BenchmarkRender(b *testing.B) { + logrus.SetLevel(logrus.ErrorLevel) + + layers := []*layer.Layer{ + &layer.Layer{ + Id: 0, + Name: "Base", + From: -16, + To: 160, + }, + } + + tmpfile, err := ioutil.TempFile("", "TestMigrate.*.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 := NewMapBlockRenderer(cache, c) + os.Mkdir("../test-output", 0755) + + b.ResetTimer() + for n := 0; n < b.N; n++ { + + results := make(chan JobResult, 100) + jobs := make(chan JobData, 100) + + go Worker(r, jobs, results) + + go func() { + for result := range results { + if result.Data.Len() == 0 { + continue + } + + tc := coords.GetTileCoordsFromMapBlock(result.Job.Pos1, layers) + f, _ := os.Create(fmt.Sprintf("../test-output/image_%d_%d.png", tc.X, tc.Y)) + result.Data.WriteTo(f) + f.Close() + } + }() + + from := 0 + to := 0 + + for x := from; x < to; x++ { + for z := from; z < to; z++ { + pos1 := coords.NewMapBlockCoords(x, 10, z) + pos2 := coords.NewMapBlockCoords(x, -1, z) + + jobs <- JobData{Pos1: pos1, Pos2: pos2} + } + } + + close(jobs) + } +} + +//func BenchmarkRender1(b *testing.B) { benchmarkRender(1, b) } +//func BenchmarkRender2(b *testing.B) { benchmarkRender(2, b) } +//func BenchmarkRender4(b *testing.B) { benchmarkRender(4, b) }