Advertisement
piffy

Timer

Aug 24th, 2014
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <sys/time.h>
  2.  
  3. typedef struct {
  4.     struct timeval startTime;
  5.     struct timeval endTime;
  6. } Timer;
  7.  
  8. Timer timer;
  9.  
  10. void startTime();
  11. void stopTime();
  12. void elapsedTime();
  13.  
  14.  
  15. void startTime() {
  16.     printf("Avvio Timer.\n");
  17.     gettimeofday(&(timer.startTime), NULL);
  18. }
  19.  
  20. void stopTime() {
  21.     printf("Fermo Timer.\n");
  22.     gettimeofday(&(timer.endTime), NULL);
  23. }
  24.  
  25. void elapsedTime() {
  26.     float elapseTime = (float) ((timer.endTime.tv_sec - timer.startTime.tv_sec) \
  27.                 + (timer.endTime.tv_usec - timer.startTime.tv_usec)/1.0e6);
  28.     printf("Tempo trascorso: %4.2f Sec.\n",elapseTime);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement