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 "SkBenchmark.h" | 8 #include "Benchmark.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkChunkAlloc.h" |
10 #include "SkPaint.h" | 11 #include "SkPaint.h" |
11 #include "SkRandom.h" | 12 #include "SkRandom.h" |
12 #include "SkChunkAlloc.h" | |
13 #include "SkString.h" | 13 #include "SkString.h" |
14 | 14 |
15 class ChunkAllocBench : public SkBenchmark { | 15 class ChunkAllocBench : public Benchmark { |
16 SkString fName; | 16 SkString fName; |
17 size_t fMinSize; | 17 size_t fMinSize; |
18 public: | 18 public: |
19 ChunkAllocBench(size_t minSize) { | 19 ChunkAllocBench(size_t minSize) { |
20 fMinSize = minSize; | 20 fMinSize = minSize; |
21 fName.printf("chunkalloc_" SK_SIZE_T_SPECIFIER, minSize); | 21 fName.printf("chunkalloc_" SK_SIZE_T_SPECIFIER, minSize); |
22 } | 22 } |
23 | 23 |
24 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { | 24 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { |
25 return backend == kNonRendering_Backend; | 25 return backend == kNonRendering_Backend; |
(...skipping 17 matching lines...) Expand all Loading... |
43 while (size < total) { | 43 while (size < total) { |
44 alloc.allocThrow(inc); | 44 alloc.allocThrow(inc); |
45 size += inc; | 45 size += inc; |
46 calls += 1; | 46 calls += 1; |
47 } | 47 } |
48 alloc.reset(); | 48 alloc.reset(); |
49 } | 49 } |
50 } | 50 } |
51 | 51 |
52 private: | 52 private: |
53 typedef SkBenchmark 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) { | 59 static int* calloc(size_t num) { |
60 return (int*)sk_calloc_throw(num*sizeof(int)); | 60 return (int*)sk_calloc_throw(num*sizeof(int)); |
61 } | 61 } |
62 | 62 |
63 static int* malloc_bzero(size_t num) { | 63 static int* malloc_bzero(size_t num) { |
64 const size_t bytes = num*sizeof(int); | 64 const size_t bytes = num*sizeof(int); |
65 int* ints = (int*)sk_malloc_throw(bytes); | 65 int* ints = (int*)sk_malloc_throw(bytes); |
66 sk_bzero(ints, bytes); | 66 sk_bzero(ints, bytes); |
67 return ints; | 67 return ints; |
68 } | 68 } |
69 | 69 |
70 class ZerosBench : public SkBenchmark { | 70 class ZerosBench : public Benchmark { |
71 size_t fNum; | 71 size_t fNum; |
72 bool fRead; | 72 bool fRead; |
73 bool fWrite; | 73 bool fWrite; |
74 bool fUseCalloc; | 74 bool fUseCalloc; |
75 SkString fName; | 75 SkString fName; |
76 public: | 76 public: |
77 ZerosBench(size_t num, bool read, bool write, bool useCalloc) | 77 ZerosBench(size_t num, bool read, bool write, bool useCalloc) |
78 : fNum(num) | 78 : fNum(num) |
79 , fRead(read) | 79 , fRead(read) |
80 , fWrite(write) | 80 , fWrite(write) |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 DEF_BENCH(return new ZerosBench(300, 1, 1, 1)) | 156 DEF_BENCH(return new ZerosBench(300, 1, 1, 1)) |
157 | 157 |
158 DEF_BENCH(return new ZerosBench(4, 0, 0, 0)) | 158 DEF_BENCH(return new ZerosBench(4, 0, 0, 0)) |
159 DEF_BENCH(return new ZerosBench(4, 0, 0, 1)) | 159 DEF_BENCH(return new ZerosBench(4, 0, 0, 1)) |
160 DEF_BENCH(return new ZerosBench(4, 0, 1, 0)) | 160 DEF_BENCH(return new ZerosBench(4, 0, 1, 0)) |
161 DEF_BENCH(return new ZerosBench(4, 0, 1, 1)) | 161 DEF_BENCH(return new ZerosBench(4, 0, 1, 1)) |
162 DEF_BENCH(return new ZerosBench(4, 1, 0, 0)) | 162 DEF_BENCH(return new ZerosBench(4, 1, 0, 0)) |
163 DEF_BENCH(return new ZerosBench(4, 1, 0, 1)) | 163 DEF_BENCH(return new ZerosBench(4, 1, 0, 1)) |
164 DEF_BENCH(return new ZerosBench(4, 1, 1, 0)) | 164 DEF_BENCH(return new ZerosBench(4, 1, 1, 0)) |
165 DEF_BENCH(return new ZerosBench(4, 1, 1, 1)) | 165 DEF_BENCH(return new ZerosBench(4, 1, 1, 1)) |
OLD | NEW |