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 | 7 |
8 #include "Benchmark.h" | 8 #include "Benchmark.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkChunkAlloc.h" | 10 #include "SkChunkAlloc.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 } | 49 } |
50 } | 50 } |
51 | 51 |
52 private: | 52 private: |
53 typedef Benchmark INHERITED; | 53 typedef Benchmark INHERITED; |
54 }; | 54 }; |
55 | 55 |
56 DEF_BENCH( return new ChunkAllocBench(64); ) | 56 DEF_BENCH( return new ChunkAllocBench(64); ) |
57 DEF_BENCH( return new ChunkAllocBench(8*1024); ) | 57 DEF_BENCH( return new ChunkAllocBench(8*1024); ) |
58 | 58 |
59 static int* calloc(size_t num) { | |
60 return (int*)sk_calloc_throw(num*sizeof(int)); | |
61 } | |
62 | |
63 static int* malloc_bzero(size_t num) { | |
64 const size_t bytes = num*sizeof(int); | |
65 int* ints = (int*)sk_malloc_throw(bytes); | |
66 sk_bzero(ints, bytes); | |
67 return ints; | |
68 } | |
69 | |
70 class ZerosBench : public Benchmark { | |
71 size_t fNum; | |
72 bool fRead; | |
73 bool fWrite; | |
74 bool fUseCalloc; | |
75 SkString fName; | |
76 public: | |
77 ZerosBench(size_t num, bool read, bool write, bool useCalloc) | |
78 : fNum(num) | |
79 , fRead(read) | |
80 , fWrite(write) | |
81 , fUseCalloc(useCalloc) { | |
82 fName.printf("memory_%s", useCalloc ? "calloc" : "malloc_bzero"); | |
83 if (read && write) { | |
84 fName.appendf("_rw"); | |
85 } else if (read) { | |
86 fName.appendf("_r"); | |
87 } else if (write) { | |
88 fName.appendf("_w"); | |
89 } | |
90 fName.appendf("_" SK_SIZE_T_SPECIFIER, num); | |
91 } | |
92 | |
93 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { | |
94 return backend == kNonRendering_Backend; | |
95 } | |
96 | |
97 protected: | |
98 virtual const char* onGetName() SK_OVERRIDE { | |
99 return fName.c_str(); | |
100 } | |
101 | |
102 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { | |
103 for (int i = 0; i < loops; i++) { | |
104 int* zeros = fUseCalloc ? calloc(fNum) : malloc_bzero(fNum); | |
105 if (fRead) { | |
106 volatile int x = 15; | |
107 for (size_t j = 0; j < fNum; j++) { | |
108 x ^= zeros[j]; | |
109 } | |
110 } | |
111 if (fWrite) { | |
112 for (size_t j = 0; j < fNum; j++) { | |
113 zeros[j] = 15; | |
114 } | |
115 } | |
116 sk_free(zeros); | |
117 } | |
118 } | |
119 }; | |
120 | |
121 // zero count r w useCalloc? | |
122 DEF_BENCH(return new ZerosBench(1024*1024, 0, 0, 0)) | |
123 DEF_BENCH(return new ZerosBench(1024*1024, 0, 0, 1)) | |
124 DEF_BENCH(return new ZerosBench(1024*1024, 0, 1, 0)) | |
125 DEF_BENCH(return new ZerosBench(1024*1024, 0, 1, 1)) | |
126 DEF_BENCH(return new ZerosBench(1024*1024, 1, 0, 0)) | |
127 DEF_BENCH(return new ZerosBench(1024*1024, 1, 0, 1)) | |
128 DEF_BENCH(return new ZerosBench(1024*1024, 1, 1, 0)) | |
129 DEF_BENCH(return new ZerosBench(1024*1024, 1, 1, 1)) | |
130 | |
131 DEF_BENCH(return new ZerosBench(256*1024, 0, 0, 0)) | |
132 DEF_BENCH(return new ZerosBench(256*1024, 0, 0, 1)) | |
133 DEF_BENCH(return new ZerosBench(256*1024, 0, 1, 0)) | |
134 DEF_BENCH(return new ZerosBench(256*1024, 0, 1, 1)) | |
135 DEF_BENCH(return new ZerosBench(256*1024, 1, 0, 0)) | |
136 DEF_BENCH(return new ZerosBench(256*1024, 1, 0, 1)) | |
137 DEF_BENCH(return new ZerosBench(256*1024, 1, 1, 0)) | |
138 DEF_BENCH(return new ZerosBench(256*1024, 1, 1, 1)) | |
139 | |
140 DEF_BENCH(return new ZerosBench(4*1024, 0, 0, 0)) | |
141 DEF_BENCH(return new ZerosBench(4*1024, 0, 0, 1)) | |
142 DEF_BENCH(return new ZerosBench(4*1024, 0, 1, 0)) | |
143 DEF_BENCH(return new ZerosBench(4*1024, 0, 1, 1)) | |
144 DEF_BENCH(return new ZerosBench(4*1024, 1, 0, 0)) | |
145 DEF_BENCH(return new ZerosBench(4*1024, 1, 0, 1)) | |
146 DEF_BENCH(return new ZerosBench(4*1024, 1, 1, 0)) | |
147 DEF_BENCH(return new ZerosBench(4*1024, 1, 1, 1)) | |
148 | |
149 DEF_BENCH(return new ZerosBench(300, 0, 0, 0)) | |
150 DEF_BENCH(return new ZerosBench(300, 0, 0, 1)) | |
151 DEF_BENCH(return new ZerosBench(300, 0, 1, 0)) | |
152 DEF_BENCH(return new ZerosBench(300, 0, 1, 1)) | |
153 DEF_BENCH(return new ZerosBench(300, 1, 0, 0)) | |
154 DEF_BENCH(return new ZerosBench(300, 1, 0, 1)) | |
155 DEF_BENCH(return new ZerosBench(300, 1, 1, 0)) | |
156 DEF_BENCH(return new ZerosBench(300, 1, 1, 1)) | |
157 | |
158 DEF_BENCH(return new ZerosBench(4, 0, 0, 0)) | |
159 DEF_BENCH(return new ZerosBench(4, 0, 0, 1)) | |
160 DEF_BENCH(return new ZerosBench(4, 0, 1, 0)) | |
161 DEF_BENCH(return new ZerosBench(4, 0, 1, 1)) | |
162 DEF_BENCH(return new ZerosBench(4, 1, 0, 0)) | |
163 DEF_BENCH(return new ZerosBench(4, 1, 0, 1)) | |
164 DEF_BENCH(return new ZerosBench(4, 1, 1, 0)) | |
165 DEF_BENCH(return new ZerosBench(4, 1, 1, 1)) | |
OLD | NEW |