-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.cu
73 lines (48 loc) · 1.17 KB
/
timer.cu
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* timer.c
*/
# define TIMER_C
# include <stdio.h>
# include <sys/time.h>
# include "timer.h"
static double start, stop; /* store the times locally */
static int start_flag, stop_flag; /* flag timer use */
void initialize_timer ( void )
{
start = 0.0;
stop = 0.0;
start_flag = 0;
stop_flag = 0;
}
void reset_timer ( void )
{
initialize_timer();
}
void start_timer ( void )
{
struct timeval time;
if ( start_flag )
fprintf( stderr, "WARNING: timer already started!\n" );
start_flag = 1;
if ( gettimeofday( &time, NULL ) < 0 )
perror( "start_timer,gettimeofday" );
start = (((double) time.tv_sec) + ((double) time.tv_usec)/1000000);
}
void stop_timer ( void )
{
struct timeval time;
if ( !start_flag )
fprintf( stderr, "WARNING: timer not started!\n" );
if ( stop_flag )
fprintf( stderr, "WARNING: timer already stopped!\n" );
stop_flag = 1;
if ( gettimeofday( &time, NULL ) < 0 )
perror( "stop_timer,gettimeofday" );
stop = (((double) time.tv_sec) + ((double) time.tv_usec)/1000000);
}
double elapsed_time ( void )
{
if ( !start_flag || !stop_flag )
return (-1.0);
return (stop-start);
}