Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(651)

Side by Side Diff: bench/ChecksumBench.cpp

Issue 2208903002: Use sse4.2 CRC32 instructions to hash when available. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « BUILD.gn ('k') | cmake/CMakeLists.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkOpts.h"
10 #include "SkMD5.h" 11 #include "SkMD5.h"
11 #include "SkRandom.h" 12 #include "SkRandom.h"
12 #include "SkTemplates.h" 13 #include "SkTemplates.h"
13 14
14 enum ChecksumType { 15 enum ChecksumType {
15 kMD5_ChecksumType, 16 kMD5_ChecksumType,
16 kMurmur3_ChecksumType, 17 kHash_ChecksumType,
17 }; 18 };
18 19
19 class ComputeChecksumBench : public Benchmark { 20 class ComputeChecksumBench : public Benchmark {
20 enum { 21 enum {
21 U32COUNT = 256, 22 U32COUNT = 256,
22 SIZE = U32COUNT * 4, 23 SIZE = U32COUNT * 4,
23 }; 24 };
24 uint32_t fData[U32COUNT]; 25 uint32_t fData[U32COUNT];
25 ChecksumType fType; 26 ChecksumType fType;
26 27
27 public: 28 public:
28 ComputeChecksumBench(ChecksumType type) : fType(type) { 29 ComputeChecksumBench(ChecksumType type) : fType(type) {
29 SkRandom rand; 30 SkRandom rand;
30 for (int i = 0; i < U32COUNT; ++i) { 31 for (int i = 0; i < U32COUNT; ++i) {
31 fData[i] = rand.nextU(); 32 fData[i] = rand.nextU();
32 } 33 }
33 } 34 }
34 35
35 bool isSuitableFor(Backend backend) override { 36 bool isSuitableFor(Backend backend) override {
36 return backend == kNonRendering_Backend; 37 return backend == kNonRendering_Backend;
37 } 38 }
38 39
39 protected: 40 protected:
40 const char* onGetName() override { 41 const char* onGetName() override {
41 switch (fType) { 42 switch (fType) {
42 case kMD5_ChecksumType: return "compute_md5"; 43 case kMD5_ChecksumType: return "compute_md5";
43 case kMurmur3_ChecksumType: return "compute_murmur3"; 44 case kHash_ChecksumType: return "compute_hash";
44 45
45 default: SK_ABORT("Invalid Type"); return ""; 46 default: SK_ABORT("Invalid Type"); return "";
46 } 47 }
47 } 48 }
48 49
49 void onDraw(int loops, SkCanvas*) override { 50 void onDraw(int loops, SkCanvas*) override {
50 switch (fType) { 51 switch (fType) {
51 case kMD5_ChecksumType: { 52 case kMD5_ChecksumType: {
52 for (int i = 0; i < loops; i++) { 53 for (int i = 0; i < loops; i++) {
53 SkMD5 md5; 54 SkMD5 md5;
54 md5.write(fData, sizeof(fData)); 55 md5.write(fData, sizeof(fData));
55 SkMD5::Digest digest; 56 SkMD5::Digest digest;
56 md5.finish(digest); 57 md5.finish(digest);
57 } 58 }
58 } break; 59 } break;
59 case kMurmur3_ChecksumType: { 60 case kHash_ChecksumType: {
60 for (int i = 0; i < loops; i++) { 61 for (int i = 0; i < loops; i++) {
61 volatile uint32_t result = SkChecksum::Murmur3(fData, sizeof (fData)); 62 volatile uint32_t result = SkOpts::hash(fData, sizeof(fData) );
62 sk_ignore_unused_variable(result); 63 sk_ignore_unused_variable(result);
63 } 64 }
64 }break; 65 }break;
65 } 66 }
66 67
67 } 68 }
68 69
69 private: 70 private:
70 typedef Benchmark INHERITED; 71 typedef Benchmark INHERITED;
71 }; 72 };
72 73
73 /////////////////////////////////////////////////////////////////////////////// 74 ///////////////////////////////////////////////////////////////////////////////
74 75
75 DEF_BENCH( return new ComputeChecksumBench(kMD5_ChecksumType); ) 76 DEF_BENCH( return new ComputeChecksumBench(kMD5_ChecksumType); )
76 DEF_BENCH( return new ComputeChecksumBench(kMurmur3_ChecksumType); ) 77 DEF_BENCH( return new ComputeChecksumBench(kHash_ChecksumType); )
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | cmake/CMakeLists.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698