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

Side by Side Diff: bench/GrMemoryPoolBench.cpp

Issue 13831011: use SkAutoTDelete instead of SkTScopedPtr (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | include/core/SkTemplates.h » ('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 "GrMemoryPool.h" 11 #include "GrMemoryPool.h"
12 #include "SkBenchmark.h" 12 #include "SkBenchmark.h"
13 #include "SkRandom.h" 13 #include "SkRandom.h"
14 #include "SkTScopedPtr.h"
15 #include "SkTDArray.h" 14 #include "SkTDArray.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 namespace { 20 namespace {
21 struct A { 21 struct A {
22 int gStuff[10]; 22 int gStuff[10];
23 #if OVERRIDE_NEW 23 #if OVERRIDE_NEW
24 void* operator new (size_t size) { return gPool.allocate(size); } 24 void* operator new (size_t size) { return gPool.allocate(size); }
25 void operator delete (void* mem) { if (mem) { return gPool.release(mem); } } 25 void operator delete (void* mem) { if (mem) { return gPool.release(mem); } }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 protected: 100 protected:
101 virtual const char* onGetName() { 101 virtual const char* onGetName() {
102 return "grmemorypool_random"; 102 return "grmemorypool_random";
103 } 103 }
104 104
105 virtual void onDraw(SkCanvas*) { 105 virtual void onDraw(SkCanvas*) {
106 SkRandom r; 106 SkRandom r;
107 enum { 107 enum {
108 kMaxObjects = 4 * (1 << 10), 108 kMaxObjects = 4 * (1 << 10),
109 }; 109 };
110 SkTScopedPtr<A> objects[kMaxObjects]; 110 SkAutoTDelete<A> objects[kMaxObjects];
111 111
112 for (int i = 0; i < N; i++) { 112 for (int i = 0; i < N; i++) {
113 uint32_t idx = r.nextRangeU(0, kMaxObjects-1); 113 uint32_t idx = r.nextRangeU(0, kMaxObjects-1);
114 if (NULL == objects[idx].get()) { 114 if (NULL == objects[idx].get()) {
115 objects[idx].reset(new A); 115 objects[idx].reset(new A);
116 } else { 116 } else {
117 objects[idx].reset(NULL); 117 objects[idx].free();
118 } 118 }
119 } 119 }
120 } 120 }
121 121
122 private: 122 private:
123 typedef SkBenchmark INHERITED; 123 typedef SkBenchmark INHERITED;
124 }; 124 };
125 125
126 /** 126 /**
127 * This benchmark creates objects and deletes them in queue order 127 * This benchmark creates objects and deletes them in queue order
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 162
163 static SkBenchmark* Fact1(void* p) { return new GrMemoryPoolBenchStack(p); } 163 static SkBenchmark* Fact1(void* p) { return new GrMemoryPoolBenchStack(p); }
164 static SkBenchmark* Fact2(void* p) { return new GrMemoryPoolBenchRandom(p); } 164 static SkBenchmark* Fact2(void* p) { return new GrMemoryPoolBenchRandom(p); }
165 static SkBenchmark* Fact3(void* p) { return new GrMemoryPoolBenchQueue(p); } 165 static SkBenchmark* Fact3(void* p) { return new GrMemoryPoolBenchQueue(p); }
166 166
167 static BenchRegistry gReg01(Fact1); 167 static BenchRegistry gReg01(Fact1);
168 static BenchRegistry gReg02(Fact2); 168 static BenchRegistry gReg02(Fact2);
169 static BenchRegistry gReg03(Fact3); 169 static BenchRegistry gReg03(Fact3);
170 170
171 #endif 171 #endif
OLDNEW
« no previous file with comments | « no previous file | include/core/SkTemplates.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698