File: benchmark.cpp

package info (click to toggle)
emscripten 2.0.12~dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 108,440 kB
  • sloc: ansic: 510,324; cpp: 384,763; javascript: 84,341; python: 51,362; sh: 50,019; pascal: 4,159; makefile: 3,409; asm: 2,150; lisp: 1,869; ruby: 488; cs: 142
file content (48 lines) | stat: -rw-r--r-- 1,519 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2013 The Emscripten Authors.  All rights reserved.
// Emscripten is available under two separate licenses, the MIT license and the
// University of Illinois/NCSA Open Source License.  Both these licenses can be
// found in the LICENSE file.

#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);
}