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 | */ |
| 7 | #include "SkBenchmark.h" |
| 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 | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 12 | #include "SkSHA1.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 { |
| 16 | kChecksum_ChecksumType, |
| 17 | kMD5_ChecksumType, |
commit-bot@chromium.org | 70d75ca | 2013-07-23 20:25:34 +0000 | [diff] [blame] | 18 | kSHA1_ChecksumType, |
| 19 | kMurmur3_ChecksumType, |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 20 | }; |
junov@chromium.org | ef76060 | 2012-06-27 20:03:16 +0000 | [diff] [blame] | 21 | |
| 22 | class ComputeChecksumBench : public SkBenchmark { |
reed@google.com | fc8581b | 2012-07-09 17:40:48 +0000 | [diff] [blame] | 23 | enum { |
reed@google.com | 142e1fe | 2012-07-09 17:44:44 +0000 | [diff] [blame] | 24 | U32COUNT = 256, |
| 25 | SIZE = U32COUNT * 4, |
reed@google.com | fc8581b | 2012-07-09 17:40:48 +0000 | [diff] [blame] | 26 | }; |
reed@google.com | 142e1fe | 2012-07-09 17:44:44 +0000 | [diff] [blame] | 27 | uint32_t fData[U32COUNT]; |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 28 | ChecksumType fType; |
reed@google.com | 142e1fe | 2012-07-09 17:44:44 +0000 | [diff] [blame] | 29 | |
| 30 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 31 | ComputeChecksumBench(ChecksumType type) : fType(type) { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 32 | SkRandom rand; |
reed@google.com | 142e1fe | 2012-07-09 17:44:44 +0000 | [diff] [blame] | 33 | for (int i = 0; i < U32COUNT; ++i) { |
| 34 | fData[i] = rand.nextU(); |
| 35 | } |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { |
| 39 | return backend == kNonRendering_Backend; |
reed@google.com | 142e1fe | 2012-07-09 17:44:44 +0000 | [diff] [blame] | 40 | } |
| 41 | |
junov@chromium.org | ef76060 | 2012-06-27 20:03:16 +0000 | [diff] [blame] | 42 | protected: |
| 43 | virtual const char* onGetName() { |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 44 | switch (fType) { |
| 45 | case kChecksum_ChecksumType: return "compute_checksum"; |
| 46 | case kMD5_ChecksumType: return "compute_md5"; |
| 47 | case kSHA1_ChecksumType: return "compute_sha1"; |
commit-bot@chromium.org | 70d75ca | 2013-07-23 20:25:34 +0000 | [diff] [blame] | 48 | case kMurmur3_ChecksumType: return "compute_murmur3"; |
| 49 | |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 50 | default: SK_CRASH(); return ""; |
| 51 | } |
junov@chromium.org | ef76060 | 2012-06-27 20:03:16 +0000 | [diff] [blame] | 52 | } |
| 53 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 54 | virtual void onDraw(const int loops, SkCanvas*) { |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 55 | switch (fType) { |
| 56 | case kChecksum_ChecksumType: { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 57 | for (int i = 0; i < loops; i++) { |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 58 | volatile uint32_t result = SkChecksum::Compute(fData, sizeof(fData)); |
bungeman@google.com | 7de18e5 | 2013-02-04 15:58:08 +0000 | [diff] [blame] | 59 | sk_ignore_unused_variable(result); |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 60 | } |
| 61 | } break; |
| 62 | case kMD5_ChecksumType: { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 63 | for (int i = 0; i < loops; i++) { |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 64 | SkMD5 md5; |
| 65 | md5.update(reinterpret_cast<uint8_t*>(fData), sizeof(fData)); |
| 66 | SkMD5::Digest digest; |
| 67 | md5.finish(digest); |
| 68 | } |
| 69 | } break; |
| 70 | case kSHA1_ChecksumType: { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 71 | for (int i = 0; i < loops; i++) { |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 72 | SkSHA1 sha1; |
| 73 | sha1.update(reinterpret_cast<uint8_t*>(fData), sizeof(fData)); |
| 74 | SkSHA1::Digest digest; |
| 75 | sha1.finish(digest); |
| 76 | } |
| 77 | } break; |
commit-bot@chromium.org | 70d75ca | 2013-07-23 20:25:34 +0000 | [diff] [blame] | 78 | case kMurmur3_ChecksumType: { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 79 | for (int i = 0; i < loops; i++) { |
commit-bot@chromium.org | 70d75ca | 2013-07-23 20:25:34 +0000 | [diff] [blame] | 80 | volatile uint32_t result = SkChecksum::Murmur3(fData, sizeof(fData)); |
| 81 | sk_ignore_unused_variable(result); |
| 82 | } |
| 83 | }break; |
reed@google.com | 142e1fe | 2012-07-09 17:44:44 +0000 | [diff] [blame] | 84 | } |
bungeman@google.com | cfcb1be | 2013-01-31 19:47:48 +0000 | [diff] [blame] | 85 | |
junov@chromium.org | ef76060 | 2012-06-27 20:03:16 +0000 | [diff] [blame] | 86 | } |
| 87 | |
junov@chromium.org | ef76060 | 2012-06-27 20:03:16 +0000 | [diff] [blame] | 88 | private: |
| 89 | typedef SkBenchmark INHERITED; |
| 90 | }; |
| 91 | |
junov@chromium.org | ef76060 | 2012-06-27 20:03:16 +0000 | [diff] [blame] | 92 | /////////////////////////////////////////////////////////////////////////////// |
| 93 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 94 | DEF_BENCH( return new ComputeChecksumBench(kChecksum_ChecksumType); ) |
| 95 | DEF_BENCH( return new ComputeChecksumBench(kMD5_ChecksumType); ) |
| 96 | DEF_BENCH( return new ComputeChecksumBench(kSHA1_ChecksumType); ) |
| 97 | DEF_BENCH( return new ComputeChecksumBench(kMurmur3_ChecksumType); ) |