-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimer.cpp
More file actions
48 lines (39 loc) · 1.44 KB
/
Timer.cpp
File metadata and controls
48 lines (39 loc) · 1.44 KB
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
/*
8888ba.88ba 888888ba a88888b. dP
88 `8b `8b 88 `8b d8' `88 88
88 88 88 a88aaaa8P' 88 .d8888b. dP dP 88d888b. d8888P
88 88 88 88 88 88' `88 88 88 88' `88 88
88 88 88 88 Y8. .88 88. .88 88. .88 88 88 88
dP dP dP dP Y88888P' `88888P' `88888P' dP dP dP
MPCount
Pedro M P Ribeiro - pribeiro@fc.up.pt
Andre Couto Meira - andre.meira@fc.up.pt
*/
/*
* Timing utilities for measuring execution performance.
*
* Last Update: 02/2026
*
*/
#include "Timer.h"
// Static variables
struct timeval Timer::cstart[MAX_TIMERS];
struct timeval Timer::cend[MAX_TIMERS];
// Stop the clock of a timer
void Timer::start(int n) {
if (n >= 0 && n < MAX_TIMERS)
gettimeofday(&cstart[n], NULL);
}
// Elapsed time of a timer
void Timer::stop(int n) {
if (n >= 0 && n < MAX_TIMERS)
gettimeofday(&cend[n], NULL);
}
// Make the difference
double Timer::elapsed(int n) {
if (n >= 0 && n < MAX_TIMERS)
return (cend[n].tv_sec - cstart[n].tv_sec) +
(double)(cend[n].tv_usec - cstart[n].tv_usec) / 1000000.0;
else
return 0;
}