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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include "TestPerformance.h"
#include "Vehicle.h"
#include <iostream>
#ifdef _WIN32
#include <windows.h> // WIN32 SDK GetTickCount function
#else
unsigned int GetTickCount()
{
std::cerr << "warning: fake GetTickCount used - timing results are not correct...\n";
return 0;
}
#endif
#define TicksPerSecond 1000
void ReportTiming(const char *s, unsigned int ts, unsigned int count)
{
std::cerr << "\n";
std::cerr << "Unmanaged Code Performance Results:\n";
std::cerr << " data type: " << s << "\n";
std::cerr << " seconds: " << ((double)ts / (double)TicksPerSecond) << "\n";
//std::cerr << " ticks: " << ts << "\n";
std::cerr << " count: " << count << "\n";
//std::cerr << " ticks per operation: " << ((double)ts/(double)count) << "\n";
std::cerr << " operations per second: " << ((double)count / (((double)ts / (double)TicksPerSecond))) << "\n";
std::cerr << "\n";
}
int TestPerformance::Main(int /*argc*/, char * /*argv*/ [])
{
int err = 0; // 0 == no error
unsigned int ts = 0;
unsigned int begin = 0;
std::cerr << "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)" << std::endl;
std::cerr << "Begin TestPerformance::Main" << std::endl;
Vehicle *vn = Vehicle::New();
Vehicle& v1 = *vn;
unsigned int i = 0;
unsigned int maxi = v1.GetMaxIndex();
std::cerr << "Set/GetValue loop..." << std::endl;
begin = GetTickCount();
for (i= 0; i<maxi; ++i)
{
v1.TSetValue(i, v1.TGetValue(i+1));
}
ts = GetTickCount() - begin;
ReportTiming("int", ts, maxi);
std::cerr << " i: " << i << std::endl;
std::cerr << "Set/GetDoubleValue loop..." << std::endl;
begin = GetTickCount();
for (i= 0; i<maxi; ++i)
{
v1.TSetDoubleValue(i, v1.TGetDoubleValue(i+1));
}
ts = GetTickCount() - begin;
ReportTiming("double", ts, maxi);
std::cerr << " i: " << i << std::endl;
std::cerr << "Set/GetStringValue loop..." << std::endl;
begin = GetTickCount();
for (i= 0; i<maxi; ++i)
{
v1.TSetStringValue(i, v1.TGetStringValue(i+1));
}
ts = GetTickCount() - begin;
ReportTiming("char* (string)", ts, maxi);
std::cerr << " i: " << i << std::endl;
std::cerr << "Set/GetObjectValue loop..." << std::endl;
begin = GetTickCount();
for (i= 0; i<maxi; ++i)
{
v1.TSetObjectValue(i, v1.TGetObjectValue(i+1));
}
ts = GetTickCount() - begin;
ReportTiming("AbstractVehicle* (object)", ts, maxi);
std::cerr << " i: " << i << std::endl;
v1.Delete();
std::cerr << "End TestPerformance::Main" << std::endl;
return err;
}
|