OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "Benchmark.h" | 8 #include "Benchmark.h" |
9 #include "SkRandom.h" | 9 #include "SkRandom.h" |
10 #include "SkString.h" | 10 #include "SkString.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 SkString fName; | 100 SkString fName; |
101 const Type fType; | 101 const Type fType; |
102 const SortProc fSortProc; | 102 const SortProc fSortProc; |
103 SkAutoTMalloc<int> fUnsorted; | 103 SkAutoTMalloc<int> fUnsorted; |
104 | 104 |
105 public: | 105 public: |
106 SortBench(Type t, SortType s) : fType(t), fSortProc(gSorts[s].fProc) { | 106 SortBench(Type t, SortType s) : fType(t), fSortProc(gSorts[s].fProc) { |
107 fName.printf("sort_%s_%s", gSorts[s].fName, gRec[t].fName); | 107 fName.printf("sort_%s_%s", gSorts[s].fName, gRec[t].fName); |
108 } | 108 } |
109 | 109 |
110 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { | 110 bool isSuitableFor(Backend backend) SK_OVERRIDE { |
111 return backend == kNonRendering_Backend; | 111 return backend == kNonRendering_Backend; |
112 } | 112 } |
113 | 113 |
114 protected: | 114 protected: |
115 virtual const char* onGetName() SK_OVERRIDE { | 115 const char* onGetName() SK_OVERRIDE { |
116 return fName.c_str(); | 116 return fName.c_str(); |
117 } | 117 } |
118 | 118 |
119 // Delayed initialization only done if onDraw will be called. | 119 // Delayed initialization only done if onDraw will be called. |
120 virtual void onPreDraw() SK_OVERRIDE { | 120 void onPreDraw() SK_OVERRIDE { |
121 fUnsorted.reset(N); | 121 fUnsorted.reset(N); |
122 gRec[fType].fProc(fUnsorted.get()); | 122 gRec[fType].fProc(fUnsorted.get()); |
123 } | 123 } |
124 | 124 |
125 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { | 125 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { |
126 SkAutoTMalloc<int> sorted(N); | 126 SkAutoTMalloc<int> sorted(N); |
127 for (int i = 0; i < loops; i++) { | 127 for (int i = 0; i < loops; i++) { |
128 memcpy(sorted.get(), fUnsorted.get(), N*sizeof(int)); | 128 memcpy(sorted.get(), fUnsorted.get(), N*sizeof(int)); |
129 fSortProc(sorted.get()); | 129 fSortProc(sorted.get()); |
130 #ifdef SK_DEBUG | 130 #ifdef SK_DEBUG |
131 for (int j = 1; j < N; ++j) { | 131 for (int j = 1; j < N; ++j) { |
132 SkASSERT(sorted[j - 1] <= sorted[j]); | 132 SkASSERT(sorted[j - 1] <= sorted[j]); |
133 } | 133 } |
134 #endif | 134 #endif |
135 } | 135 } |
(...skipping 27 matching lines...) Expand all Loading... |
163 DEF_BENCH( return NewSkHeap(kFore); ) | 163 DEF_BENCH( return NewSkHeap(kFore); ) |
164 DEF_BENCH( return NewQSort(kFore); ) | 164 DEF_BENCH( return NewQSort(kFore); ) |
165 | 165 |
166 DEF_BENCH( return NewSkQSort(kBack); ) | 166 DEF_BENCH( return NewSkQSort(kBack); ) |
167 DEF_BENCH( return NewSkHeap(kBack); ) | 167 DEF_BENCH( return NewSkHeap(kBack); ) |
168 DEF_BENCH( return NewQSort(kBack); ) | 168 DEF_BENCH( return NewQSort(kBack); ) |
169 | 169 |
170 DEF_BENCH( return NewSkQSort(kSame); ) | 170 DEF_BENCH( return NewSkQSort(kSame); ) |
171 DEF_BENCH( return NewSkHeap(kSame); ) | 171 DEF_BENCH( return NewSkHeap(kSame); ) |
172 DEF_BENCH( return NewQSort(kSame); ) | 172 DEF_BENCH( return NewQSort(kSame); ) |
OLD | NEW |