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 "Benchmark.h" | 7 #include "Benchmark.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, | |
17 kMD5_ChecksumType, | 16 kMD5_ChecksumType, |
18 kSHA1_ChecksumType, | 17 kSHA1_ChecksumType, |
19 kMurmur3_ChecksumType, | 18 kMurmur3_ChecksumType, |
20 }; | 19 }; |
21 | 20 |
22 class ComputeChecksumBench : public Benchmark { | 21 class ComputeChecksumBench : public Benchmark { |
23 enum { | 22 enum { |
24 U32COUNT = 256, | 23 U32COUNT = 256, |
25 SIZE = U32COUNT * 4, | 24 SIZE = U32COUNT * 4, |
26 }; | 25 }; |
27 uint32_t fData[U32COUNT]; | 26 uint32_t fData[U32COUNT]; |
28 ChecksumType fType; | 27 ChecksumType fType; |
29 | 28 |
30 public: | 29 public: |
31 ComputeChecksumBench(ChecksumType type) : fType(type) { | 30 ComputeChecksumBench(ChecksumType type) : fType(type) { |
32 SkRandom rand; | 31 SkRandom rand; |
33 for (int i = 0; i < U32COUNT; ++i) { | 32 for (int i = 0; i < U32COUNT; ++i) { |
34 fData[i] = rand.nextU(); | 33 fData[i] = rand.nextU(); |
35 } | 34 } |
36 } | 35 } |
37 | 36 |
38 bool isSuitableFor(Backend backend) override { | 37 bool isSuitableFor(Backend backend) override { |
39 return backend == kNonRendering_Backend; | 38 return backend == kNonRendering_Backend; |
40 } | 39 } |
41 | 40 |
42 protected: | 41 protected: |
43 const char* onGetName() override { | 42 const char* onGetName() override { |
44 switch (fType) { | 43 switch (fType) { |
45 case kChecksum_ChecksumType: return "compute_checksum"; | |
46 case kMD5_ChecksumType: return "compute_md5"; | 44 case kMD5_ChecksumType: return "compute_md5"; |
47 case kSHA1_ChecksumType: return "compute_sha1"; | 45 case kSHA1_ChecksumType: return "compute_sha1"; |
48 case kMurmur3_ChecksumType: return "compute_murmur3"; | 46 case kMurmur3_ChecksumType: return "compute_murmur3"; |
49 | 47 |
50 default: SK_CRASH(); return ""; | 48 default: SK_CRASH(); return ""; |
51 } | 49 } |
52 } | 50 } |
53 | 51 |
54 void onDraw(int loops, SkCanvas*) override { | 52 void onDraw(int loops, SkCanvas*) override { |
55 switch (fType) { | 53 switch (fType) { |
56 case kChecksum_ChecksumType: { | |
57 for (int i = 0; i < loops; i++) { | |
58 volatile uint32_t result = SkChecksum::Compute(fData, sizeof
(fData)); | |
59 sk_ignore_unused_variable(result); | |
60 } | |
61 } break; | |
62 case kMD5_ChecksumType: { | 54 case kMD5_ChecksumType: { |
63 for (int i = 0; i < loops; i++) { | 55 for (int i = 0; i < loops; i++) { |
64 SkMD5 md5; | 56 SkMD5 md5; |
65 md5.update(reinterpret_cast<uint8_t*>(fData), sizeof(fData))
; | 57 md5.update(reinterpret_cast<uint8_t*>(fData), sizeof(fData))
; |
66 SkMD5::Digest digest; | 58 SkMD5::Digest digest; |
67 md5.finish(digest); | 59 md5.finish(digest); |
68 } | 60 } |
69 } break; | 61 } break; |
70 case kSHA1_ChecksumType: { | 62 case kSHA1_ChecksumType: { |
71 for (int i = 0; i < loops; i++) { | 63 for (int i = 0; i < loops; i++) { |
(...skipping 12 matching lines...) Expand all Loading... |
84 } | 76 } |
85 | 77 |
86 } | 78 } |
87 | 79 |
88 private: | 80 private: |
89 typedef Benchmark INHERITED; | 81 typedef Benchmark INHERITED; |
90 }; | 82 }; |
91 | 83 |
92 /////////////////////////////////////////////////////////////////////////////// | 84 /////////////////////////////////////////////////////////////////////////////// |
93 | 85 |
94 DEF_BENCH( return new ComputeChecksumBench(kChecksum_ChecksumType); ) | |
95 DEF_BENCH( return new ComputeChecksumBench(kMD5_ChecksumType); ) | 86 DEF_BENCH( return new ComputeChecksumBench(kMD5_ChecksumType); ) |
96 DEF_BENCH( return new ComputeChecksumBench(kSHA1_ChecksumType); ) | 87 DEF_BENCH( return new ComputeChecksumBench(kSHA1_ChecksumType); ) |
97 DEF_BENCH( return new ComputeChecksumBench(kMurmur3_ChecksumType); ) | 88 DEF_BENCH( return new ComputeChecksumBench(kMurmur3_ChecksumType); ) |
OLD | NEW |