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