mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-15 13:39:05 +02:00
Use appropriate units for timing tests
This commit is contained in:
parent
42169ddcb3
commit
0f6162d683
2 changed files with 43 additions and 32 deletions
|
@ -136,66 +136,76 @@ void runTimingTests() {
|
|||
float fTest = 1.0;
|
||||
float* fResults = (float*)malloc(sizeof(float) * numTests);
|
||||
QElapsedTimer startTime;
|
||||
startTime.start();
|
||||
float elapsedUsecs;
|
||||
float elapsedNSecs;
|
||||
float elapsedUSecs;
|
||||
|
||||
float NSEC_TO_USEC = 1.0f / 1000.0f;
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qCDebug(interfaceapp, "QElapsedTimer::nsecElapsed() usecs: %f", (double)elapsedUsecs);
|
||||
startTime.start();
|
||||
elapsedNSecs = (float)startTime.nsecsElapsed();
|
||||
qCDebug(interfaceapp, "QElapsedTimer::nsecElapsed() ns: %f", (double)elapsedNSecs);
|
||||
|
||||
// Test sleep functions for accuracy
|
||||
startTime.start();
|
||||
QThread::msleep(1);
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qCDebug(interfaceapp, "QThread::msleep(1) ms: %f", (double)(elapsedUsecs / 1000.0f));
|
||||
elapsedNSecs = (float)startTime.nsecsElapsed();
|
||||
qCDebug(interfaceapp, "QThread::msleep(1) ms: %f", (double)(elapsedNSecs / NSECS_PER_MSEC));
|
||||
|
||||
startTime.start();
|
||||
QThread::sleep(1);
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qCDebug(interfaceapp, "QThread::sleep(1) ms: %f", (double)(elapsedUsecs / 1000.0f));
|
||||
elapsedNSecs = (float)startTime.nsecsElapsed();
|
||||
qCDebug(interfaceapp, "QThread::sleep(1) s: %f", (double)(elapsedNSecs / NSECS_PER_MSEC / MSECS_PER_SECOND));
|
||||
|
||||
startTime.start();
|
||||
usleep(1);
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qCDebug(interfaceapp, "usleep(1) ms: %f", (double)(elapsedUsecs / 1000.0f));
|
||||
elapsedNSecs = (float)startTime.nsecsElapsed();
|
||||
qCDebug(interfaceapp, "usleep(1) us: %f", (double)(elapsedNSecs / NSECS_PER_USEC));
|
||||
|
||||
startTime.start();
|
||||
usleep(10);
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qCDebug(interfaceapp, "usleep(10) ms: %f", (double)(elapsedUsecs / 1000.0f));
|
||||
elapsedNSecs = (float)startTime.nsecsElapsed();
|
||||
qCDebug(interfaceapp, "usleep(10) us: %f", (double)(elapsedNSecs / NSECS_PER_USEC));
|
||||
|
||||
startTime.start();
|
||||
usleep(100);
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qCDebug(interfaceapp, "usleep(100) ms: %f", (double)(elapsedUsecs / 1000.0f));
|
||||
elapsedNSecs = (float)startTime.nsecsElapsed();
|
||||
qCDebug(interfaceapp, "usleep(100) us: %f", (double)(elapsedNSecs / NSECS_PER_USEC));
|
||||
|
||||
startTime.start();
|
||||
usleep(1000);
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qCDebug(interfaceapp, "usleep(1000) ms: %f", (double)(elapsedUsecs / 1000.0f));
|
||||
elapsedNSecs = (float)startTime.nsecsElapsed();
|
||||
qCDebug(interfaceapp, "usleep(1000) us: %f", (double)(elapsedNSecs / NSECS_PER_USEC));
|
||||
|
||||
startTime.start();
|
||||
usleep(1500);
|
||||
elapsedNSecs = (float)startTime.nsecsElapsed();
|
||||
qCDebug(interfaceapp, "usleep(1500) us: %f", (double)(elapsedNSecs / NSECS_PER_USEC));
|
||||
|
||||
startTime.start();
|
||||
usleep(2500);
|
||||
elapsedNSecs = (float)startTime.nsecsElapsed();
|
||||
qCDebug(interfaceapp, "usleep(2500) us: %f", (double)(elapsedNSecs / NSECS_PER_USEC));
|
||||
|
||||
startTime.start();
|
||||
usleep(15000);
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qCDebug(interfaceapp, "usleep(15000) ms: %f", (double)(elapsedUsecs / 1000.0f));
|
||||
elapsedNSecs = (float)startTime.nsecsElapsed();
|
||||
qCDebug(interfaceapp, "usleep(15000) us: %f", (double)(elapsedNSecs / NSECS_PER_USEC));
|
||||
|
||||
// Random number generation
|
||||
startTime.start();
|
||||
for (int i = 0; i < numTests; i++) {
|
||||
iResults[i] = rand();
|
||||
}
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
elapsedUSecs = (float)startTime.nsecsElapsed() / NSECS_PER_USEC;
|
||||
qCDebug(interfaceapp, "rand() stored in array usecs: %f, first result:%d",
|
||||
(double)(elapsedUsecs / numTests), iResults[0]);
|
||||
(double)(elapsedUSecs / numTests), iResults[0]);
|
||||
|
||||
// Random number generation using randFloat()
|
||||
startTime.start();
|
||||
for (int i = 0; i < numTests; i++) {
|
||||
fResults[i] = randFloat();
|
||||
}
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
elapsedUSecs = (float)startTime.nsecsElapsed() / NSECS_PER_USEC;
|
||||
qCDebug(interfaceapp, "randFloat() stored in array usecs: %f, first result: %f",
|
||||
(double)(elapsedUsecs / numTests), (double)(fResults[0]));
|
||||
(double)(elapsedUSecs / numTests), (double)(fResults[0]));
|
||||
|
||||
free(iResults);
|
||||
free(fResults);
|
||||
|
@ -206,8 +216,8 @@ void runTimingTests() {
|
|||
for (int i = 0; i < numTests; i++) {
|
||||
fTest = powf(fTest, 0.5f);
|
||||
}
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qCDebug(interfaceapp, "powf(f, 0.5) usecs: %f", (double)(elapsedUsecs / (float) numTests));
|
||||
elapsedUSecs = (float)startTime.nsecsElapsed() / NSECS_PER_USEC;
|
||||
qCDebug(interfaceapp, "powf(f, 0.5) usecs: %f", (double)(elapsedUSecs / (float) numTests));
|
||||
|
||||
// Vector Math
|
||||
float distance;
|
||||
|
@ -218,9 +228,9 @@ void runTimingTests() {
|
|||
//float distanceSquared = glm::dot(temp, temp);
|
||||
distance = glm::distance(pointA, pointB);
|
||||
}
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
elapsedUSecs = (float)startTime.nsecsElapsed() / NSECS_PER_USEC;
|
||||
qCDebug(interfaceapp, "vector math usecs: %f [%f usecs total for %d tests], last result:%f",
|
||||
(double)(elapsedUsecs / (float) numTests), (double)elapsedUsecs, numTests, (double)distance);
|
||||
(double)(elapsedUSecs / (float) numTests), (double)elapsedUSecs, numTests, (double)distance);
|
||||
|
||||
// Vec3 test
|
||||
glm::vec3 vecA(randVector()), vecB(randVector());
|
||||
|
@ -231,9 +241,9 @@ void runTimingTests() {
|
|||
glm::vec3 temp = vecA-vecB;
|
||||
result = glm::dot(temp,temp);
|
||||
}
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
elapsedUSecs = (float)startTime.nsecsElapsed() / NSECS_PER_USEC;
|
||||
qCDebug(interfaceapp, "vec3 assign and dot() usecs: %f, last result:%f",
|
||||
(double)(elapsedUsecs / numTests), (double)result);
|
||||
(double)(elapsedUSecs / numTests), (double)result);
|
||||
|
||||
|
||||
quint64 BYTE_CODE_MAX_TEST_VALUE = 99999999;
|
||||
|
@ -265,9 +275,9 @@ void runTimingTests() {
|
|||
}
|
||||
|
||||
}
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qCDebug(interfaceapp) << "ByteCountCoded<quint64> usecs: " << elapsedUsecs
|
||||
<< "per test:" << (double) (elapsedUsecs / tests)
|
||||
elapsedUSecs = (float)startTime.nsecsElapsed() / NSECS_PER_USEC;
|
||||
qCDebug(interfaceapp) << "ByteCountCoded<quint64> usecs: " << elapsedUSecs
|
||||
<< "per test:" << (double) (elapsedUSecs / tests)
|
||||
<< "tests:" << tests
|
||||
<< "failed:" << failed;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ const float METERS_PER_CENTIMETER = 0.01f;
|
|||
const float METERS_PER_MILLIMETER = 0.001f;
|
||||
const float MILLIMETERS_PER_METER = 1000.0f;
|
||||
const quint64 NSECS_PER_USEC = 1000;
|
||||
const quint64 NSECS_PER_MSEC = 1000000;
|
||||
const quint64 USECS_PER_MSEC = 1000;
|
||||
const quint64 MSECS_PER_SECOND = 1000;
|
||||
const quint64 USECS_PER_SECOND = USECS_PER_MSEC * MSECS_PER_SECOND;
|
||||
|
|
Loading…
Reference in a new issue