/* */ /* File : time.c */ /* -- comment : a timer must be view as a counter in which the running -- time is stored. A chronometer is associated to the counter, -- it can be started and stopped. The time beetween the start -- and stop commands is then added to the counter. */ #include #include #include "timer.h" static struct tms tcpu; static unsigned int cpu_time(); static unsigned int cpu_time() { times(&tcpu); return(tcpu.tms_utime); } type_timer create_timer() { type_timer timer; timer=(type_timer) malloc(sizeof(struct struct_timer)); timer->accu = 0; return(timer); } void reinitialize_timer(type_timer timer) { timer->accu = 0; } void start_timer(type_timer timer) { timer->chrono = cpu_time(); } void stop_timer(type_timer timer) { timer->accu += cpu_time() - timer->chrono; } void display_value_timer(type_timer timer) { char buffer[256]; int value = timer->accu; sprintf(buffer,"%lds%ld", value/60,(value*5/3)%100); /* display_text(buffer); */ printf("%s \n",buffer); }