| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#include <stdio.h> |
| 22 |
#include <stdlib.h> |
| 23 |
#include "stopwatch.h" |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#define IA 1103515245u |
| 30 |
#define IC 12345u |
| 31 |
#define IM 2147483648u |
| 32 |
|
| 33 |
static unsigned int current_random = 1; |
| 34 |
|
| 35 |
static int |
| 36 |
my_irand (int imax) |
| 37 |
{ |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
current_random = current_random * IA + IC; |
| 42 |
int ival = current_random & (IM - 1); |
| 43 |
ival = (int) ((float) ival * (float) (imax + 0.999) / (float) IM); |
| 44 |
return ival; |
| 45 |
} |
| 46 |
|
| 47 |
#define N 6000000 |
| 48 |
|
| 49 |
int |
| 50 |
fitos (int n) |
| 51 |
{ |
| 52 |
int i, k, retv; |
| 53 |
hrtime_t start = gethrtime (); |
| 54 |
hrtime_t vstart = gethrvtime (); |
| 55 |
|
| 56 |
|
| 57 |
wlog ("start of fitos", NULL); |
| 58 |
|
| 59 |
if (n <= 0) |
| 60 |
n = 1; |
| 61 |
int max = N * n; |
| 62 |
|
| 63 |
long long count = 0; |
| 64 |
do |
| 65 |
{ |
| 66 |
for (current_random = 1, i = retv = k = 0; i < max; i++) |
| 67 |
{ |
| 68 |
retv += my_irand (100); |
| 69 |
k += (current_random & (IM - 1)) >= (1 << 22); |
| 70 |
} |
| 71 |
count++; |
| 72 |
} |
| 73 |
while (start + testtime * 1e9 > gethrtime ()); |
| 74 |
fprintf (stderr, "\t\t%d out of a total of %d >= 2^22 (%d)\n", k, max, retv); |
| 75 |
fprintf (stderr, " Performed %lld while-loop iterations\n", count); |
| 76 |
whrvlog ((gethrtime () - start), (gethrvtime () - vstart), "fitos", NULL); |
| 77 |
return 0; |
| 78 |
} |