00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __loaded__array_test_cpp__
00021 #define __loaded__array_test_cpp__
00022 using namespace std;
00023 #line 1 "array-test.c++"
00024 #include <time.h>
00025 #include <stdio.h>
00026 #include "om-data.h"
00027
00028 int main(int, char*[])
00029 {
00030 time_t st;
00031 printf("Picture testing...\n");
00032 typedef Array<3,unsigned char> Image;
00033 typedef Array<2,unsigned char> Plane;
00034 const int COLOR = 0;
00035 const int X = 1;
00036 const int Y = 2;
00037 Array<3,unsigned char> picture(3,1024,768);
00038 picture = 2;
00039 printf(" Normal iteration loop\n");
00040 st = time(NULL);
00041 int nr = 0;
00042 int r = 0;
00043 int g = 0;
00044 int b = 0;
00045 printf(" %d [%d,%d,%d] times\nExtra optimized loop\n",nr,r,g,b);
00046 st = time(NULL);
00047 nr = 0;
00048 picture(From<3>(0,0,0))(Select<2>(1,2))=1;
00049 picture(From<3>(1,0,0))(Select<2>(1,2))=2;
00050 picture(From<3>(2,0,0))(Select<2>(1,2))=3;
00051
00052 while(time(NULL)-st<10)
00053 {
00054 nr++;
00055 b = g = r = 0;
00056 Image::matrix_positions color(picture,COLOR);
00057 Plane::values xy(picture(Select<2>(X,Y)));
00058 for( ; color.more() ; ++color)
00059 {
00060 int v = 0;
00061 for(xy.init(color) ; xy.more() ; ++xy)
00062 v+=xy;
00063 if (color[COLOR]==0) r = v;
00064 else if (color[COLOR]==1) g = v;
00065 else if (color[COLOR]==2) b = v;
00066 else assert(0);
00067 }
00068 }
00069 printf(" %d [%d,%d,%d] times\nOptimized loop\n",nr,r,g,b);
00070 st = time(NULL);
00071 nr = 0;
00072 while(time(NULL)-st<10)
00073 {
00074 nr++;
00075 b = g = r = 0;
00076 for(Image::matrix_positions colors(picture,COLOR) ; colors.more() ;
00077 ++colors)
00078 {
00079 int v = 0;
00080 Image::matrix &colorplane = colors;
00081 for(Image::matrix::values chunks(colorplane); chunks.more() ;
00082 ++chunks)
00083 v+=chunks;
00084 if (colors[0]==0) r = v;
00085 else if (colors[0]==1) g = v;
00086 else if (colors[0]==2) b = v;
00087 else assert(0);
00088 }
00089 }
00090 printf(" %d [%d,%d,%d] times\n",nr,r,g,b);
00091 }
00092 #endif // __loaded__array_test_cpp__