blob: cba9572aa330974529dbc85d67a6805a418c9859 [file] [log] [blame]
junov@chromium.orgef760602012-06-27 20:03:16 +00001/*
2 * Copyright 2012 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 */
tfarinaf168b862014-06-19 12:32:29 -07007#include "Benchmark.h"
junov@chromium.orgef760602012-06-27 20:03:16 +00008#include "SkCanvas.h"
9#include "SkChecksum.h"
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000010#include "SkMD5.h"
reed@google.com142e1fe2012-07-09 17:44:44 +000011#include "SkRandom.h"
bungeman@google.com7de18e52013-02-04 15:58:08 +000012#include "SkTemplates.h"
bungeman@google.com29dea742013-01-31 20:36:30 +000013
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000014enum ChecksumType {
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000015 kMD5_ChecksumType,
commit-bot@chromium.org70d75ca2013-07-23 20:25:34 +000016 kMurmur3_ChecksumType,
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000017};
junov@chromium.orgef760602012-06-27 20:03:16 +000018
tfarinaf168b862014-06-19 12:32:29 -070019class ComputeChecksumBench : public Benchmark {
reed@google.comfc8581b2012-07-09 17:40:48 +000020 enum {
reed@google.com142e1fe2012-07-09 17:44:44 +000021 U32COUNT = 256,
22 SIZE = U32COUNT * 4,
reed@google.comfc8581b2012-07-09 17:40:48 +000023 };
reed@google.com142e1fe2012-07-09 17:44:44 +000024 uint32_t fData[U32COUNT];
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000025 ChecksumType fType;
reed@google.com142e1fe2012-07-09 17:44:44 +000026
27public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000028 ComputeChecksumBench(ChecksumType type) : fType(type) {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000029 SkRandom rand;
reed@google.com142e1fe2012-07-09 17:44:44 +000030 for (int i = 0; i < U32COUNT; ++i) {
31 fData[i] = rand.nextU();
32 }
commit-bot@chromium.org644629c2013-11-21 06:21:58 +000033 }
34
mtklein36352bf2015-03-25 18:17:31 -070035 bool isSuitableFor(Backend backend) override {
commit-bot@chromium.org644629c2013-11-21 06:21:58 +000036 return backend == kNonRendering_Backend;
reed@google.com142e1fe2012-07-09 17:44:44 +000037 }
38
junov@chromium.orgef760602012-06-27 20:03:16 +000039protected:
mtkleinf0599002015-07-13 06:18:39 -070040 const char* onGetName() override {
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000041 switch (fType) {
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000042 case kMD5_ChecksumType: return "compute_md5";
commit-bot@chromium.org70d75ca2013-07-23 20:25:34 +000043 case kMurmur3_ChecksumType: return "compute_murmur3";
44
djsollenf2b340f2016-01-29 08:51:04 -080045 default: SK_ABORT("Invalid Type"); return "";
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000046 }
junov@chromium.orgef760602012-06-27 20:03:16 +000047 }
48
mtkleina1ebeb22015-10-01 09:43:39 -070049 void onDraw(int loops, SkCanvas*) override {
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000050 switch (fType) {
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000051 case kMD5_ChecksumType: {
commit-bot@chromium.org33614712013-12-03 18:17:16 +000052 for (int i = 0; i < loops; i++) {
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000053 SkMD5 md5;
54 md5.update(reinterpret_cast<uint8_t*>(fData), sizeof(fData));
55 SkMD5::Digest digest;
56 md5.finish(digest);
57 }
58 } break;
commit-bot@chromium.org70d75ca2013-07-23 20:25:34 +000059 case kMurmur3_ChecksumType: {
commit-bot@chromium.org33614712013-12-03 18:17:16 +000060 for (int i = 0; i < loops; i++) {
commit-bot@chromium.org70d75ca2013-07-23 20:25:34 +000061 volatile uint32_t result = SkChecksum::Murmur3(fData, sizeof(fData));
62 sk_ignore_unused_variable(result);
63 }
64 }break;
reed@google.com142e1fe2012-07-09 17:44:44 +000065 }
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000066
junov@chromium.orgef760602012-06-27 20:03:16 +000067 }
68
junov@chromium.orgef760602012-06-27 20:03:16 +000069private:
tfarinaf168b862014-06-19 12:32:29 -070070 typedef Benchmark INHERITED;
junov@chromium.orgef760602012-06-27 20:03:16 +000071};
72
junov@chromium.orgef760602012-06-27 20:03:16 +000073///////////////////////////////////////////////////////////////////////////////
74
mtklein@google.com410e6e82013-09-13 19:52:27 +000075DEF_BENCH( return new ComputeChecksumBench(kMD5_ChecksumType); )
mtklein@google.com410e6e82013-09-13 19:52:27 +000076DEF_BENCH( return new ComputeChecksumBench(kMurmur3_ChecksumType); )