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 "SkBenchmark.h" | 8 #include "Benchmark.h" |
9 #include "SkRandom.h" | 9 #include "SkRandom.h" |
| 10 #include "SkString.h" |
10 #include "SkTSort.h" | 11 #include "SkTSort.h" |
11 #include "SkString.h" | |
12 | 12 |
13 static const int N = 1000; | 13 static const int N = 1000; |
14 | 14 |
15 static void rand_proc(int array[N]) { | 15 static void rand_proc(int array[N]) { |
16 SkRandom rand; | 16 SkRandom rand; |
17 for (int i = 0; i < N; ++i) { | 17 for (int i = 0; i < N; ++i) { |
18 array[i] = rand.nextS(); | 18 array[i] = rand.nextS(); |
19 } | 19 } |
20 } | 20 } |
21 | 21 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 89 |
90 static const struct { | 90 static const struct { |
91 const char* fName; | 91 const char* fName; |
92 SortProc fProc; | 92 SortProc fProc; |
93 } gSorts[] = { | 93 } gSorts[] = { |
94 { "skqsort", skqsort_sort }, | 94 { "skqsort", skqsort_sort }, |
95 { "skheap", skheap_sort }, | 95 { "skheap", skheap_sort }, |
96 { "qsort", qsort_sort }, | 96 { "qsort", qsort_sort }, |
97 }; | 97 }; |
98 | 98 |
99 class SortBench : public SkBenchmark { | 99 class SortBench : public Benchmark { |
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 |
(...skipping 19 matching lines...) Expand all Loading... |
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 } |
136 } | 136 } |
137 | 137 |
138 private: | 138 private: |
139 typedef SkBenchmark INHERITED; | 139 typedef Benchmark INHERITED; |
140 }; | 140 }; |
141 | 141 |
142 /////////////////////////////////////////////////////////////////////////////// | 142 /////////////////////////////////////////////////////////////////////////////// |
143 | 143 |
144 static SkBenchmark* NewSkQSort(Type t) { | 144 static Benchmark* NewSkQSort(Type t) { |
145 return new SortBench(t, kSKQSort); | 145 return new SortBench(t, kSKQSort); |
146 } | 146 } |
147 static SkBenchmark* NewSkHeap(Type t) { | 147 static Benchmark* NewSkHeap(Type t) { |
148 return new SortBench(t, kSKHeap); | 148 return new SortBench(t, kSKHeap); |
149 } | 149 } |
150 static SkBenchmark* NewQSort(Type t) { | 150 static Benchmark* NewQSort(Type t) { |
151 return new SortBench(t, kQSort); | 151 return new SortBench(t, kQSort); |
152 } | 152 } |
153 | 153 |
154 DEF_BENCH( return NewSkQSort(kRand); ) | 154 DEF_BENCH( return NewSkQSort(kRand); ) |
155 DEF_BENCH( return NewSkHeap(kRand); ) | 155 DEF_BENCH( return NewSkHeap(kRand); ) |
156 DEF_BENCH( return NewQSort(kRand); ) | 156 DEF_BENCH( return NewQSort(kRand); ) |
157 | 157 |
158 DEF_BENCH( return NewSkQSort(kRandN); ) | 158 DEF_BENCH( return NewSkQSort(kRandN); ) |
159 DEF_BENCH( return NewSkHeap(kRandN); ) | 159 DEF_BENCH( return NewSkHeap(kRandN); ) |
160 DEF_BENCH( return NewQSort(kRandN); ) | 160 DEF_BENCH( return NewQSort(kRandN); ) |
161 | 161 |
162 DEF_BENCH( return NewSkQSort(kFore); ) | 162 DEF_BENCH( return NewSkQSort(kFore); ) |
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 |