kdb@chinet.chi.il.us (Karl Botts) (11/06/90)
If you wanna see some aggressive optimization, compile this with MSC 6.0 using -Od, then with -Ox, execute 'em, and compare the results (L model; I haven't tried the others). --------------------------- cut --------------------- /* kdb$hpb 19:41:01 11/05/90 */ #include <stdio.h> #include <stdlib.h> typedef unsigned short word; #define loword(d) (*((word *)&(d))) #define hiword(d) (*(((word *)&(d)+1))) #define HASHPAGE(pg, fd) (loword(pg) ^ hiword(pg) ^ fd * 5821) #ifndef NUM_CHAINS #define NUM_CHAINS 32 #endif long lrand() { long l; loword(l) = rand(); hiword(l) = rand(); return(l); } main() { int fd; long l; long chains[NUM_CHAINS]; for ( fd = 0; fd < _NFILE; fd++ ) { word hash; memset(chains, 0, sizeof(chains)); for ( l = 0; l < 100000; l++ ) { long x = lrand(); hash = HASHPAGE(x, fd); hash %= NUM_CHAINS; chains[hash]++; } for ( hash = 0; hash < NUM_CHAINS; hash++ ) printf("%ld%c", chains[hash], (hash + 1) % 16 ? ' ' : '\n'); printf("\n"); } return 0; }