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

Side by Side Diff: webrtc/system_wrappers/test/TestSort/TestSort.cc

Issue 1888593004: Delete all use of tick_util.h. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase. Created 4 years, 7 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
« no previous file with comments | « webrtc/system_wrappers/system_wrappers.gyp ('k') | webrtc/video/call_stats.cc » ('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 (c) 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <stdio.h> 11 #include <stdio.h>
12 #include <string.h> 12 #include <string.h>
13 13
14 #include <algorithm> 14 #include <algorithm>
15 15
16 #include "webrtc/base/timeutils.h"
16 #include "webrtc/system_wrappers/include/sort.h" 17 #include "webrtc/system_wrappers/include/sort.h"
17 #include "webrtc/system_wrappers/include/tick_util.h"
18 18
19 // Excellent work polluting the global namespace Visual Studio... 19 // Excellent work polluting the global namespace Visual Studio...
20 #undef max 20 #undef max
21 #undef min 21 #undef min
22 #include <limits> 22 #include <limits>
23 23
24 template<typename KeyType> 24 template<typename KeyType>
25 struct LotsOfData 25 struct LotsOfData
26 { 26 {
27 KeyType key; 27 KeyType key;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 137
138 if (keySort) 138 if (keySort)
139 { 139 {
140 printf("Running %s KeySort() tests...\n", TypeEnumToString(sortType)); 140 printf("Running %s KeySort() tests...\n", TypeEnumToString(sortType));
141 } 141 }
142 else 142 else
143 { 143 {
144 printf("Running %s Sort() tests...\n", TypeEnumToString(sortType)); 144 printf("Running %s Sort() tests...\n", TypeEnumToString(sortType));
145 } 145 }
146 146
147 TickInterval accTicks; 147 int64_t accTicks;
148 for (int i = 0; i < NumOfTests; i++) 148 for (int i = 0; i < NumOfTests; i++)
149 { 149 {
150 for (int j = 0; j < DataLength; j++) 150 for (int j = 0; j < DataLength; j++)
151 { 151 {
152 key[j] = TypedRand<KeyType>(); 152 key[j] = TypedRand<KeyType>();
153 data[j].key = key[j]; 153 data[j].key = key[j];
154 // Write index to payload. We use this later for verification. 154 // Write index to payload. We use this later for verification.
155 sprintf(data[j].data, "%d", j); 155 sprintf(data[j].data, "%d", j);
156 } 156 }
157 157
158 memcpy(dataRef, data, sizeof(data)); 158 memcpy(dataRef, data, sizeof(data));
159 memcpy(keyRef, key, sizeof(key)); 159 memcpy(keyRef, key, sizeof(key));
160 160
161 retVal = 0; 161 retVal = 0;
162 TickTime t0 = TickTime::Now(); 162 int64_t t0 = rtc::TimeNanos();
163 if (keySort) 163 if (keySort)
164 { 164 {
165 retVal = webrtc::KeySort(data, key, DataLength, sizeof(LotsOfData<Ke yType>), 165 retVal = webrtc::KeySort(data, key, DataLength, sizeof(LotsOfData<Ke yType>),
166 sortType); 166 sortType);
167 167
168 //std::sort(data, data + DataLength, KeyLessThan<KeyType>()); 168 //std::sort(data, data + DataLength, KeyLessThan<KeyType>());
169 //qsort(data, DataLength, sizeof(LotsOfData<KeyType>), 169 //qsort(data, DataLength, sizeof(LotsOfData<KeyType>),
170 // CompareKey<LotsOfData<KeyType>, KeyType>); 170 // CompareKey<LotsOfData<KeyType>, KeyType>);
171 } 171 }
172 else 172 else
173 { 173 {
174 retVal = webrtc::Sort(key, DataLength, sortType); 174 retVal = webrtc::Sort(key, DataLength, sortType);
175 175
176 //std::sort(key, key + DataLength); 176 //std::sort(key, key + DataLength);
177 //qsort(key, DataLength, sizeof(KeyType), Compare<KeyType>); 177 //qsort(key, DataLength, sizeof(KeyType), Compare<KeyType>);
178 } 178 }
179 TickTime t1 = TickTime::Now(); 179 int64_t t1 = rtc::TimeNanos();
180 accTicks += (t1 - t0); 180 accTicks += (t1 - t0);
181 181
182 if (retVal != 0) 182 if (retVal != 0)
183 { 183 {
184 printf("Test failed at iteration %d:\n", i); 184 printf("Test failed at iteration %d:\n", i);
185 printf("Sort returned an error. "); 185 printf("Sort returned an error. ");
186 printf("It likely does not support the requested type\nExiting...\n" ); 186 printf("It likely does not support the requested type\nExiting...\n" );
187 exit(0); 187 exit(0);
188 } 188 }
189 189
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 { 229 {
230 printf("Test failed at iteration %d:\n", i); 230 printf("Test failed at iteration %d:\n", i);
231 printf("Sort data differs from std::sort reference\nExiting...\n "); 231 printf("Sort data differs from std::sort reference\nExiting...\n ");
232 exit(0); 232 exit(0);
233 } 233 }
234 } 234 }
235 } 235 }
236 236
237 printf("Compliance test passed over %d iterations\n", NumOfTests); 237 printf("Compliance test passed over %d iterations\n", NumOfTests);
238 238
239 int64_t executeTime = accTicks.Milliseconds(); 239 int64_t executeTime = accTicks / rtc::kNumNanosecsPerMillisec;
240 printf("Execute time: %.2f s\n\n", (float)executeTime / 1000); 240 printf("Execute time: %.2f s\n\n", (float)executeTime / 1000);
241 } 241 }
242 242
243 int main() 243 int main()
244 { 244 {
245 // Seed rand(). 245 // Seed rand().
246 srand(42); 246 srand(42);
247 bool keySort = false; 247 bool keySort = false;
248 for (int i = 0; i < 2; i++) { 248 for (int i = 0; i < 2; i++) {
249 RunSortTest<int8_t>(webrtc::TYPE_Word8, keySort); 249 RunSortTest<int8_t>(webrtc::TYPE_Word8, keySort);
250 RunSortTest<uint8_t>(webrtc::TYPE_UWord8, keySort); 250 RunSortTest<uint8_t>(webrtc::TYPE_UWord8, keySort);
251 RunSortTest<int16_t>(webrtc::TYPE_Word16, keySort); 251 RunSortTest<int16_t>(webrtc::TYPE_Word16, keySort);
252 RunSortTest<uint16_t>(webrtc::TYPE_UWord16, keySort); 252 RunSortTest<uint16_t>(webrtc::TYPE_UWord16, keySort);
253 RunSortTest<int32_t>(webrtc::TYPE_Word32, keySort); 253 RunSortTest<int32_t>(webrtc::TYPE_Word32, keySort);
254 RunSortTest<uint32_t>(webrtc::TYPE_UWord32, keySort); 254 RunSortTest<uint32_t>(webrtc::TYPE_UWord32, keySort);
255 RunSortTest<int64_t>(webrtc::TYPE_Word64, keySort); 255 RunSortTest<int64_t>(webrtc::TYPE_Word64, keySort);
256 RunSortTest<uint64_t>(webrtc::TYPE_UWord64, keySort); 256 RunSortTest<uint64_t>(webrtc::TYPE_UWord64, keySort);
257 RunSortTest<float>(webrtc::TYPE_Float32, keySort); 257 RunSortTest<float>(webrtc::TYPE_Float32, keySort);
258 RunSortTest<double>(webrtc::TYPE_Float64, keySort); 258 RunSortTest<double>(webrtc::TYPE_Float64, keySort);
259 259
260 keySort = !keySort; 260 keySort = !keySort;
261 } 261 }
262 262
263 printf("All tests passed\n"); 263 printf("All tests passed\n");
264 264
265 return 0; 265 return 0;
266 } 266 }
OLDNEW
« no previous file with comments | « webrtc/system_wrappers/system_wrappers.gyp ('k') | webrtc/video/call_stats.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698