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