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 "SkCityHash.h" | |
11 #include "SkMD5.h" | 10 #include "SkMD5.h" |
12 #include "SkRandom.h" | 11 #include "SkRandom.h" |
13 #include "SkSHA1.h" | 12 #include "SkSHA1.h" |
14 #include "SkTemplates.h" | 13 #include "SkTemplates.h" |
15 | 14 |
16 enum ChecksumType { | 15 enum ChecksumType { |
17 kChecksum_ChecksumType, | 16 kChecksum_ChecksumType, |
18 kMD5_ChecksumType, | 17 kMD5_ChecksumType, |
19 kSHA1_ChecksumType, | 18 kSHA1_ChecksumType |
20 kCityHash32, | |
21 kCityHash64 | |
22 }; | 19 }; |
23 | 20 |
24 class ComputeChecksumBench : public SkBenchmark { | 21 class ComputeChecksumBench : public SkBenchmark { |
25 enum { | 22 enum { |
26 U32COUNT = 256, | 23 U32COUNT = 256, |
27 SIZE = U32COUNT * 4, | 24 SIZE = U32COUNT * 4, |
28 N = SkBENCHLOOP(100000), | 25 N = SkBENCHLOOP(100000), |
29 }; | 26 }; |
30 uint32_t fData[U32COUNT]; | 27 uint32_t fData[U32COUNT]; |
31 ChecksumType fType; | 28 ChecksumType fType; |
32 | 29 |
33 public: | 30 public: |
34 ComputeChecksumBench(void* param, ChecksumType type) : INHERITED(param), fTy
pe(type) { | 31 ComputeChecksumBench(void* param, ChecksumType type) : INHERITED(param), fTy
pe(type) { |
35 SkRandom rand; | 32 SkRandom rand; |
36 for (int i = 0; i < U32COUNT; ++i) { | 33 for (int i = 0; i < U32COUNT; ++i) { |
37 fData[i] = rand.nextU(); | 34 fData[i] = rand.nextU(); |
38 } | 35 } |
39 fIsRendering = false; | 36 fIsRendering = false; |
40 } | 37 } |
41 | 38 |
42 protected: | 39 protected: |
43 virtual const char* onGetName() { | 40 virtual const char* onGetName() { |
44 switch (fType) { | 41 switch (fType) { |
45 case kChecksum_ChecksumType: return "compute_checksum"; | 42 case kChecksum_ChecksumType: return "compute_checksum"; |
46 case kMD5_ChecksumType: return "compute_md5"; | 43 case kMD5_ChecksumType: return "compute_md5"; |
47 case kSHA1_ChecksumType: return "compute_sha1"; | 44 case kSHA1_ChecksumType: return "compute_sha1"; |
48 case kCityHash32: return "compute_cityhash32"; | |
49 case kCityHash64: return "compute_cityhash64"; | |
50 default: SK_CRASH(); return ""; | 45 default: SK_CRASH(); return ""; |
51 } | 46 } |
52 } | 47 } |
53 | 48 |
54 virtual void onDraw(SkCanvas*) { | 49 virtual void onDraw(SkCanvas*) { |
55 switch (fType) { | 50 switch (fType) { |
56 case kChecksum_ChecksumType: { | 51 case kChecksum_ChecksumType: { |
57 for (int i = 0; i < N; i++) { | 52 for (int i = 0; i < N; i++) { |
58 volatile uint32_t result = SkChecksum::Compute(fData, sizeof
(fData)); | 53 volatile uint32_t result = SkChecksum::Compute(fData, sizeof
(fData)); |
59 sk_ignore_unused_variable(result); | 54 sk_ignore_unused_variable(result); |
60 } | 55 } |
61 } break; | 56 } break; |
62 case kMD5_ChecksumType: { | 57 case kMD5_ChecksumType: { |
63 for (int i = 0; i < N; i++) { | 58 for (int i = 0; i < N; i++) { |
64 SkMD5 md5; | 59 SkMD5 md5; |
65 md5.update(reinterpret_cast<uint8_t*>(fData), sizeof(fData))
; | 60 md5.update(reinterpret_cast<uint8_t*>(fData), sizeof(fData))
; |
66 SkMD5::Digest digest; | 61 SkMD5::Digest digest; |
67 md5.finish(digest); | 62 md5.finish(digest); |
68 } | 63 } |
69 } break; | 64 } break; |
70 case kSHA1_ChecksumType: { | 65 case kSHA1_ChecksumType: { |
71 for (int i = 0; i < N; i++) { | 66 for (int i = 0; i < N; i++) { |
72 SkSHA1 sha1; | 67 SkSHA1 sha1; |
73 sha1.update(reinterpret_cast<uint8_t*>(fData), sizeof(fData)
); | 68 sha1.update(reinterpret_cast<uint8_t*>(fData), sizeof(fData)
); |
74 SkSHA1::Digest digest; | 69 SkSHA1::Digest digest; |
75 sha1.finish(digest); | 70 sha1.finish(digest); |
76 } | 71 } |
77 } break; | 72 } break; |
78 case kCityHash32: { | |
79 for (int i = 0; i < N; i++) { | |
80 volatile uint32_t result = SkCityHash::Compute32(reinterpret
_cast<char*>(fData), sizeof(fData)); | |
81 sk_ignore_unused_variable(result); | |
82 } | |
83 } break; | |
84 case kCityHash64: { | |
85 for (int i = 0; i < N; i++) { | |
86 volatile uint64_t result = SkCityHash::Compute64(reinterpret
_cast<char*>(fData), sizeof(fData)); | |
87 sk_ignore_unused_variable(result); | |
88 } | |
89 } break; | |
90 } | 73 } |
91 | 74 |
92 } | 75 } |
93 | 76 |
94 private: | 77 private: |
95 typedef SkBenchmark INHERITED; | 78 typedef SkBenchmark INHERITED; |
96 }; | 79 }; |
97 | 80 |
98 /////////////////////////////////////////////////////////////////////////////// | 81 /////////////////////////////////////////////////////////////////////////////// |
99 | 82 |
100 static SkBenchmark* Fact0(void* p) { return new ComputeChecksumBench(p, kChecksu
m_ChecksumType); } | 83 static SkBenchmark* Fact0(void* p) { return new ComputeChecksumBench(p, kChecksu
m_ChecksumType); } |
101 static SkBenchmark* Fact1(void* p) { return new ComputeChecksumBench(p, kMD5_Che
cksumType); } | 84 static SkBenchmark* Fact1(void* p) { return new ComputeChecksumBench(p, kMD5_Che
cksumType); } |
102 static SkBenchmark* Fact2(void* p) { return new ComputeChecksumBench(p, kSHA1_Ch
ecksumType); } | 85 static SkBenchmark* Fact2(void* p) { return new ComputeChecksumBench(p, kSHA1_Ch
ecksumType); } |
103 static SkBenchmark* Fact3(void* p) { return new ComputeChecksumBench(p, kCityHas
h32); } | |
104 static SkBenchmark* Fact4(void* p) { return new ComputeChecksumBench(p, kCityHas
h64); } | |
105 | 86 |
106 static BenchRegistry gReg0(Fact0); | 87 static BenchRegistry gReg0(Fact0); |
107 static BenchRegistry gReg1(Fact1); | 88 static BenchRegistry gReg1(Fact1); |
108 static BenchRegistry gReg2(Fact2); | 89 static BenchRegistry gReg2(Fact2); |
109 static BenchRegistry gReg3(Fact3); | |
110 static BenchRegistry gReg4(Fact4); | |
OLD | NEW |