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

Side by Side Diff: bench/GrMemoryPoolBench.cpp

Issue 347823004: Remove Sk prefix from some bench classes. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: SkGMBench -> GMBench Created 6 years, 6 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 | « bench/GameBench.cpp ('k') | bench/GrOrderedSetBench.cpp » ('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 7
8 // This tests a Gr class 8 // This tests a Gr class
9 #if SK_SUPPORT_GPU 9 #if SK_SUPPORT_GPU
10 10
11 #include "Benchmark.h"
11 #include "GrMemoryPool.h" 12 #include "GrMemoryPool.h"
12 #include "SkBenchmark.h"
13 #include "SkRandom.h" 13 #include "SkRandom.h"
14 #include "SkTDArray.h" 14 #include "SkTDArray.h"
15 #include "SkTemplates.h" 15 #include "SkTemplates.h"
16 16
17 // change this to 0 to compare GrMemoryPool to default new / delete 17 // change this to 0 to compare GrMemoryPool to default new / delete
18 #define OVERRIDE_NEW 1 18 #define OVERRIDE_NEW 1
19 19
20 struct A { 20 struct A {
21 int gStuff[10]; 21 int gStuff[10];
22 #if OVERRIDE_NEW 22 #if OVERRIDE_NEW
23 void* operator new (size_t size) { return gBenchPool.allocate(size); } 23 void* operator new (size_t size) { return gBenchPool.allocate(size); }
24 void operator delete (void* mem) { if (mem) { return gBenchPool.release(mem) ; } } 24 void operator delete (void* mem) { if (mem) { return gBenchPool.release(mem) ; } }
25 #endif 25 #endif
26 static GrMemoryPool gBenchPool; 26 static GrMemoryPool gBenchPool;
27 }; 27 };
28 GrMemoryPool A::gBenchPool(10 * (1 << 10), 10 * (1 << 10)); 28 GrMemoryPool A::gBenchPool(10 * (1 << 10), 10 * (1 << 10));
29 29
30 /** 30 /**
31 * This benchmark creates and deletes objects in stack order 31 * This benchmark creates and deletes objects in stack order
32 */ 32 */
33 class GrMemoryPoolBenchStack : public SkBenchmark { 33 class GrMemoryPoolBenchStack : public Benchmark {
34 public: 34 public:
35 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { 35 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
36 return backend == kNonRendering_Backend; 36 return backend == kNonRendering_Backend;
37 } 37 }
38 38
39 protected: 39 protected:
40 virtual const char* onGetName() { 40 virtual const char* onGetName() {
41 return "grmemorypool_stack"; 41 return "grmemorypool_stack";
42 } 42 }
43 43
(...skipping 25 matching lines...) Expand all
69 objects[count] = new A; 69 objects[count] = new A;
70 ++count; 70 ++count;
71 } 71 }
72 } 72 }
73 for (int i = 0; i < count; ++i) { 73 for (int i = 0; i < count; ++i) {
74 delete objects[i]; 74 delete objects[i];
75 } 75 }
76 } 76 }
77 77
78 private: 78 private:
79 typedef SkBenchmark INHERITED; 79 typedef Benchmark INHERITED;
80 }; 80 };
81 81
82 struct B { 82 struct B {
83 int gStuff[10]; 83 int gStuff[10];
84 #if OVERRIDE_NEW 84 #if OVERRIDE_NEW
85 void* operator new (size_t size) { return gBenchPool.allocate(size); } 85 void* operator new (size_t size) { return gBenchPool.allocate(size); }
86 void operator delete (void* mem) { if (mem) { return gBenchPool.release(mem) ; } } 86 void operator delete (void* mem) { if (mem) { return gBenchPool.release(mem) ; } }
87 #endif 87 #endif
88 static GrMemoryPool gBenchPool; 88 static GrMemoryPool gBenchPool;
89 }; 89 };
90 GrMemoryPool B::gBenchPool(10 * (1 << 10), 10 * (1 << 10)); 90 GrMemoryPool B::gBenchPool(10 * (1 << 10), 10 * (1 << 10));
91 91
92 /** 92 /**
93 * This benchmark creates objects and deletes them in random order 93 * This benchmark creates objects and deletes them in random order
94 */ 94 */
95 class GrMemoryPoolBenchRandom : public SkBenchmark { 95 class GrMemoryPoolBenchRandom : public Benchmark {
96 public: 96 public:
97 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { 97 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
98 return backend == kNonRendering_Backend; 98 return backend == kNonRendering_Backend;
99 } 99 }
100 100
101 protected: 101 protected:
102 virtual const char* onGetName() { 102 virtual const char* onGetName() {
103 return "grmemorypool_random"; 103 return "grmemorypool_random";
104 } 104 }
105 105
106 virtual void onDraw(const int loops, SkCanvas*) { 106 virtual void onDraw(const int loops, SkCanvas*) {
107 SkRandom r; 107 SkRandom r;
108 enum { 108 enum {
109 kMaxObjects = 4 * (1 << 10), 109 kMaxObjects = 4 * (1 << 10),
110 }; 110 };
111 SkAutoTDelete<B> objects[kMaxObjects]; 111 SkAutoTDelete<B> objects[kMaxObjects];
112 112
113 for (int i = 0; i < loops; i++) { 113 for (int i = 0; i < loops; i++) {
114 uint32_t idx = r.nextRangeU(0, kMaxObjects-1); 114 uint32_t idx = r.nextRangeU(0, kMaxObjects-1);
115 if (NULL == objects[idx].get()) { 115 if (NULL == objects[idx].get()) {
116 objects[idx].reset(new B); 116 objects[idx].reset(new B);
117 } else { 117 } else {
118 objects[idx].free(); 118 objects[idx].free();
119 } 119 }
120 } 120 }
121 } 121 }
122 122
123 private: 123 private:
124 typedef SkBenchmark INHERITED; 124 typedef Benchmark INHERITED;
125 }; 125 };
126 126
127 struct C { 127 struct C {
128 int gStuff[10]; 128 int gStuff[10];
129 #if OVERRIDE_NEW 129 #if OVERRIDE_NEW
130 void* operator new (size_t size) { return gBenchPool.allocate(size); } 130 void* operator new (size_t size) { return gBenchPool.allocate(size); }
131 void operator delete (void* mem) { if (mem) { return gBenchPool.release(mem) ; } } 131 void operator delete (void* mem) { if (mem) { return gBenchPool.release(mem) ; } }
132 #endif 132 #endif
133 static GrMemoryPool gBenchPool; 133 static GrMemoryPool gBenchPool;
134 }; 134 };
135 GrMemoryPool C::gBenchPool(10 * (1 << 10), 10 * (1 << 10)); 135 GrMemoryPool C::gBenchPool(10 * (1 << 10), 10 * (1 << 10));
136 136
137 /** 137 /**
138 * This benchmark creates objects and deletes them in queue order 138 * This benchmark creates objects and deletes them in queue order
139 */ 139 */
140 class GrMemoryPoolBenchQueue : public SkBenchmark { 140 class GrMemoryPoolBenchQueue : public Benchmark {
141 enum { 141 enum {
142 M = 4 * (1 << 10), 142 M = 4 * (1 << 10),
143 }; 143 };
144 public: 144 public:
145 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { 145 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
146 return backend == kNonRendering_Backend; 146 return backend == kNonRendering_Backend;
147 } 147 }
148 148
149 protected: 149 protected:
150 virtual const char* onGetName() { 150 virtual const char* onGetName() {
151 return "grmemorypool_queue"; 151 return "grmemorypool_queue";
152 } 152 }
153 153
154 virtual void onDraw(const int loops, SkCanvas*) { 154 virtual void onDraw(const int loops, SkCanvas*) {
155 SkRandom r; 155 SkRandom r;
156 C* objects[M]; 156 C* objects[M];
157 for (int i = 0; i < loops; i++) { 157 for (int i = 0; i < loops; i++) {
158 uint32_t count = r.nextRangeU(0, M-1); 158 uint32_t count = r.nextRangeU(0, M-1);
159 for (uint32_t i = 0; i < count; i++) { 159 for (uint32_t i = 0; i < count; i++) {
160 objects[i] = new C; 160 objects[i] = new C;
161 } 161 }
162 for (uint32_t i = 0; i < count; i++) { 162 for (uint32_t i = 0; i < count; i++) {
163 delete objects[i]; 163 delete objects[i];
164 } 164 }
165 } 165 }
166 } 166 }
167 167
168 private: 168 private:
169 typedef SkBenchmark INHERITED; 169 typedef Benchmark INHERITED;
170 }; 170 };
171 171
172 /////////////////////////////////////////////////////////////////////////////// 172 ///////////////////////////////////////////////////////////////////////////////
173 173
174 DEF_BENCH( return new GrMemoryPoolBenchStack(); ) 174 DEF_BENCH( return new GrMemoryPoolBenchStack(); )
175 DEF_BENCH( return new GrMemoryPoolBenchRandom(); ) 175 DEF_BENCH( return new GrMemoryPoolBenchRandom(); )
176 DEF_BENCH( return new GrMemoryPoolBenchQueue(); ) 176 DEF_BENCH( return new GrMemoryPoolBenchQueue(); )
177 177
178 #endif 178 #endif
OLDNEW
« no previous file with comments | « bench/GameBench.cpp ('k') | bench/GrOrderedSetBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698