OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkRandom.h" | 9 #include "SkRandom.h" |
10 | 10 |
11 #include "SkChunkAlloc.h" | 11 #include "SkChunkAlloc.h" |
12 #include "SkDeque.h" | 12 #include "SkDeque.h" |
13 #include "SkTArray.h" | 13 #include "SkTArray.h" |
14 #include "SkTDArray.h" | 14 #include "SkTDArray.h" |
15 | 15 |
16 // This file has several benchmarks using various data structures to do stack-li
ke things: | 16 // This file has several benchmarks using various data structures to do stack-li
ke things: |
17 // - push | 17 // - push |
18 // - push, immediately pop | 18 // - push, immediately pop |
19 // - push many, pop all of them | 19 // - push many, pop all of them |
20 // - serial access | 20 // - serial access |
21 // - random access | 21 // - random access |
22 // When a data structure doesn't suppport an operation efficiently, we leave tha
t combination out. | 22 // When a data structure doesn't suppport an operation efficiently, we leave tha
t combination out. |
23 // Where possible we hint to the data structure to allocate in 4K pages. | 23 // Where possible we hint to the data structure to allocate in 4K pages. |
24 // | 24 // |
25 // These benchmarks may help you decide which data structure to use for a dynami
cally allocated | 25 // These benchmarks may help you decide which data structure to use for a dynami
cally allocated |
26 // ordered list of allocations that grows on one end. | 26 // ordered list of allocations that grows on one end. |
27 // | 27 // |
28 // Current overall winner (01/2014): SkTDArray. | 28 // Current overall winner (01/2014): SkTDArray. |
29 // It wins every benchmark on every machine I tried (Desktop, Nexus S, Laptop). | 29 // It wins every benchmark on every machine I tried (Desktop, Nexus S, Laptop). |
30 | 30 |
31 template <typename Impl> | 31 template <typename Impl> |
32 struct StackBench : public SkBenchmark { | 32 struct StackBench : public Benchmark { |
33 virtual bool isSuitableFor(Backend b) SK_OVERRIDE { return b == kNonRenderin
g_Backend; } | 33 virtual bool isSuitableFor(Backend b) SK_OVERRIDE { return b == kNonRenderin
g_Backend; } |
34 virtual const char* onGetName() SK_OVERRIDE { return Impl::kName; } | 34 virtual const char* onGetName() SK_OVERRIDE { return Impl::kName; } |
35 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { Impl::bench(lo
ops); } | 35 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { Impl::bench(lo
ops); } |
36 }; | 36 }; |
37 | 37 |
38 #define BENCH(name) \ | 38 #define BENCH(name) \ |
39 struct name { static const char* const kName; static void bench(int); }; \ | 39 struct name { static const char* const kName; static void bench(int); }; \ |
40 const char* const name::kName = #name; \ | 40 const char* const name::kName = #name; \ |
41 DEF_BENCH(return new StackBench<name>();) \ | 41 DEF_BENCH(return new StackBench<name>();) \ |
42 void name::bench(int loops) | 42 void name::bench(int loops) |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 SkTArray<int, true> s; | 170 SkTArray<int, true> s; |
171 for (int i = 0; i < K*loops; i++) s.push_back(i); | 171 for (int i = 0; i < K*loops; i++) s.push_back(i); |
172 for (int i = 0; i < K*loops; i++) s.pop_back(); | 172 for (int i = 0; i < K*loops; i++) s.pop_back(); |
173 } | 173 } |
174 | 174 |
175 BENCH(TDArray_PushAllPopAll) { | 175 BENCH(TDArray_PushAllPopAll) { |
176 SkTDArray<int> s; | 176 SkTDArray<int> s; |
177 for (int i = 0; i < K*loops; i++) s.push(i); | 177 for (int i = 0; i < K*loops; i++) s.push(i); |
178 for (int i = 0; i < K*loops; i++) s.pop(); | 178 for (int i = 0; i < K*loops; i++) s.pop(); |
179 } | 179 } |
OLD | NEW |