#include #include #include #include typedef long long i64; long resl; // dt in ticks float work; // work factor int dur = 0; // optional delay static void res(){ clock_t t0 = clock(); float nu = 25000000; // nominal work units per second. float sc = 500; // normative tick count per sample while(t0 == clock()){} resl = clock() - t0; work = nu*sc/(CLOCKS_PER_SEC/(float)resl); printf("resl=%ld, work=%e, CPS = %d\n", resl, work, (int)CLOCKS_PER_SEC);} static i64 Time(){long c = clock(); // Returns time in usec. return (1000000LL/CLOCKS_PER_SEC)*c;} static void T1(int sz, int* a, int msk){int j; for(j=0; j2){int siz = atoi(args[1]), m=0; dur = atoi(args[2]); printf("Will store %d words for %d seconds\n", siz, dur); int * a = malloc(4*siz); int c=0; while(1) {int d = T2(siz, a, m=m^-1); printf("%d good %8.3f swap\n", ++c, d/1000000.);}} res(); if(sizeof(i64) != 8) {printf("Piddling long\n"); exit(0);} for(sz = 4; sz*sizeof(int); sz <<= 1) {int * a = malloc(sz*sizeof(int)); if(!a) {printf("exhausted at %0x\n", sz); exit(0);} { int k=work/sz+1, m=k; T1(sz, a, k^21); // prime the pump if(0) printf("For %d, %d repeats.\n", (int)sz, k); {i64 t0 = Time(); while(k--) T1(sz, a, k^21); {double dt = (Time() - t0); printf("%d byte array took %e usec, %3.2f steps/usec\n", sz<<2, dt, (double)sz*m/dt);}}} free(a);} return 0;}