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