add test for computing the bounds of an array of points (SkRect::set)
authorreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 15 May 2012 14:14:04 +0000 (14:14 +0000)
committerreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 15 May 2012 14:14:04 +0000 (14:14 +0000)
git-svn-id: http://skia.googlecode.com/svn/trunk@3935 2bbb7eff-a529-9590-31e7-b0007b416f81

bench/ScalarBench.cpp

index 8bedfbdede80c246452d34ace1b68391e8df9660..8889d7b74fe7df11d04e2aed5468ad72a7195658 100644 (file)
@@ -8,6 +8,7 @@
 #include "SkBenchmark.h"
 #include "SkFloatBits.h"
 #include "SkRandom.h"
+#include "SkRect.h"
 #include "SkString.h"
 
 class ScalarBench : public SkBenchmark {
@@ -97,8 +98,46 @@ private:
     typedef ScalarBench INHERITED;
 };
 
+///////////////////////////////////////////////////////////////////////////////
+
+class RectBoundsBench : public SkBenchmark {
+    enum {
+        PTS = 100,
+        N = SkBENCHLOOP(10000)
+    };
+    SkPoint fPts[PTS];
+
+public:
+    RectBoundsBench(void* param) : INHERITED(param) {
+        SkRandom rand;
+        for (int i = 0; i < PTS; ++i) {
+            fPts[i].fX = rand.nextSScalar1();
+            fPts[i].fY = rand.nextSScalar1();
+        }
+    }
+
+protected:
+    virtual const char* onGetName() SK_OVERRIDE {
+        return "rect_bounds";
+    }
+
+    virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+        SkRect r;
+        for (int i = 0; i < N; ++i) {
+            r.set(fPts, PTS);
+        }
+    }
+
+private:
+    typedef SkBenchmark INHERITED;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
 static SkBenchmark* S0(void* p) { return new FloatComparisonBench(p); }
 static SkBenchmark* S1(void* p) { return new ForcedIntComparisonBench(p); }
+static SkBenchmark* S2(void* p) { return new RectBoundsBench(p); }
 
 static BenchRegistry gReg0(S0);
 static BenchRegistry gReg1(S1);
+static BenchRegistry gReg2(S2);