/* cc timerbit.c -o pbit -lm */ /* timer1.txt: cc timerbit.c -o pbit -lm on molokai timer2.txt: cc timerbit.c -o pbit -lm -fast on molokai ....50/50 random bits really are that fast! 300 reps of 20K takes 0.21 secs! timer3.txt: cc timerbit.c -o pbit -lm on manoa (compaq laptop) timer4.txt: cc timerbit.c -o pbit -lm -O4 on manoa */ #include #include #include #define NRUSED 20000 #define NREPS 50 #define NSKIP 10 #define NP 127 #define NPMNQ (NP-30) #define NRANDS (NRUSED+NP) #define NPROBZ (NRUSED) long unsigned rands1[NRANDS]; long unsigned filt[32]; typedef struct probarray { long unsigned prob[NPROBZ]; long unsigned probfilt; int probbit; int probword; double prob_val; } Probz; Probz probbits; long unsigned multishift(); main() { int iter, wordnum, bitnum, oldbit, newbit; long icnt, yescnt1, yescnt2, yescnt3; int seed; long probcnter1; long unsigned *prob1, probfilt1; double drandtime, rbittime, pbittime; double bee, cee, dee, eee; for(iter=NSKIP;iter<=NREPS;iter+=NSKIP) { bee = clock(); seed=1465739853; srand48(seed); yescnt1 = 0; for(icnt=0;icnt<32*NRUSED*iter;icnt++) if(drand48()<0.5) yescnt1++; cee = clock(); seed=1465739853; srand48(seed); InitFilt(); InitRands(rands1); yescnt2 = 0; for(icnt=0;icntprob; if(probbie->prob_val==0.0) { for(i=0;iprob_val==1.0) { for(i=0;iprob_val * 32 * NPROBZ; if(probbie->prob_val >= 0.5) npp = 32 * NPROBZ - npp; for(i=0;iprob_val >= 0.5) for(i=0;iprobbit = 0; probbie->probword = NPROBZ; probbie->probfilt = filt[0]; } CheckProbz(probbie,numleft,probs,filter) Probz *probbie; long *numleft; long unsigned **probs, *filter; { *numleft = probbie->probword; *filter = probbie->probfilt; *probs = probbie->prob; } AdvanceProbz(probbie,numleft,filter) Probz *probbie; long *numleft; long unsigned *filter; { probbie->probword = *numleft; if(probbie->probword==0) { probbie->probbit++; if(probbie->probbit==32) { ScrambleProbz(probbie->prob); probbie->probbit = 0; } probbie->probword = NPROBZ; probbie->probfilt = filt[probbie->probbit]; *numleft = (long)NPROBZ; *filter = probbie->probfilt; } } ScrambleProbz(array) long unsigned array[NPROBZ]; { int i, j, ii, jj, isii; long unsigned itemp1, itemp2, iswitch; for(i=0;i=0) { for(i=0;i> 1) & 0x7fffffff; if(temp1==0x1) temp2 = temp2 | 0x80000000; } } return(temp2); }