From ef76060cbf36032a5bef9cd8d18138704349c3ae Mon Sep 17 00:00:00 2001 From: "junov@chromium.org" Date: Wed, 27 Jun 2012 20:03:16 +0000 Subject: 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 --- bench/ChecksumBench.cpp | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 bench/ChecksumBench.cpp (limited to 'bench/ChecksumBench.cpp') 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(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); -- cgit v1.2.3