OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2014 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 |
| 8 #include "Benchmark.h" |
| 9 #include "SkGeometry.h" |
| 10 #include "SkRandom.h" |
| 11 #include "SkRect.h" |
| 12 |
| 13 class GeometryBench : public Benchmark { |
| 14 public: |
| 15 GeometryBench(const char suffix[]) : fVolatileInt(0) { |
| 16 fName.printf("geo_%s", suffix); |
| 17 } |
| 18 |
| 19 virtual const char* onGetName() SK_OVERRIDE { |
| 20 return fName.c_str(); |
| 21 } |
| 22 |
| 23 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { |
| 24 return kNonRendering_Backend == backend; |
| 25 } |
| 26 |
| 27 protected: |
| 28 volatile int fVolatileInt; |
| 29 |
| 30 virtual void virtualCallToFoilOptimizers(int) {} |
| 31 |
| 32 private: |
| 33 SkString fName; |
| 34 }; |
| 35 |
| 36 class GeoRectBench : public GeometryBench { |
| 37 public: |
| 38 GeoRectBench(const char suffix[]) : GeometryBench(suffix) {} |
| 39 |
| 40 protected: |
| 41 SkRect fRects[2048]; |
| 42 |
| 43 virtual void onPreDraw() { |
| 44 const SkScalar min = -100; |
| 45 const SkScalar max = 100; |
| 46 SkRandom rand; |
| 47 for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) { |
| 48 SkScalar x = rand.nextRangeScalar(min, max); |
| 49 SkScalar y = rand.nextRangeScalar(min, max); |
| 50 SkScalar w = rand.nextRangeScalar(min, max); |
| 51 SkScalar h = rand.nextRangeScalar(min, max); |
| 52 fRects[i].setXYWH(x, y, w, h); |
| 53 } |
| 54 } |
| 55 }; |
| 56 |
| 57 class GeoRectBench_intersect : public GeoRectBench { |
| 58 public: |
| 59 GeoRectBench_intersect() : GeoRectBench("rect_intersect") {} |
| 60 |
| 61 protected: |
| 62 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 63 for (int outer = 0; outer < loops; ++outer) { |
| 64 int count = 0; |
| 65 for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) { |
| 66 SkRect r = fRects[0]; |
| 67 count += r.intersect(fRects[i]); |
| 68 } |
| 69 this->virtualCallToFoilOptimizers(count); |
| 70 } |
| 71 } |
| 72 }; |
| 73 |
| 74 class GeoRectBench_intersect_rect : public GeoRectBench { |
| 75 public: |
| 76 GeoRectBench_intersect_rect() : GeoRectBench("rect_intersect_rect") {} |
| 77 |
| 78 protected: |
| 79 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 80 for (int outer = 0; outer < loops; ++outer) { |
| 81 int count = 0; |
| 82 SkRect r; |
| 83 for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) { |
| 84 count += r.intersect(fRects[0], fRects[i]); |
| 85 } |
| 86 this->virtualCallToFoilOptimizers(count); |
| 87 } |
| 88 } |
| 89 }; |
| 90 |
| 91 class GeoRectBench_Intersects : public GeoRectBench { |
| 92 public: |
| 93 GeoRectBench_Intersects() : GeoRectBench("rect_Intersects") {} |
| 94 |
| 95 protected: |
| 96 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 97 for (int outer = 0; outer < loops; ++outer) { |
| 98 int count = 0; |
| 99 for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) { |
| 100 fVolatileInt += SkRect::Intersects(fRects[0], fRects[i]); |
| 101 } |
| 102 this->virtualCallToFoilOptimizers(count); |
| 103 } |
| 104 } |
| 105 }; |
| 106 |
| 107 DEF_BENCH( return new GeoRectBench_intersect; ) |
| 108 DEF_BENCH( return new GeoRectBench_intersect_rect; ) |
| 109 DEF_BENCH( return new GeoRectBench_Intersects; ) |
OLD | NEW |