aboutsummaryrefslogtreecommitdiff
path: root/tests/qsort/benchmark.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-08-05 14:00:16 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-08-05 14:00:16 -0700
commit1b7122c6aaa19cb6e2a62598dca8e0fd9e3cc7a7 (patch)
tree659d33c0fcfa4f6ae3afaae9808649e4021979b7 /tests/qsort/benchmark.cpp
parent6039aea9a13ea217301c2c19eca3e857dc2dace7 (diff)
parenta0c6ab57cb11258df23dd670aebdc260d9e16da3 (diff)
Merge branch 'incoming'
Diffstat (limited to 'tests/qsort/benchmark.cpp')
-rw-r--r--tests/qsort/benchmark.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/qsort/benchmark.cpp b/tests/qsort/benchmark.cpp
new file mode 100644
index 00000000..950ca437
--- /dev/null
+++ b/tests/qsort/benchmark.cpp
@@ -0,0 +1,43 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+
+typedef unsigned int uint32;
+
+int cmp_uint(const void *i1, const void *i2) {
+ if (*static_cast<const uint32*>(i1) >
+ *static_cast<const uint32*>(i2))
+ return 1;
+
+ if (*static_cast<const uint32*>(i1) <
+ *static_cast<const uint32*>(i2))
+ return -1;
+
+ return 0;
+}
+
+int main() {
+ clock_t start = clock();
+ const size_t TIMES = 10000;
+ for (size_t i = 0; i < TIMES; i++) {
+ const size_t num = 100;
+ uint32 rnd[num] = { \
+ 407, 236, 765, 529, 24, 13, 577, 900, 242, 245, \
+ 782, 972, 514, 100, 596, 470, 680, 65, 370, 788, \
+ 44, 330, 579, 314, 914, 399, 100, 945, 992, 412, \
+ 308, 102, 895, 529, 216, 422, 851, 778, 28, 804, \
+ 325, 975, 961, 623, 922, 667, 141, 755, 416, 575, \
+ 712, 503, 174, 675, 14, 647, 544, 881, 858, 621, \
+ 26, 283, 460, 252, 146, 16, 571, 570, 14, 143, \
+ 674, 985, 477, 386, 932, 490, 611, 127, 702, 619, \
+ 104, 892, 58, 635, 663, 424, 714, 740, 229, 538, \
+ 167, 181, 193, 193, 657, 778, 217, 573, 764, 745};
+
+ qsort(rnd, num, sizeof(uint32), cmp_uint);
+ }
+ clock_t end = clock();
+
+ float diff = (((float)end - (float)start) / CLOCKS_PER_SEC ) * 1000;
+ printf("cost %fms\n", diff);
+}
+