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

Side by Side Diff: bench/GrMemoryPoolBench.cpp

Issue 23478013: Major bench refactoring. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: merge with head agani Created 7 years, 3 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 | « bench/GameBench.cpp ('k') | bench/GradientBench.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
(...skipping 16 matching lines...) Expand all
27 static GrMemoryPool gPool; 27 static GrMemoryPool gPool;
28 }; 28 };
29 GrMemoryPool A::gPool(10 * (1 << 10), 10 * (1 << 10)); 29 GrMemoryPool A::gPool(10 * (1 << 10), 10 * (1 << 10));
30 } 30 }
31 31
32 32
33 /** 33 /**
34 * This benchmark creates and deletes objects in stack order 34 * This benchmark creates and deletes objects in stack order
35 */ 35 */
36 class GrMemoryPoolBenchStack : public SkBenchmark { 36 class GrMemoryPoolBenchStack : public SkBenchmark {
37 enum {
38 N = SkBENCHLOOP(1 * (1 << 20)),
39 };
40 public: 37 public:
41 GrMemoryPoolBenchStack(void* param) : INHERITED(param) { 38 GrMemoryPoolBenchStack(void* param) : INHERITED(param) {
42 fIsRendering = false; 39 fIsRendering = false;
43 } 40 }
44 protected: 41 protected:
45 virtual const char* onGetName() { 42 virtual const char* onGetName() {
46 return "grmemorypool_stack"; 43 return "grmemorypool_stack";
47 } 44 }
48 45
49 virtual void onDraw(SkCanvas*) { 46 virtual void onDraw(SkCanvas*) {
50 SkRandom r; 47 SkRandom r;
51 enum { 48 enum {
52 kMaxObjects = 4 * (1 << 10), 49 kMaxObjects = 4 * (1 << 10),
53 }; 50 };
54 A* objects[kMaxObjects]; 51 A* objects[kMaxObjects];
55 52
56 // We delete if a random [-1, 1] fixed pt is < the thresh. Otherwise, 53 // We delete if a random [-1, 1] fixed pt is < the thresh. Otherwise,
57 // we allocate. We start allocate-biased and ping-pong to delete-biased 54 // we allocate. We start allocate-biased and ping-pong to delete-biased
58 SkFixed delThresh = -SK_FixedHalf; 55 SkFixed delThresh = -SK_FixedHalf;
59 enum { 56 const int kSwitchThreshPeriod = this->getLoops() / (2 * kMaxObjects);
60 kSwitchThreshPeriod = N / (2 * kMaxObjects),
61 };
62 int s = 0; 57 int s = 0;
63 58
64 int count = 0; 59 int count = 0;
65 for (int i = 0; i < N; i++, ++s) { 60 for (int i = 0; i < this->getLoops(); i++, ++s) {
66 if (kSwitchThreshPeriod == s) { 61 if (kSwitchThreshPeriod == s) {
67 delThresh = -delThresh; 62 delThresh = -delThresh;
68 s = 0; 63 s = 0;
69 } 64 }
70 SkFixed del = r.nextSFixed1(); 65 SkFixed del = r.nextSFixed1();
71 if (count && 66 if (count &&
72 (kMaxObjects == count || del < delThresh)) { 67 (kMaxObjects == count || del < delThresh)) {
73 delete objects[count-1]; 68 delete objects[count-1];
74 --count; 69 --count;
75 } else { 70 } else {
76 objects[count] = new A; 71 objects[count] = new A;
77 ++count; 72 ++count;
78 } 73 }
79 } 74 }
80 for (int i = 0; i < count; ++i) { 75 for (int i = 0; i < count; ++i) {
81 delete objects[i]; 76 delete objects[i];
82 } 77 }
83 } 78 }
84 79
85 private: 80 private:
86 typedef SkBenchmark INHERITED; 81 typedef SkBenchmark INHERITED;
87 }; 82 };
88 83
89 /** 84 /**
90 * This benchmark creates objects and deletes them in random order 85 * This benchmark creates objects and deletes them in random order
91 */ 86 */
92 class GrMemoryPoolBenchRandom : public SkBenchmark { 87 class GrMemoryPoolBenchRandom : public SkBenchmark {
93 enum {
94 N = SkBENCHLOOP(1 * (1 << 20)),
95 };
96 public: 88 public:
97 GrMemoryPoolBenchRandom(void* param) : INHERITED(param) { 89 GrMemoryPoolBenchRandom(void* param) : INHERITED(param) {
98 fIsRendering = false; 90 fIsRendering = false;
99 } 91 }
100 protected: 92 protected:
101 virtual const char* onGetName() { 93 virtual const char* onGetName() {
102 return "grmemorypool_random"; 94 return "grmemorypool_random";
103 } 95 }
104 96
105 virtual void onDraw(SkCanvas*) { 97 virtual void onDraw(SkCanvas*) {
106 SkRandom r; 98 SkRandom r;
107 enum { 99 enum {
108 kMaxObjects = 4 * (1 << 10), 100 kMaxObjects = 4 * (1 << 10),
109 }; 101 };
110 SkAutoTDelete<A> objects[kMaxObjects]; 102 SkAutoTDelete<A> objects[kMaxObjects];
111 103
112 for (int i = 0; i < N; i++) { 104 for (int i = 0; i < this->getLoops(); i++) {
113 uint32_t idx = r.nextRangeU(0, kMaxObjects-1); 105 uint32_t idx = r.nextRangeU(0, kMaxObjects-1);
114 if (NULL == objects[idx].get()) { 106 if (NULL == objects[idx].get()) {
115 objects[idx].reset(new A); 107 objects[idx].reset(new A);
116 } else { 108 } else {
117 objects[idx].free(); 109 objects[idx].free();
118 } 110 }
119 } 111 }
120 } 112 }
121 113
122 private: 114 private:
123 typedef SkBenchmark INHERITED; 115 typedef SkBenchmark INHERITED;
124 }; 116 };
125 117
126 /** 118 /**
127 * This benchmark creates objects and deletes them in queue order 119 * This benchmark creates objects and deletes them in queue order
128 */ 120 */
129 class GrMemoryPoolBenchQueue : public SkBenchmark { 121 class GrMemoryPoolBenchQueue : public SkBenchmark {
130 enum { 122 enum {
131 N = SkBENCHLOOP((1 << 8)), 123 M = 4 * (1 << 10),
132 M = SkBENCHLOOP(4 * (1 << 10)),
133 }; 124 };
134 public: 125 public:
135 GrMemoryPoolBenchQueue(void* param) : INHERITED(param) { 126 GrMemoryPoolBenchQueue(void* param) : INHERITED(param) {
136 fIsRendering = false; 127 fIsRendering = false;
137 } 128 }
138 protected: 129 protected:
139 virtual const char* onGetName() { 130 virtual const char* onGetName() {
140 return "grmemorypool_queue"; 131 return "grmemorypool_queue";
141 } 132 }
142 133
143 virtual void onDraw(SkCanvas*) { 134 virtual void onDraw(SkCanvas*) {
144 SkRandom r; 135 SkRandom r;
145 A* objects[M]; 136 A* objects[M];
146 for (int i = 0; i < N; i++) { 137 for (int i = 0; i < this->getLoops(); i++) {
147 uint32_t count = r.nextRangeU(0, M-1); 138 uint32_t count = r.nextRangeU(0, M-1);
148 for (uint32_t i = 0; i < count; i++) { 139 for (uint32_t i = 0; i < count; i++) {
149 objects[i] = new A; 140 objects[i] = new A;
150 } 141 }
151 for (uint32_t i = 0; i < count; i++) { 142 for (uint32_t i = 0; i < count; i++) {
152 delete objects[i]; 143 delete objects[i];
153 } 144 }
154 } 145 }
155 } 146 }
156 147
157 private: 148 private:
158 typedef SkBenchmark INHERITED; 149 typedef SkBenchmark INHERITED;
159 }; 150 };
160 151
161 /////////////////////////////////////////////////////////////////////////////// 152 ///////////////////////////////////////////////////////////////////////////////
162 153
163 static SkBenchmark* Fact1(void* p) { return new GrMemoryPoolBenchStack(p); } 154 static SkBenchmark* Fact1(void* p) { return new GrMemoryPoolBenchStack(p); }
164 static SkBenchmark* Fact2(void* p) { return new GrMemoryPoolBenchRandom(p); } 155 static SkBenchmark* Fact2(void* p) { return new GrMemoryPoolBenchRandom(p); }
165 static SkBenchmark* Fact3(void* p) { return new GrMemoryPoolBenchQueue(p); } 156 static SkBenchmark* Fact3(void* p) { return new GrMemoryPoolBenchQueue(p); }
166 157
167 static BenchRegistry gReg01(Fact1); 158 static BenchRegistry gReg01(Fact1);
168 static BenchRegistry gReg02(Fact2); 159 static BenchRegistry gReg02(Fact2);
169 static BenchRegistry gReg03(Fact3); 160 static BenchRegistry gReg03(Fact3);
170 161
171 #endif 162 #endif
OLDNEW
« no previous file with comments | « bench/GameBench.cpp ('k') | bench/GradientBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698