/* time_fadd.c try to measure time of double A = A + B; */ /* roughly time of one floating point add */ /* using double difference and minimum and stability */ #include #include #include #define dabs(a) (a)<0.0?-(a):(a) void do_count(int * count_check, int rep, double * B); int main(void) { double t1, t2, t3, t4, tmeas, t_min, t_prev, ts, tavg; double A, B, Q; int stable; int i, j; int count_check, outer; int rep, min_rep; t_min = 10.0; /* 10.0 seconds typical minimum measurement time */ Q = 5.0; /* 5.0 typical approximate percentage stability */ min_rep = 32; /* minimum of 32 typical */ outer = 100000; /* some big number */ printf("time_fadd.c \n"); printf("min time %g seconds, min stability %g percent, outer loop=%d\n", t_min, Q, outer); stable = 5; /* max tries */ t_prev = 0.0; for(rep=min_rep; rep<100000; rep=rep+rep) /* increase until good measure */ { A = 0.0; B = 0.1; t1 = (double)clock()/(double)CLOCKS_PER_SEC; for(i=0; i