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