Sorry, it was late and I was tired.
[dyninst.git] / common / src / timing.C
1
2
3 #include "util/h/Timer.h"
4 #define NOPS_4  asm("nop"); asm("nop"); asm("nop"); asm("nop")
5 #define NOPS_16 NOPS_4; NOPS_4; NOPS_4; NOPS_4
6
7 double timing_loop(const unsigned TRIES, const unsigned LOOP_LIMIT) {
8   const double MILLION = 1.0e6;
9   int            i, j;
10   double         speed;
11   timer stopwatch;
12   double max_speed=0;
13
14   for (j=0; j<TRIES; j++) {
15     stopwatch.start();
16     for (i = 0; i < LOOP_LIMIT; i++) {
17       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
18       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
19       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
20       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
21     }
22     stopwatch.stop();
23     speed   = ((256*LOOP_LIMIT)/stopwatch.usecs())/MILLION;
24     stopwatch.clear();
25     if (speed > max_speed)
26       max_speed = speed;
27   }
28
29   for (j=0; j<TRIES; j++) {
30     stopwatch.start();
31     for (i = 0; i < LOOP_LIMIT; i++) {
32       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
33       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
34       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
35       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
36       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
37       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
38       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
39       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
40     }
41     stopwatch.stop();
42     speed   = ((512*LOOP_LIMIT)/stopwatch.usecs())/MILLION;
43     stopwatch.clear();
44     if (speed > max_speed)
45       max_speed = speed;
46   }
47
48   for (j=0; j<TRIES; j++) {
49     stopwatch.start();
50     for (i = 0; i < LOOP_LIMIT; i++) {
51       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
52       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
53       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
54       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
55       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
56       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
57       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
58       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
59       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
60       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
61       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
62       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
63       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
64       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
65       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
66       NOPS_16; NOPS_16; NOPS_16; NOPS_16;
67     }
68     stopwatch.stop();
69     speed   = ((1024*LOOP_LIMIT)/stopwatch.usecs())/MILLION;
70     stopwatch.clear();
71     if (speed > max_speed)
72       max_speed = speed;
73   }
74   return max_speed;
75 }