• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

image2d.cc

00001 # include <mln/core/image/image2d.hh>
00002 # include <mln/util/timer.hh>
00003 
00004 # include <mln/core/pixter2d.hh>
00005 # include <mln/opt/at.hh>
00006 
00007 
00008 int size;
00009 
00010 
00011 float a_la_C()
00012 {
00013   unsigned len = size * size;
00014   int* buf = new int[len];
00015 
00016   mln::util::timer t;
00017   t.start();
00018   int* p = buf;
00019   for (unsigned i = 0; i < len; ++i)
00020     *p++ = 0;
00021   return t.read();
00022 }
00023 
00024 
00025 float loops()
00026 {
00027   typedef mln::image2d<int> I;
00028   mln::internal::data<I> data(mln::make::box2d(size, size), 1);
00029 
00030   mln::util::timer t;
00031   t.start();
00032   int** array = data.array_;
00033   for (int row = 0; row < size; ++row)
00034     for (int col = 0; col < size; ++col)
00035       array[row][col] = 0;
00036   return t.read();
00037 }
00038 
00039 
00040 float for_at()
00041 {
00042   typedef mln::image2d<int> I;
00043   I ima(size, size);
00044 
00045   mln::util::timer t;
00046   t.start();
00047   for (int row = 0; row < size; ++row)
00048     for (int col = 0; col < size; ++col)
00049       mln::opt::at(ima, row, col) = 0;
00050   return t.read();
00051 }
00052 
00053 
00054 float loops_ref()
00055 {
00056   typedef mln::image2d<int> I;
00057   mln::internal::data<I> data(mln::make::box2d(size, size), 1);
00058 
00059   mln::util::timer t;
00060   t.start();
00061 
00062   int** array = data.array_;
00063   mln::point2d p;
00064   mln::def::coord & row = p.row(), & col = p.col();
00065   for (row = 0; row < size; ++row)
00066     for (col = 0; col < size; ++col)
00067       array[row][col] = 0;
00068 
00069   return t.read();
00070 }
00071 
00072 
00073 float hybrid_1()
00074 {
00075   typedef mln::image2d<int> I;
00076   I ima(size, size);
00077 
00078   mln::util::timer t;
00079   t.start();
00080   mln::point2d p;
00081   mln::def::coord & row = p.row(), & col = p.col();
00082   for (row = 0; row < size; ++row)
00083     for (col = 0; col < size; ++col)
00084       mln::opt::at(ima, row, col) = 0;
00085   return t.read();
00086 }
00087 
00088 
00089 
00090 float milena()
00091 {
00092   typedef mln::image2d<int> I;
00093   I ima(size, size);
00094 
00095   mln::util::timer t;
00096   t.start();
00097   mln_piter_(I) p(ima.domain());
00098   for_all(p)
00099     ima(p) = 0;
00100   return t.read();
00101 }
00102 
00103 
00104 float optim()
00105 {
00106   typedef mln::image2d<int> I;
00107   I ima(size, size);
00108 
00109   mln::util::timer t;
00110   t.start();
00111   mln_piter_(I) p(ima.domain());
00112   for (p.start(); p.is_valid(); p.next())
00113     ima.alt(p) = 0;
00114   return t.read();
00115 }
00116 
00117 
00118 float fast()
00119 {
00120   typedef mln::image2d<int> I;
00121   I ima(size, size);
00122 
00123   mln::util::timer t;
00124   t.start();
00125   mln_pixter_(I) p(ima);
00126   for_all(p)
00127     p.val() = 0;
00128   return t.read();
00129 }
00130 
00131 
00132 void usage(char* argv[])
00133 {
00134   std::cerr << "usage: " << argv[0] << " size" << std::endl;
00135   abort();
00136 }
00137 
00138 
00139 int main(int argc, char* argv[])
00140 {
00141   if (argc != 2)
00142     usage(argv);
00143   size = std::atoi(argv[1]);
00144 
00145   std::cout << "*p++         " << a_la_C()   << std::endl;
00146   std::cout << "for (r,c)    " << loops()    << std::endl;
00147   std::cout << "for at(r,c)  " << for_at()   << std::endl;
00148   std::cout << "for &(r,c)   " << loops_ref()  << std::endl;
00149   std::cout << "hybrid_1     " << hybrid_1() << std::endl;
00150   std::cout << "for_all(p)   " << milena()   << std::endl;
00151   std::cout << "optim        " << optim()    << std::endl;
00152   std::cout << "for_all(pix) " << fast()   << std::endl;
00153 }

Generated on Tue Oct 4 2011 15:23:56 for Milena (Olena) by  doxygen 1.7.1