-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.c
More file actions
executable file
·46 lines (38 loc) · 784 Bytes
/
timer.c
File metadata and controls
executable file
·46 lines (38 loc) · 784 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* mytimer.c */
//
// Functions for getting the time
// difference between two points in
// a program. A common use is to time
// how long a function or algorithm takes.
//
// Michael Mei
// Linux Mint 18(Sarah) with gcc
// U. of Illinois, Chicago
// CS251, Fall 2016
// HW #14
//
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "timer.h"
static clock_t myTimerStart = 0;
static clock_t myTimerEnd = 0;
void timer_start()
{
myTimerStart = clock();
}
void timer_stop()
{
myTimerEnd = clock();
}
double timer_value()
{
return (((double) myTimerEnd) - ((double) myTimerStart)) / CLOCKS_PER_SEC;
}
void timer_stats(char* message)
{
if(!message)
printf("Time: %lf seconds\n", timer_value());
else
printf("%s%lf seconds\n", message, timer_value());
}