junov@chromium.org | ef76060 | 2012-06-27 20:03:16 +0000 | [diff] [blame] | 1 | /* |
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 | */ | ||||
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 7 | #include "Benchmark.h" |
junov@chromium.org | ef76060 | 2012-06-27 20:03:16 +0000 | [diff] [blame] | 8 | #include "SkCanvas.h" |
9 | #include "SkChecksum.h" | ||||
mtklein | 4e97607 | 2016-08-08 09:06:27 -0700 | [diff] [blame] | 10 | #include "SkOpts.h" |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 11 | #include "SkMD5.h" |
reed@google.com | 142e1fe | 2012-07-09 17:44:44 +0000 | [diff] [blame] | 12 | #include "SkRandom.h" |
bungeman@google.com | 7de18e5 | 2013-02-04 15:58:08 +0000 | [diff] [blame] | 13 | #include "SkTemplates.h" |
bungeman@google.com | 29dea74 | 2013-01-31 20:36:30 +0000 | [diff] [blame] | 14 | |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 15 | enum ChecksumType { |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 16 | kMD5_ChecksumType, |
mtklein | 4e97607 | 2016-08-08 09:06:27 -0700 | [diff] [blame] | 17 | kHash_ChecksumType, |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 18 | }; |
junov@chromium.org | ef76060 | 2012-06-27 20:03:16 +0000 | [diff] [blame] | 19 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 20 | class ComputeChecksumBench : public Benchmark { |
reed@google.com | fc8581b | 2012-07-09 17:40:48 +0000 | [diff] [blame] | 21 | enum { |
reed@google.com | 142e1fe | 2012-07-09 17:44:44 +0000 | [diff] [blame] | 22 | U32COUNT = 256, |
23 | SIZE = U32COUNT * 4, | ||||
reed@google.com | fc8581b | 2012-07-09 17:40:48 +0000 | [diff] [blame] | 24 | }; |
reed@google.com | 142e1fe | 2012-07-09 17:44:44 +0000 | [diff] [blame] | 25 | uint32_t fData[U32COUNT]; |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 26 | ChecksumType fType; |
reed@google.com | 142e1fe | 2012-07-09 17:44:44 +0000 | [diff] [blame] | 27 | |
28 | public: | ||||
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 29 | ComputeChecksumBench(ChecksumType type) : fType(type) { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 30 | SkRandom rand; |
reed@google.com | 142e1fe | 2012-07-09 17:44:44 +0000 | [diff] [blame] | 31 | for (int i = 0; i < U32COUNT; ++i) { |
32 | fData[i] = rand.nextU(); | ||||
33 | } | ||||
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 34 | } |
35 | |||||
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 36 | bool isSuitableFor(Backend backend) override { |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 37 | return backend == kNonRendering_Backend; |
reed@google.com | 142e1fe | 2012-07-09 17:44:44 +0000 | [diff] [blame] | 38 | } |
39 | |||||
junov@chromium.org | ef76060 | 2012-06-27 20:03:16 +0000 | [diff] [blame] | 40 | protected: |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 41 | const char* onGetName() override { |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 42 | switch (fType) { |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 43 | case kMD5_ChecksumType: return "compute_md5"; |
mtklein | 4e97607 | 2016-08-08 09:06:27 -0700 | [diff] [blame] | 44 | case kHash_ChecksumType: return "compute_hash"; |
commit-bot@chromium.org | 70d75ca | 2013-07-23 20:25:34 +0000 | [diff] [blame] | 45 | |
djsollen | f2b340f | 2016-01-29 08:51:04 -0800 | [diff] [blame] | 46 | default: SK_ABORT("Invalid Type"); return ""; |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 47 | } |
junov@chromium.org | ef76060 | 2012-06-27 20:03:16 +0000 | [diff] [blame] | 48 | } |
49 | |||||
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 50 | void onDraw(int loops, SkCanvas*) override { |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 51 | switch (fType) { |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 52 | case kMD5_ChecksumType: { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 53 | for (int i = 0; i < loops; i++) { |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 54 | SkMD5 md5; |
halcanary | 1e90304 | 2016-04-25 10:29:36 -0700 | [diff] [blame] | 55 | md5.write(fData, sizeof(fData)); |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 56 | SkMD5::Digest digest; |
57 | md5.finish(digest); | ||||
58 | } | ||||
59 | } break; | ||||
mtklein | 4e97607 | 2016-08-08 09:06:27 -0700 | [diff] [blame] | 60 | case kHash_ChecksumType: { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 61 | for (int i = 0; i < loops; i++) { |
mtklein | 4e97607 | 2016-08-08 09:06:27 -0700 | [diff] [blame] | 62 | volatile uint32_t result = SkOpts::hash(fData, sizeof(fData)); |
commit-bot@chromium.org | 70d75ca | 2013-07-23 20:25:34 +0000 | [diff] [blame] | 63 | sk_ignore_unused_variable(result); |
64 | } | ||||
65 | }break; | ||||
reed@google.com | 142e1fe | 2012-07-09 17:44:44 +0000 | [diff] [blame] | 66 | } |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 67 | |
junov@chromium.org | ef76060 | 2012-06-27 20:03:16 +0000 | [diff] [blame] | 68 | } |
69 | |||||
junov@chromium.org | ef76060 | 2012-06-27 20:03:16 +0000 | [diff] [blame] | 70 | private: |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 71 | typedef Benchmark INHERITED; |
junov@chromium.org | ef76060 | 2012-06-27 20:03:16 +0000 | [diff] [blame] | 72 | }; |
73 | |||||
junov@chromium.org | ef76060 | 2012-06-27 20:03:16 +0000 | [diff] [blame] | 74 | /////////////////////////////////////////////////////////////////////////////// |
75 | |||||
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 76 | DEF_BENCH( return new ComputeChecksumBench(kMD5_ChecksumType); ) |
mtklein | 4e97607 | 2016-08-08 09:06:27 -0700 | [diff] [blame] | 77 | DEF_BENCH( return new ComputeChecksumBench(kHash_ChecksumType); ) |