Mike Reed | cf7258a | 2018-08-15 14:04:01 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 Google Inc. |
| 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "bench/Benchmark.h" |
| 9 | #include "include/core/SkCubicMap.h" |
Mike Reed | cf7258a | 2018-08-15 14:04:01 -0400 | [diff] [blame] | 10 | |
| 11 | class CubicMapBench : public Benchmark { |
| 12 | public: |
| 13 | CubicMapBench(SkPoint p1, SkPoint p2) : fCMap(p1, p2) { |
| 14 | fName.printf("cubicmap_%g_%g_%g_%g", p1.fX, p1.fY, p2.fX, p2.fY); |
| 15 | } |
| 16 | |
| 17 | bool isSuitableFor(Backend backend) override { |
| 18 | return backend == kNonRendering_Backend; |
| 19 | } |
| 20 | |
| 21 | const char* onGetName() override { |
| 22 | return fName.c_str(); |
| 23 | } |
| 24 | |
| 25 | void onDraw(int loops, SkCanvas*) override { |
Mike Reed | 21ba586 | 2019-07-09 10:13:39 -0400 | [diff] [blame] | 26 | for (int outer = 0; outer < 100; ++outer) { |
| 27 | for (int i = 0; i < loops; ++i) { |
| 28 | for (SkScalar x = 0; x <= 1; x += 1.0f / 512) { |
| 29 | fCMap.computeYFromX(x); |
| 30 | } |
Mike Reed | cf7258a | 2018-08-15 14:04:01 -0400 | [diff] [blame] | 31 | } |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | private: |
| 36 | SkCubicMap fCMap; |
| 37 | SkString fName; |
| 38 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 39 | using INHERITED = Benchmark; |
Mike Reed | cf7258a | 2018-08-15 14:04:01 -0400 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | DEF_BENCH( return new CubicMapBench({1, 0}, {0,0}); ) |
| 43 | DEF_BENCH( return new CubicMapBench({1, 0}, {0,1}); ) |
| 44 | DEF_BENCH( return new CubicMapBench({1, 0}, {1,0}); ) |
| 45 | DEF_BENCH( return new CubicMapBench({1, 0}, {1,1}); ) |
| 46 | |
| 47 | DEF_BENCH( return new CubicMapBench({0, 1}, {0,0}); ) |
| 48 | DEF_BENCH( return new CubicMapBench({0, 1}, {0,1}); ) |
| 49 | DEF_BENCH( return new CubicMapBench({0, 1}, {1,0}); ) |
| 50 | DEF_BENCH( return new CubicMapBench({0, 1}, {1,1}); ) |
| 51 | |
| 52 | DEF_BENCH( return new CubicMapBench({0, 0}, {1,1}); ) |
| 53 | DEF_BENCH( return new CubicMapBench({1, 1}, {0,0}); ) |