Skip to content

Commit 47c3030

Browse files
committed
Tweak to timings to reduce any overhead while timing functions.
1 parent 3c0c1be commit 47c3030

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

test/TestClass.hpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class TestClass
6868
, m_current_time(m_start_time)
6969
, m_timed_function_calls(0)
7070
, m_sample_time(secs, nanosecs)
71+
, m_stop_time(m_start_time + m_sample_time)
7172
, m_check_count(0)
7273
, m_failure_check_count(0)
7374
, m_test_number(0)
@@ -526,21 +527,18 @@ class TestClass
526527
/// @note This function also refreshes the current time.
527528
bool CheckTime()
528529
{
529-
TestTime stop_time(m_start_time);
530-
stop_time += m_sample_time;
531-
532530
m_current_time.Refresh();
533531

534532
++m_timed_function_calls;
535533

536-
bool complete = m_current_time > stop_time;
537-
if (complete)
534+
bool time_complete = m_current_time > m_stop_time;
535+
if (time_complete)
538536
{
539537
unsigned long call_time = TestTime::GetCallTimeInNanoseconds();
540538
m_current_time -= TestTime(call_time * static_cast<unsigned long>(m_timed_function_calls));
541539
}
542540

543-
return complete;
541+
return time_complete;
544542
}
545543

546544
/// While the current time has not reached the start time + sample time,
@@ -549,14 +547,11 @@ class TestClass
549547
/// @note This function also refreshes the current time.
550548
bool CheckTime(ocl_size_type min_iterations, TestString const& filename, ocl_size_type line_number)
551549
{
552-
TestTime stop_time(m_start_time);
553-
stop_time += m_sample_time;
554-
555550
m_current_time.Refresh();
556551

557552
++m_timed_function_calls;
558553

559-
bool time_complete = m_current_time > stop_time;
554+
bool time_complete = m_current_time > m_stop_time;
560555

561556
if (time_complete && (m_timed_function_calls < min_iterations))
562557
{
@@ -1044,6 +1039,10 @@ class TestClass
10441039
// The amount of time to run the performance test.
10451040
TestTime m_sample_time;
10461041

1042+
// When this test is timed, record the end time.
1043+
// NOTE: This must be defined after m_start_time and m_sample_time.
1044+
TestTime m_stop_time;
1045+
10471046
// Total checks for this function.
10481047
ocl_size_type m_check_count;
10491048

test/TestTime.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,20 @@ class TestTime
124124
return *this;
125125
}
126126

127+
TestTime operator -(TestTime const& time_to_add) throw()
128+
{
129+
TestTime tm(*this);
130+
tm -= time_to_add;
131+
return tm;
132+
}
133+
134+
TestTime operator +(TestTime const& time_to_add) throw()
135+
{
136+
TestTime tm(*this);
137+
tm += time_to_add;
138+
return tm;
139+
}
140+
127141
public:
128142
bool IsSet() const throw()
129143
{

0 commit comments

Comments
 (0)