| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 #include "SkBenchmark.h" | 7 #include "SkBenchmark.h" |
| 8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkChecksum.h" | 9 #include "SkChecksum.h" |
| 10 #include "SkMD5.h" | 10 #include "SkMD5.h" |
| 11 #include "SkRandom.h" | 11 #include "SkRandom.h" |
| 12 #include "SkSHA1.h" | 12 #include "SkSHA1.h" |
| 13 #include "SkTemplates.h" | 13 #include "SkTemplates.h" |
| 14 | 14 |
| 15 enum ChecksumType { | 15 enum ChecksumType { |
| 16 kChecksum_ChecksumType, | 16 kChecksum_ChecksumType, |
| 17 kMD5_ChecksumType, | 17 kMD5_ChecksumType, |
| 18 kSHA1_ChecksumType, | 18 kSHA1_ChecksumType, |
| 19 kMurmur3_ChecksumType, | 19 kMurmur3_ChecksumType, |
| 20 }; | 20 }; |
| 21 | 21 |
| 22 class ComputeChecksumBench : public SkBenchmark { | 22 class ComputeChecksumBench : public SkBenchmark { |
| 23 enum { | 23 enum { |
| 24 U32COUNT = 256, | 24 U32COUNT = 256, |
| 25 SIZE = U32COUNT * 4, | 25 SIZE = U32COUNT * 4, |
| 26 N = SkBENCHLOOP(100000), | |
| 27 }; | 26 }; |
| 28 uint32_t fData[U32COUNT]; | 27 uint32_t fData[U32COUNT]; |
| 29 ChecksumType fType; | 28 ChecksumType fType; |
| 30 | 29 |
| 31 public: | 30 public: |
| 32 ComputeChecksumBench(void* param, ChecksumType type) : INHERITED(param), fTy
pe(type) { | 31 ComputeChecksumBench(void* param, ChecksumType type) : INHERITED(param), fTy
pe(type) { |
| 33 SkRandom rand; | 32 SkRandom rand; |
| 34 for (int i = 0; i < U32COUNT; ++i) { | 33 for (int i = 0; i < U32COUNT; ++i) { |
| 35 fData[i] = rand.nextU(); | 34 fData[i] = rand.nextU(); |
| 36 } | 35 } |
| 37 fIsRendering = false; | 36 fIsRendering = false; |
| 38 } | 37 } |
| 39 | 38 |
| 40 protected: | 39 protected: |
| 41 virtual const char* onGetName() { | 40 virtual const char* onGetName() { |
| 42 switch (fType) { | 41 switch (fType) { |
| 43 case kChecksum_ChecksumType: return "compute_checksum"; | 42 case kChecksum_ChecksumType: return "compute_checksum"; |
| 44 case kMD5_ChecksumType: return "compute_md5"; | 43 case kMD5_ChecksumType: return "compute_md5"; |
| 45 case kSHA1_ChecksumType: return "compute_sha1"; | 44 case kSHA1_ChecksumType: return "compute_sha1"; |
| 46 case kMurmur3_ChecksumType: return "compute_murmur3"; | 45 case kMurmur3_ChecksumType: return "compute_murmur3"; |
| 47 | 46 |
| 48 default: SK_CRASH(); return ""; | 47 default: SK_CRASH(); return ""; |
| 49 } | 48 } |
| 50 } | 49 } |
| 51 | 50 |
| 52 virtual void onDraw(SkCanvas*) { | 51 virtual void onDraw(SkCanvas*) { |
| 53 switch (fType) { | 52 switch (fType) { |
| 54 case kChecksum_ChecksumType: { | 53 case kChecksum_ChecksumType: { |
| 55 for (int i = 0; i < N; i++) { | 54 for (int i = 0; i < this->getLoops(); i++) { |
| 56 volatile uint32_t result = SkChecksum::Compute(fData, sizeof
(fData)); | 55 volatile uint32_t result = SkChecksum::Compute(fData, sizeof
(fData)); |
| 57 sk_ignore_unused_variable(result); | 56 sk_ignore_unused_variable(result); |
| 58 } | 57 } |
| 59 } break; | 58 } break; |
| 60 case kMD5_ChecksumType: { | 59 case kMD5_ChecksumType: { |
| 61 for (int i = 0; i < N; i++) { | 60 for (int i = 0; i < this->getLoops(); i++) { |
| 62 SkMD5 md5; | 61 SkMD5 md5; |
| 63 md5.update(reinterpret_cast<uint8_t*>(fData), sizeof(fData))
; | 62 md5.update(reinterpret_cast<uint8_t*>(fData), sizeof(fData))
; |
| 64 SkMD5::Digest digest; | 63 SkMD5::Digest digest; |
| 65 md5.finish(digest); | 64 md5.finish(digest); |
| 66 } | 65 } |
| 67 } break; | 66 } break; |
| 68 case kSHA1_ChecksumType: { | 67 case kSHA1_ChecksumType: { |
| 69 for (int i = 0; i < N; i++) { | 68 for (int i = 0; i < this->getLoops(); i++) { |
| 70 SkSHA1 sha1; | 69 SkSHA1 sha1; |
| 71 sha1.update(reinterpret_cast<uint8_t*>(fData), sizeof(fData)
); | 70 sha1.update(reinterpret_cast<uint8_t*>(fData), sizeof(fData)
); |
| 72 SkSHA1::Digest digest; | 71 SkSHA1::Digest digest; |
| 73 sha1.finish(digest); | 72 sha1.finish(digest); |
| 74 } | 73 } |
| 75 } break; | 74 } break; |
| 76 case kMurmur3_ChecksumType: { | 75 case kMurmur3_ChecksumType: { |
| 77 for (int i = 0; i < N; i++) { | 76 for (int i = 0; i < this->getLoops(); i++) { |
| 78 volatile uint32_t result = SkChecksum::Murmur3(fData, sizeof
(fData)); | 77 volatile uint32_t result = SkChecksum::Murmur3(fData, sizeof
(fData)); |
| 79 sk_ignore_unused_variable(result); | 78 sk_ignore_unused_variable(result); |
| 80 } | 79 } |
| 81 }break; | 80 }break; |
| 82 } | 81 } |
| 83 | 82 |
| 84 } | 83 } |
| 85 | 84 |
| 86 private: | 85 private: |
| 87 typedef SkBenchmark INHERITED; | 86 typedef SkBenchmark INHERITED; |
| 88 }; | 87 }; |
| 89 | 88 |
| 90 /////////////////////////////////////////////////////////////////////////////// | 89 /////////////////////////////////////////////////////////////////////////////// |
| 91 | 90 |
| 92 static SkBenchmark* Fact0(void* p) { return new ComputeChecksumBench(p, kChecksu
m_ChecksumType); } | 91 static SkBenchmark* Fact0(void* p) { return new ComputeChecksumBench(p, kChecksu
m_ChecksumType); } |
| 93 static SkBenchmark* Fact1(void* p) { return new ComputeChecksumBench(p, kMD5_Che
cksumType); } | 92 static SkBenchmark* Fact1(void* p) { return new ComputeChecksumBench(p, kMD5_Che
cksumType); } |
| 94 static SkBenchmark* Fact2(void* p) { return new ComputeChecksumBench(p, kSHA1_Ch
ecksumType); } | 93 static SkBenchmark* Fact2(void* p) { return new ComputeChecksumBench(p, kSHA1_Ch
ecksumType); } |
| 95 static SkBenchmark* Fact3(void* p) { return new ComputeChecksumBench(p, kMurmur3
_ChecksumType); } | 94 static SkBenchmark* Fact3(void* p) { return new ComputeChecksumBench(p, kMurmur3
_ChecksumType); } |
| 96 | 95 |
| 97 | 96 |
| 98 static BenchRegistry gReg0(Fact0); | 97 static BenchRegistry gReg0(Fact0); |
| 99 static BenchRegistry gReg1(Fact1); | 98 static BenchRegistry gReg1(Fact1); |
| 100 static BenchRegistry gReg2(Fact2); | 99 static BenchRegistry gReg2(Fact2); |
| 101 static BenchRegistry gReg3(Fact3); | 100 static BenchRegistry gReg3(Fact3); |
| OLD | NEW |