aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/ChecksumBench.cpp
diff options
context:
space:
mode:
authorGravatar junov@chromium.org <junov@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-06-27 20:03:16 +0000
committerGravatar junov@chromium.org <junov@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-06-27 20:03:16 +0000
commitef76060cbf36032a5bef9cd8d18138704349c3ae (patch)
tree311689250089aa74aa3297a0dd6bdf0de4b073b1 /bench/ChecksumBench.cpp
parent97fafe1b5ec06b470d36ea5cd98fe7bf2c143491 (diff)
Adding checksum to SkFlatData to accelerate SkPicture recording.
The checksum triggers an early exit in the mem compare use to search for duplicate flattened objects. Also, call to memcmp was replaced with 64-bit at a time comparison loop. Review URL: http://codereview.appspot.com/6339046/ BUG=http://code.google.com/p/chromium/issues/detail?id=54079 TEST=Checksum and PictureRecord tests in bench.exe git-svn-id: http://skia.googlecode.com/svn/trunk@4378 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'bench/ChecksumBench.cpp')
-rw-r--r--bench/ChecksumBench.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/bench/ChecksumBench.cpp b/bench/ChecksumBench.cpp
new file mode 100644
index 0000000000..9057d1272b
--- /dev/null
+++ b/bench/ChecksumBench.cpp
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "SkBenchmark.h"
+#include "SkCanvas.h"
+#include "SkChecksum.h"
+#include "SkString.h"
+
+class ComputeChecksumBench : public SkBenchmark {
+public:
+ ComputeChecksumBench(void* param, const char name[]) : INHERITED(param) {
+ fName.printf("compute_checksum_%s", name);
+ }
+
+ enum {
+ DATA_SIZE = 1024,
+ N = SkBENCHLOOP(100000),
+ };
+protected:
+ virtual const char* onGetName() {
+ return fName.c_str();
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ uint64_t data[DATA_SIZE / sizeof(uint64_t)];
+ computeChecksum(data, DATA_SIZE);
+ }
+
+ virtual void computeChecksum(const uint64_t*, size_t) = 0;
+
+ SkString fName;
+private:
+ typedef SkBenchmark INHERITED;
+};
+
+/*
+ * Use SkComputeChecksum32 to compute a checksum on a datablock
+ */
+class ComputeChecksum32Bench : public ComputeChecksumBench {
+public:
+ ComputeChecksum32Bench(void* param)
+ : INHERITED(param, "32") { }
+
+protected:
+ virtual void computeChecksum(const uint64_t* data, size_t len) {
+ for (int i = 0; i < N; i++) {
+ volatile uint32_t result = SkComputeChecksum32(reinterpret_cast<const uint32_t*>(data), len);
+ }
+ }
+
+private:
+ typedef ComputeChecksumBench INHERITED;
+};
+
+/*
+ * Use SkComputeChecksum64 to compute a checksum on a datablock
+ */
+class ComputeChecksum64Bench : public ComputeChecksumBench {
+public:
+ ComputeChecksum64Bench(void* param)
+ : INHERITED(param, "64") { }
+
+protected:
+ virtual void computeChecksum(const uint64_t* data, size_t len) {
+ for (int i = 0; i < N; i++) {
+ volatile uint64_t result = SkComputeChecksum64(data, len);
+ }
+ }
+
+private:
+ typedef ComputeChecksumBench INHERITED;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+static SkBenchmark* Fact0(void* p) { return new ComputeChecksum32Bench(p); }
+static SkBenchmark* Fact1(void* p) { return new ComputeChecksum64Bench(p); }
+
+static BenchRegistry gReg0(Fact0);
+static BenchRegistry gReg1(Fact1);