aboutsummaryrefslogtreecommitdiffstats
path: root/mps/code
diff options
context:
space:
mode:
authorRichard Kistruck2009-01-13 16:30:27 +0000
committerRichard Kistruck2009-01-13 16:30:27 +0000
commit4fc1ea19fbf43ab263c604f26870eb935399c44d (patch)
treeefe4f0f214a9274d1b2927be68da2de80b706d20 /mps/code
parenta899c472e1f32b6acd083ced9f7a2851c96b28f0 (diff)
downloademacs-4fc1ea19fbf43ab263c604f26870eb935399c44d.tar.gz
emacs-4fc1ea19fbf43ab263c604f26870eb935399c44d.zip
Mps br/timing zcoll.c: show count of objects made & kept.
Also (TEMPORARY) investigate poor seeding of rnd(). Aha -- it's a full-period generator. Therefore the current randomize is a very poor way to seed it. Copied from Perforce Change: 167152 ServerID: perforce.ravenbrook.com
Diffstat (limited to 'mps/code')
-rw-r--r--mps/code/zcoll.c69
1 files changed, 67 insertions, 2 deletions
diff --git a/mps/code/zcoll.c b/mps/code/zcoll.c
index b00b11aceeb..c8f70d46d6a 100644
--- a/mps/code/zcoll.c
+++ b/mps/code/zcoll.c
@@ -141,19 +141,24 @@ static void testscriptC(mps_arena_t arena, mps_ap_t ap, const char *script)
141 printf("makeTotal: %d, wastefulness: %d.\n", 141 printf("makeTotal: %d, wastefulness: %d.\n",
142 makeTotal, wastefulness); 142 makeTotal, wastefulness);
143 script += bytesread; 143 script += bytesread;
144 144
145 objCount = 0;
145 while(makeCount < makeTotal) { 146 while(makeCount < makeTotal) {
146 mps_word_t v; 147 mps_word_t v;
147 die(make_dylan_vector(&v, ap, 2), "make_dylan_vector"); 148 die(make_dylan_vector(&v, ap, 2), "make_dylan_vector");
148 DYLAN_VECTOR_SLOT(v, 0) = DYLAN_INT(objCount); 149 DYLAN_VECTOR_SLOT(v, 0) = DYLAN_INT(objCount);
149 DYLAN_VECTOR_SLOT(v, 1) = (mps_word_t)NULL; 150 DYLAN_VECTOR_SLOT(v, 1) = (mps_word_t)NULL;
151 objCount++;
150 if(rnd() % wastefulness == 0) { 152 if(rnd() % wastefulness == 0) {
151 /* keep this one */ 153 /* keep this one */
152 myroot[makeCount % myrootCOUNT] = (void*)v; 154 myroot[makeCount % myrootCOUNT] = (void*)v;
153 makeCount++; 155 makeCount++;
154 } 156 }
155 } 157 }
156 158 printf("Made and kept: %d objects (actually created %d objects,"
159 " in accord with wastefulness of %d).\n",
160 makeCount, objCount, wastefulness);
161
157 break; 162 break;
158 } 163 }
159 default: { 164 default: {
@@ -269,17 +274,77 @@ static void testscriptA(const char *script)
269 274
270} 275}
271 276
277#include <math.h> /* fmod */
278
279static unsigned long rndA(void)
280{
281 static unsigned long seed = 1;
282 double s;
283
284 s = seed;
285 s *= 16807.0;
286 s = fmod(s, 2147483647.0); /* 2^31 - 1 */
287 seed = (unsigned long)s;
288 return seed;
289}
290
291static unsigned long rndB(void)
292{
293 static unsigned long seed = 1;
294 double s;
295
296 s = seed;
297 s *= 16807.0;
298 s = fmod(s, 2147483647.0); /* 2^31 - 1 */
299 seed = (unsigned long)s;
300 return seed;
301}
302
303
272 304
273/* main -- runs various test scripts 305/* main -- runs various test scripts
274 * 306 *
275 */ 307 */
276int main(int argc, char **argv) 308int main(int argc, char **argv)
277{ 309{
310
311 {
312 /* ..... All this is very interesting, but the answer is in the
313 * literature: *= 16807 mod (2^31-1) is a full-period generator.
314 *
315 * (For itnerest, at about 3.5 seconds per million iterations on
316 * my old Mac this will wrap in about 2 hours, and take 4 hours
317 * for fast to catch up with slow).
318 *
319 * The way randomize does its seeding is plain wrong.
320 */
321
322 unsigned long slow, fast;
323 double count;
324 for(count = 0, slow = rndA(), fast = rndB(), fast = rndB();
325 fast != slow;
326 count += 1, slow = rndA(), fast = rndB(), fast = rndB()) {
327 if(fmod(count, 100000) == 0) {
328 printf(".");
329 fflush(stdout);
330 }
331 if(fmod(count, 1000000) == 0) {
332 printf(" %9.f.\n", count);
333 printf("%lu %lu.\n", slow, fast);
334 fflush(stdout);
335 }
336 }
337
338 printf("coincidence at count=%.f.\n", count);
339 exit(0);
340 }
341
278 342
279 randomize(argc, argv); 343 randomize(argc, argv);
280 344
281 /* The most basic scripts */ 345 /* The most basic scripts */
282 testscriptA("Make(objs 1500, wastefulness 50)"); 346 testscriptA("Make(objs 1500, wastefulness 50)");
347 testscriptA("Make(objs 10000, wastefulness 5)");
283 348
284 349
285 fflush(stdout); /* synchronize */ 350 fflush(stdout); /* synchronize */