-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathTimer.cpp
More file actions
31 lines (26 loc) · 693 Bytes
/
Timer.cpp
File metadata and controls
31 lines (26 loc) · 693 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//
// Created by jared on 11/10/15.
//
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include "Timer.h"
void Timer::start(){
//store time of day
gettimeofday(&start_time, NULL);
}
double Timer::stop(){
timeval end_time;
long seconds, useconds;
double duration;
gettimeofday(&end_time, NULL);
//calculate difference in seconds and microseconds.
seconds = end_time.tv_sec - start_time.tv_sec;
useconds = end_time.tv_usec - start_time.tv_usec;
//actual duartion is sum of differences
duration = seconds + useconds/1000000.0;
return duration;
}
void Timer::printTime(double duration) {
printf("%5.6f seconds\n", duration);
}