aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/MathBench.cpp
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-04-29 13:55:11 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-04-29 13:55:11 +0000
commit0d7aac9ce7e66927055c79d25705a1d3be180eb9 (patch)
tree619c191369d7ee8aaf3cf6f16c86984a630a9243 /bench/MathBench.cpp
parent553ad65f787c7dafa7a131921ea107724dc95357 (diff)
add bench for SkCLZ
git-svn-id: http://skia.googlecode.com/svn/trunk@8894 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'bench/MathBench.cpp')
-rw-r--r--bench/MathBench.cpp70
1 files changed, 66 insertions, 4 deletions
diff --git a/bench/MathBench.cpp b/bench/MathBench.cpp
index 86dd684b86..26af374823 100644
--- a/bench/MathBench.cpp
+++ b/bench/MathBench.cpp
@@ -59,15 +59,15 @@ private:
class MathBenchU32 : public MathBench {
public:
MathBenchU32(void* param, const char name[]) : INHERITED(param, name) {}
-
+
protected:
virtual void performITest(uint32_t* SK_RESTRICT dst,
const uint32_t* SK_RESTRICT src,
int count) = 0;
-
+
virtual void performTest(float* SK_RESTRICT dst,
- const float* SK_RESTRICT src,
- int count) SK_OVERRIDE {
+ const float* SK_RESTRICT src,
+ int count) SK_OVERRIDE {
uint32_t* d = SkTCast<uint32_t*>(dst);
const uint32_t* s = SkTCast<const uint32_t*>(src);
this->performITest(d, s, count);
@@ -371,6 +371,66 @@ private:
typedef SkBenchmark INHERITED;
};
+class CLZBench : public SkBenchmark {
+ enum {
+ ARRAY = SkBENCHLOOP(1000),
+ LOOP = SkBENCHLOOP(1000),
+ };
+ uint32_t fData[ARRAY];
+ bool fUsePortable;
+
+public:
+ CLZBench(void* param, bool usePortable)
+ : INHERITED(param)
+ , fUsePortable(usePortable) {
+
+ SkRandom rand;
+ for (int i = 0; i < ARRAY; ++i) {
+ fData[i] = rand.nextU();
+ }
+
+ if (fUsePortable) {
+ fName = "clz_portable";
+ } else {
+ fName = "clz_intrinsic";
+ }
+ fIsRendering = false;
+ }
+
+ // just so the compiler doesn't remove our loops
+ virtual void process(int) {}
+
+protected:
+ virtual void onDraw(SkCanvas*) {
+ int accum = 0;
+
+ if (fUsePortable) {
+ for (int j = 0; j < LOOP; ++j) {
+ for (int i = 0; i < ARRAY; ++i) {
+ accum += SkCLZ_portable(fData[i]);
+ }
+ this->process(accum);
+ }
+ } else {
+ for (int j = 0; j < LOOP; ++j) {
+ for (int i = 0; i < ARRAY; ++i) {
+ accum += SkCLZ(fData[i]);
+ }
+ this->process(accum);
+ }
+ }
+ }
+
+ virtual const char* onGetName() {
+ return fName;
+ }
+
+private:
+ const char* fName;
+
+ typedef SkBenchmark INHERITED;
+};
+
///////////////////////////////////////////////////////////////////////////////
DEF_BENCH( return new NoOpMathBench(p); )
@@ -390,3 +450,5 @@ DEF_BENCH( return new IsFiniteBench(p, 5); )
DEF_BENCH( return new FloorBench(p, false); )
DEF_BENCH( return new FloorBench(p, true); )
+DEF_BENCH( return new CLZBench(p, false); )
+DEF_BENCH( return new CLZBench(p, true); )