Skip to content

Commit c5a73ad

Browse files
committed
timer with a stack
1 parent 624c84d commit c5a73ad

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

NBody OpenCL/Timer.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,21 @@ Timer::Timer() {}
66
Timer::~Timer() {}
77

88

9-
void Timer::Tic() {
10-
m_tic = clock();
9+
void Timer::TicSimple( ) {
10+
m_simple_tic = clock();
11+
}
12+
13+
14+
double Timer::TocSimple( ) {
15+
return (double) (clock() - m_simple_tic) / CLOCKS_PER_SEC;
1116
}
1217

18+
void Timer::Tic() {
19+
m_tics.push( clock() );
20+
}
1321

1422
double Timer::Toc() {
15-
return (double) (clock() - m_tic) / CLOCKS_PER_SEC;
23+
double dt = (double) (clock( ) - m_tics.top()) / CLOCKS_PER_SEC;
24+
m_tics.pop();
25+
return dt;
1626
}

NBody OpenCL/Timer.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
#pragma once
22
#include <ctime>
3+
#include <stack>
34

45
class Timer {
56
public:
67
Timer();
78
~Timer();
89
private:
9-
clock_t m_tic;
10+
clock_t m_simple_tic;
11+
std::stack<clock_t> m_tics;
1012
public:
11-
void Tic();
12-
double Toc();
13+
void TicSimple();
14+
double TocSimple();
15+
void Tic( );
16+
double Toc( );
1317
};
1418

0 commit comments

Comments
 (0)