blob: f84cd3d3bc535db21f68e22ed74ebe4305ccab99 [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"
mtklein4e976072016-08-08 09:06:27 -070010#include "SkOpts.h"
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000011#include "SkMD5.h"
reed@google.com142e1fe2012-07-09 17:44:44 +000012#include "SkRandom.h"
bungeman@google.com7de18e52013-02-04 15:58:08 +000013#include "SkTemplates.h"
bungeman@google.com29dea742013-01-31 20:36:30 +000014
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000015enum ChecksumType {
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000016 kMD5_ChecksumType,
mtklein4e976072016-08-08 09:06:27 -070017 kHash_ChecksumType,
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000018};
junov@chromium.orgef760602012-06-27 20:03:16 +000019
tfarinaf168b862014-06-19 12:32:29 -070020class ComputeChecksumBench : public Benchmark {
reed@google.comfc8581b2012-07-09 17:40:48 +000021 enum {
reed@google.com142e1fe2012-07-09 17:44:44 +000022 U32COUNT = 256,
23 SIZE = U32COUNT * 4,
reed@google.comfc8581b2012-07-09 17:40:48 +000024 };
reed@google.com142e1fe2012-07-09 17:44:44 +000025 uint32_t fData[U32COUNT];
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000026 ChecksumType fType;
reed@google.com142e1fe2012-07-09 17:44:44 +000027
28public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000029 ComputeChecksumBench(ChecksumType type) : fType(type) {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000030 SkRandom rand;
reed@google.com142e1fe2012-07-09 17:44:44 +000031 for (int i = 0; i < U32COUNT; ++i) {
32 fData[i] = rand.nextU();
33 }
commit-bot@chromium.org644629c2013-11-21 06:21:58 +000034 }
35
mtklein36352bf2015-03-25 18:17:31 -070036 bool isSuitableFor(Backend backend) override {
commit-bot@chromium.org644629c2013-11-21 06:21:58 +000037 return backend == kNonRendering_Backend;
reed@google.com142e1fe2012-07-09 17:44:44 +000038 }
39
junov@chromium.orgef760602012-06-27 20:03:16 +000040protected:
mtkleinf0599002015-07-13 06:18:39 -070041 const char* onGetName() override {
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000042 switch (fType) {
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000043 case kMD5_ChecksumType: return "compute_md5";
mtklein4e976072016-08-08 09:06:27 -070044 case kHash_ChecksumType: return "compute_hash";
commit-bot@chromium.org70d75ca2013-07-23 20:25:34 +000045
djsollenf2b340f2016-01-29 08:51:04 -080046 default: SK_ABORT("Invalid Type"); return "";
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000047 }
junov@chromium.orgef760602012-06-27 20:03:16 +000048 }
49
mtkleina1ebeb22015-10-01 09:43:39 -070050 void onDraw(int loops, SkCanvas*) override {
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000051 switch (fType) {
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000052 case kMD5_ChecksumType: {
commit-bot@chromium.org33614712013-12-03 18:17:16 +000053 for (int i = 0; i < loops; i++) {
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000054 SkMD5 md5;
halcanary1e903042016-04-25 10:29:36 -070055 md5.write(fData, sizeof(fData));
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000056 SkMD5::Digest digest;
57 md5.finish(digest);
58 }
59 } break;
mtklein4e976072016-08-08 09:06:27 -070060 case kHash_ChecksumType: {
commit-bot@chromium.org33614712013-12-03 18:17:16 +000061 for (int i = 0; i < loops; i++) {
mtklein4e976072016-08-08 09:06:27 -070062 volatile uint32_t result = SkOpts::hash(fData, sizeof(fData));
commit-bot@chromium.org70d75ca2013-07-23 20:25:34 +000063 sk_ignore_unused_variable(result);
64 }
65 }break;
reed@google.com142e1fe2012-07-09 17:44:44 +000066 }
bungeman@google.comcfcb1be2013-01-31 19:47:48 +000067
junov@chromium.orgef760602012-06-27 20:03:16 +000068 }
69
junov@chromium.orgef760602012-06-27 20:03:16 +000070private:
tfarinaf168b862014-06-19 12:32:29 -070071 typedef Benchmark INHERITED;
junov@chromium.orgef760602012-06-27 20:03:16 +000072};
73
junov@chromium.orgef760602012-06-27 20:03:16 +000074///////////////////////////////////////////////////////////////////////////////
75
mtklein@google.com410e6e82013-09-13 19:52:27 +000076DEF_BENCH( return new ComputeChecksumBench(kMD5_ChecksumType); )
mtklein4e976072016-08-08 09:06:27 -070077DEF_BENCH( return new ComputeChecksumBench(kHash_ChecksumType); )