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

Side by Side Diff: bench/MemoryBench.cpp

Issue 24251008: Add sk_calloc. Remove SkMemory_stdlib, which seems unused. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: use sk_out_of_memory 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 | « no previous file | gyp/tests.gyp » ('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 #include "SkBenchmark.h" 8 #include "SkBenchmark.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkPaint.h" 10 #include "SkPaint.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 alloc.reset(); 45 alloc.reset();
46 } 46 }
47 } 47 }
48 48
49 private: 49 private:
50 typedef SkBenchmark INHERITED; 50 typedef SkBenchmark INHERITED;
51 }; 51 };
52 52
53 DEF_BENCH( return new ChunkAllocBench(64); ) 53 DEF_BENCH( return new ChunkAllocBench(64); )
54 DEF_BENCH( return new ChunkAllocBench(8*1024); ) 54 DEF_BENCH( return new ChunkAllocBench(8*1024); )
55
56 static int* calloc(size_t num) {
57 return (int*)sk_calloc_throw(num*sizeof(int));
58 }
59
60 static int* malloc_bzero(size_t num) {
61 const size_t bytes = num*sizeof(int);
62 int* ints = (int*)sk_malloc_throw(bytes);
63 sk_bzero(ints, bytes);
64 return ints;
65 }
66
67 class ZerosBench : public SkBenchmark {
68 size_t fNum;
69 bool fRead;
70 bool fWrite;
71 bool fUseCalloc;
72 SkString fName;
73 public:
74 ZerosBench(size_t num, bool read, bool write, bool useCalloc)
75 : fNum(num)
76 , fRead(read)
77 , fWrite(write)
78 , fUseCalloc(useCalloc) {
79 fName.printf("memory_%s", useCalloc ? "calloc" : "malloc_bzero");
80 if (read && write) {
81 fName.appendf("_rw");
82 } else if (read) {
83 fName.appendf("_r");
84 } else if (write) {
85 fName.appendf("_w");
86 }
87 fName.appendf("_"SK_SIZE_T_SPECIFIER, num);
88 fIsRendering = false;
89 }
90
91 protected:
92 virtual const char* onGetName() SK_OVERRIDE {
93 return fName.c_str();
94 }
95
96 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
97 for (int i = 0; i < this->getLoops(); i++) {
98 int* zeros = fUseCalloc ? calloc(fNum) : malloc_bzero(fNum);
99 if (fRead) {
100 volatile int x = 15;
101 for (size_t j = 0; j < fNum; j++) {
102 x ^= zeros[j];
103 }
104 }
105 if (fWrite) {
106 for (size_t j = 0; j < fNum; j++) {
107 zeros[j] = 15;
108 }
109 }
110 sk_free(zeros);
111 }
112 }
113 };
114
115 // zero count r w useCalloc?
116 DEF_BENCH(return new ZerosBench(1024*1024, 0, 0, 0))
117 DEF_BENCH(return new ZerosBench(1024*1024, 0, 0, 1))
118 DEF_BENCH(return new ZerosBench(1024*1024, 0, 1, 0))
119 DEF_BENCH(return new ZerosBench(1024*1024, 0, 1, 1))
120 DEF_BENCH(return new ZerosBench(1024*1024, 1, 0, 0))
121 DEF_BENCH(return new ZerosBench(1024*1024, 1, 0, 1))
122 DEF_BENCH(return new ZerosBench(1024*1024, 1, 1, 0))
123 DEF_BENCH(return new ZerosBench(1024*1024, 1, 1, 1))
124
125 DEF_BENCH(return new ZerosBench(256*1024, 0, 0, 0))
126 DEF_BENCH(return new ZerosBench(256*1024, 0, 0, 1))
127 DEF_BENCH(return new ZerosBench(256*1024, 0, 1, 0))
128 DEF_BENCH(return new ZerosBench(256*1024, 0, 1, 1))
129 DEF_BENCH(return new ZerosBench(256*1024, 1, 0, 0))
130 DEF_BENCH(return new ZerosBench(256*1024, 1, 0, 1))
131 DEF_BENCH(return new ZerosBench(256*1024, 1, 1, 0))
132 DEF_BENCH(return new ZerosBench(256*1024, 1, 1, 1))
133
134 DEF_BENCH(return new ZerosBench(4*1024, 0, 0, 0))
135 DEF_BENCH(return new ZerosBench(4*1024, 0, 0, 1))
136 DEF_BENCH(return new ZerosBench(4*1024, 0, 1, 0))
137 DEF_BENCH(return new ZerosBench(4*1024, 0, 1, 1))
138 DEF_BENCH(return new ZerosBench(4*1024, 1, 0, 0))
139 DEF_BENCH(return new ZerosBench(4*1024, 1, 0, 1))
140 DEF_BENCH(return new ZerosBench(4*1024, 1, 1, 0))
141 DEF_BENCH(return new ZerosBench(4*1024, 1, 1, 1))
142
143 DEF_BENCH(return new ZerosBench(300, 0, 0, 0))
144 DEF_BENCH(return new ZerosBench(300, 0, 0, 1))
145 DEF_BENCH(return new ZerosBench(300, 0, 1, 0))
146 DEF_BENCH(return new ZerosBench(300, 0, 1, 1))
147 DEF_BENCH(return new ZerosBench(300, 1, 0, 0))
148 DEF_BENCH(return new ZerosBench(300, 1, 0, 1))
149 DEF_BENCH(return new ZerosBench(300, 1, 1, 0))
150 DEF_BENCH(return new ZerosBench(300, 1, 1, 1))
151
152 DEF_BENCH(return new ZerosBench(4, 0, 0, 0))
153 DEF_BENCH(return new ZerosBench(4, 0, 0, 1))
154 DEF_BENCH(return new ZerosBench(4, 0, 1, 0))
155 DEF_BENCH(return new ZerosBench(4, 0, 1, 1))
156 DEF_BENCH(return new ZerosBench(4, 1, 0, 0))
157 DEF_BENCH(return new ZerosBench(4, 1, 0, 1))
158 DEF_BENCH(return new ZerosBench(4, 1, 1, 0))
159 DEF_BENCH(return new ZerosBench(4, 1, 1, 1))
OLDNEW
« no previous file with comments | « no previous file | gyp/tests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698