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
|
#define CBT(a) ((int**********)(void*)a)
#define CBI(a) ((int***)(void*)a)
#define CBS(a) ((QString***)(void*)a)
int random(int v)
{
return rand()%v;
}
int main(int, char**)
{
qDebug("Functionality test");
CCube<3, int> int_cube({4, 4, 4});
CCube<3, QString> str_cube({4, 4, 4});
int n=1;
for(int i=0; i<int_cube.size(0); ++i)
for(int j=0; j<int_cube.size(1); ++j)
for(int k=0; k<int_cube.size(2); ++k)
{
CBI(int_cube)[i][j][k]=n;
CBS(str_cube)[i][j][k]=QString("Hello_%1").arg(n);
++n;
}
CCube<3, QString> str_cube2;
str_cube2=str_cube;
for(int i=0; i<int_cube.size(0); ++i)
for(int j=0; j<int_cube.size(1); ++j)
for(int k=0; k<int_cube.size(2); ++k)
{
qDebug("Str value = %s, Str2 value = %s, int value (ptr) = %d, int value (math) = %d",
CBS(str_cube)[i][j][k].toUtf8().data(),
CBS(str_cube2)[i][j][k].toUtf8().data(),
CBI(int_cube)[i][j][k], int_cube.GetElem_Math({i, j, k}));
}
qDebug("\nPerformance test");
CCube<10, int> tb({7, 7, 7, 7, 7, 7, 7, 7, 7, 7});
srand(time(0));
struct timeval tv1, tv2;
const int tries=10000000;
qDebug("Pointer dereference readings");
gettimeofday(&tv1, 0);
for(n=0; n<tries; ++n)
{
CBT(tb)[random(7)][random(7)][random(7)][random(7)][random(7)]
[random(7)][random(7)][random(7)][random(7)][random(7)];
}
gettimeofday(&tv2, 0);
printf("Pointer algorithm time = %lld mksecs\n", ((qint64)(tv2.tv_sec)-(qint64)(tv1.tv_sec))*1000000ll+
((qint64)(tv2.tv_usec)-(qint64)(tv1.tv_usec)));
qDebug("Index calculation readings");
gettimeofday(&tv1, 0);
for(n=0; n<tries; ++n)
{
tb.GetElem_Math({random(7), random(7), random(7), random(7), random(7),
random(7), random(7), random(7), random(7), random(7)});
}
gettimeofday(&tv2, 0);
printf("Math algorithm time = %lld mksecs\n", ((qint64)(tv2.tv_sec)-(qint64)(tv1.tv_sec))*1000000ll+
((qint64)(tv2.tv_usec)-(qint64)(tv1.tv_usec)));
return 0;
}
|