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 | */ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 7 | #include "bench/Benchmark.h" |
| 8 | #include "include/core/SkCanvas.h" |
| 9 | #include "include/private/SkChecksum.h" |
| 10 | #include "include/private/SkTemplates.h" |
| 11 | #include "include/utils/SkRandom.h" |
| 12 | #include "src/core/SkMD5.h" |
| 13 | #include "src/core/SkOpts.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 | |
Brian Salomon | 74c19de | 2019-08-09 16:05:58 -0400 | [diff] [blame] | 46 | default: SK_ABORT("Invalid Type"); |
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)); |
Hal Canary | 0f2f522 | 2019-04-03 10:13:45 -0400 | [diff] [blame] | 56 | (void)md5.finish(); |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 57 | } |
| 58 | } break; |
mtklein | 4e97607 | 2016-08-08 09:06:27 -0700 | [diff] [blame] | 59 | case kHash_ChecksumType: { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 60 | for (int i = 0; i < loops; i++) { |
mtklein | 4e97607 | 2016-08-08 09:06:27 -0700 | [diff] [blame] | 61 | volatile uint32_t result = SkOpts::hash(fData, sizeof(fData)); |
commit-bot@chromium.org | 70d75ca | 2013-07-23 20:25:34 +0000 | [diff] [blame] | 62 | sk_ignore_unused_variable(result); |
| 63 | } |
| 64 | }break; |
reed@google.com | 142e1fe | 2012-07-09 17:44:44 +0000 | [diff] [blame] | 65 | } |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 66 | |
junov@chromium.org | ef76060 | 2012-06-27 20:03:16 +0000 | [diff] [blame] | 67 | } |
| 68 | |
junov@chromium.org | ef76060 | 2012-06-27 20:03:16 +0000 | [diff] [blame] | 69 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 70 | using INHERITED = Benchmark; |
junov@chromium.org | ef76060 | 2012-06-27 20:03:16 +0000 | [diff] [blame] | 71 | }; |
| 72 | |
junov@chromium.org | ef76060 | 2012-06-27 20:03:16 +0000 | [diff] [blame] | 73 | /////////////////////////////////////////////////////////////////////////////// |
| 74 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 75 | DEF_BENCH( return new ComputeChecksumBench(kMD5_ChecksumType); ) |
mtklein | 4e97607 | 2016-08-08 09:06:27 -0700 | [diff] [blame] | 76 | DEF_BENCH( return new ComputeChecksumBench(kHash_ChecksumType); ) |