diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-08-01 16:20:27 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-08-01 16:20:27 -0700 |
commit | 3cff82da6afdc1b377f081d84b463581624f5e02 (patch) | |
tree | b13ed1619e549e37eac877fba33fe5ec810cdae0 | |
parent | 19d109d8eff8fe5a153d5b8536f3cbee7ac10557 (diff) | |
parent | ad2bd9af8354849c88254dc01f20fd96549a796f (diff) |
Merge branch 'qsort_reduce_callchain' of github.com:PinZhang/emscripten into incoming
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | src/library.js | 6 | ||||
-rw-r--r-- | tests/qsort/benchmark.cpp | 43 |
3 files changed, 49 insertions, 1 deletions
@@ -91,4 +91,5 @@ a license to everyone to use it as detailed in LICENSE.) * Ryan Kelly (ryan@rfk.id.au) * Michael Lelli <toadking@toadking.com> * Yu Kobayashi <yukoba@accelart.jp> +* Pin Zhang <zhangpin04@gmail.com> diff --git a/src/library.js b/src/library.js index 68addfdc..8342decf 100644 --- a/src/library.js +++ b/src/library.js @@ -4157,7 +4157,11 @@ LibraryManager.library = { var keys = []; for (var i = 0; i < num; i++) keys.push(i); keys.sort(function(a, b) { - return comparator(base+a*size, base+b*size); +#if ASM_JS + return Module['dynCall_iii'](cmp, base+a*size, base+b*size); +#else + return FUNCTION_TABLE[cmp](base+a*size, base+b*size); +#endif }); // apply the sort var temp = _malloc(num*size); 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); +} + |