-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTestRunner.cpp
More file actions
46 lines (34 loc) · 1001 Bytes
/
TestRunner.cpp
File metadata and controls
46 lines (34 loc) · 1001 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
#include "TestRunner.hpp"
#include <algorithm>
#include <ctime>
namespace funcperf {
TestRunner::TestRunner()
{
}
int64_t TestRunner::runTest(ITest& test, void* func, int iterations, bool* verifyResult)
{
int res;
struct timespec tp0, tp1;
int64_t nanos[iterations];
int64_t totalSum = 0;
int totalValidMeasures = 0;
for (int iteration = 0; iteration < iterations; iteration++) {
res = clock_gettime(CLOCK_MONOTONIC_PRECISE, &tp0);
test.run(func);
res |= clock_gettime(CLOCK_MONOTONIC_PRECISE, &tp1);
if (res == 0) {
uint64_t nano0 = (1000000000LL * tp0.tv_sec) + tp0.tv_nsec;
uint64_t nano1 = (1000000000LL * tp1.tv_sec) + tp1.tv_nsec;
nanos[totalValidMeasures++] = nano1 - nano0;
//totalValidMeasures++;
totalSum += (nano1 - nano0);
}
if (verifyResult != NULL && iteration == 0) {
*verifyResult = test.verify();
}
}
// return an approximation of the median
std::sort(nanos, nanos + totalValidMeasures);
return nanos[totalValidMeasures / 2];
}
}