55{
56 unsigned int round;
57 unsigned int buckets[31];
58 unsigned int i;
59 int j;
60 unsigned int r;
62 unsigned long long total;
63 unsigned int want;
64 double predict;
65
66 srandom (time (NULL));
67 total = 0;
68 want = atoi (argv[1]);
69 for (round = 0; round <
ROUNDS; round++)
70 {
71 memset (buckets, 0, sizeof(buckets));
72 for (i = 0; i < want; i++)
73 {
74
75
76 r = random ();
77 if (0 == r)
78 continue;
79#if SLOW
80 for (j = 0; (j < 31) && (0 == (r & (1 << j))); j++)
81 ;
82#else
83
84 j = __builtin_ffs (r) - 1;
85#endif
86 buckets[j]++;
87 }
89 predict = 0.0;
90 for (j = 31; j >= 0; j--)
91 {
92#if FIX1
93
94
95
96
97if ((j > 0) &&
99 {
100 ret *= (1 << (j + 1));
101 break;
102 }
103#endif
104#if FIX2
105
106
107
108
109 if ((j > 0) &&
112 {
113 ret *= (1 << (j + 1));
114 break;
115 }
116#endif
117#if STRATA
118
119
121 {
122 ret *= (1 << (j + 1));
123 break;
124 }
125#endif
127 predict = (buckets[j] + 2.0 * predict) / 2.0;
128 }
129#if VERBOSE
130 fprintf (stderr,
"%u ",
ret);
131#endif
133 }
134 fprintf (stderr, "\n");
135 fprintf (stdout,
"average %llu\n", total /
ROUNDS);
136 return 0;
137}
static int ret
Final status code.