Debian Codegraph @

bench/CanvasSaveRestoreBench.cpp

raw
1 /*
2 * Copyright 2021 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "bench/Benchmark.h"
9 #include "include/core/SkCanvas.h"
10
11 class CanvasSaveRestoreBench : public Benchmark {
12 public:
13 CanvasSaveRestoreBench(int depth) : fDepth(depth) {
14 fName.printf("canvas_save_restore_%d", fDepth);
15 }
16
17 protected:
18 const char* onGetName() override { return fName.c_str(); }
19 bool isSuitableFor(Backend backend) override { return backend == Backend::kRaster; }
20 SkISize onGetSize() override { return { 1, 1 }; }
21
22 void onDraw(int loops, SkCanvas* canvas) override {
23 SkM44 m = SkM44::Rotate({0, 0, 1}, 1);
24
25 for (int i = 0; i < loops; ++i) {
26 for (int j = 0; j < fDepth; ++j) {
27 canvas->save();
28 canvas->concat(m);
29 }
30 canvas->drawColor(SkColors::kCyan);
31 for (int j = 0; j < fDepth; ++j) {
32 canvas->restore();
33 }
34 }
35 }
36
37 private:
38 const int fDepth;
39 SkString fName;
40
41 using INHERITED = Benchmark;
42 };
43
44 // Performance remains roughly constant up to 32 (the number of preallocated save records).
45 // After that, the cost of additional malloc/free calls starts to be measurable.
46 DEF_BENCH( return new CanvasSaveRestoreBench(8);)
47 DEF_BENCH( return new CanvasSaveRestoreBench(32);)
48 DEF_BENCH( return new CanvasSaveRestoreBench(128);)
49 DEF_BENCH( return new CanvasSaveRestoreBench(512);)