containers.cpp
Go to the documentation of this file.
00001 
00009 /*****************************************************************************
00010 ** Includes
00011 *****************************************************************************/
00012 
00013 #include <algorithm>
00014 #include <iostream>
00015 #include <vector>
00016 #include <ecl/containers/array.hpp>
00017 #include <ecl/threads/priority.hpp>
00018 #include <ecl/time/stopwatch.hpp>
00019 #include <ecl/time/timestamp.hpp>
00020 
00021 /*****************************************************************************
00022 ** Using
00023 *****************************************************************************/
00024 
00025 using std::string;
00026 using std::vector;
00027 using ecl::Array;
00028 using ecl::RealTimePriority4;
00029 using ecl::StandardException;
00030 using ecl::StopWatch;
00031 using ecl::TimeStamp;
00032 
00033 /*****************************************************************************
00034 ** Main
00035 *****************************************************************************/
00036 
00037 
00038 int main()
00039 {
00040         try {
00041                 ecl::set_priority(RealTimePriority4);
00042         } catch ( StandardException &e ) {
00043                 // dont worry about it.
00044         }
00045     StopWatch stopwatch;
00046     TimeStamp timestamp[5];
00047 
00048     Array<int,4> array_tmp;
00049     array_tmp << 3,4,6,3;
00050     array_tmp << 3,4,6,3;
00051     array_tmp << 3,4,6,3;
00052 
00053     std::cout << std::endl;
00054     std::cout << "***********************************************************" << std::endl;
00055     std::cout << "                    Constructors" << std::endl;
00056     std::cout << "***********************************************************" << std::endl;
00057     std::cout << std::endl;
00058 
00059     stopwatch.restart();
00060     // Array [manual]
00061     Array<int,4> array1;
00062     for ( int i = 0; i < 4; ++i ) {
00063         array1[i] = 3;
00064     }
00065     timestamp[0] = stopwatch.split();
00066 
00067     // Array [comma]
00068     Array<int,4> array2;
00069     array2 << 3,3,3,3;
00070     timestamp[1] = stopwatch.split();
00071 
00072     // Array [blueprint]
00073     Array<int,4> array3 = Array<int,4>::Constant(3);
00074     timestamp[2] = stopwatch.split();
00075 
00076     // Vector [manual]
00077     vector<int> v1(4);
00078     for ( int i = 0; i < 4; ++i ) {
00079         v1[i] = 3;
00080     }
00081     timestamp[3] = stopwatch.split();
00082 
00083     // Vector [manual]
00084     int a1[4];
00085     for ( int i = 0; i < 4; ++i ) {
00086         a1[i] = 3;
00087     }
00088     timestamp[4] = stopwatch.split();
00089 
00090     std::cout << "carray [manual]   : " << timestamp[4] << std::endl;
00091     std::cout << "Array  [blueprint]: " << timestamp[2] << std::endl;
00092     std::cout << "Array  [manual]   : " << timestamp[0] << std::endl;
00093     std::cout << "Array  [comma]    : " << timestamp[1] << std::endl;
00094     std::cout << "Vector [manual]   : " << timestamp[3] << std::endl;
00095 
00096     std::cout << std::endl;
00097     std::cout << "***********************************************************" << std::endl;
00098     std::cout << "                    Accessors" << std::endl;
00099     std::cout << "***********************************************************" << std::endl;
00100     std::cout << std::endl;
00101 
00102     int elements[4];
00103 
00104     stopwatch.restart();
00105     for (int i = 0; i < 4; ++i ) { elements[i] = array1[i]; }
00106     timestamp[0] = stopwatch.split();
00107 
00108     for (int i = 0; i < 4; ++i ) { elements[i] = array1.at(i); }
00109     timestamp[1] = stopwatch.split();
00110 
00111     for (int i = 0; i < 4; ++i ) { elements[i] = v1[i]; }
00112     timestamp[2] = stopwatch.split();
00113 
00114     for (int i = 0; i < 4; ++i ) { elements[i] = v1.at(i); }
00115     timestamp[3] = stopwatch.split();
00116 
00117     for (int i = 0; i < 4; ++i ) { elements[i] = a1[i]; }
00118     timestamp[4] = stopwatch.split();
00119 
00120     std::cout << "carray []   : " << timestamp[4] << std::endl;
00121     std::cout << "Array  []   : " << timestamp[0] << std::endl;
00122     std::cout << "Array  at   : " << timestamp[1] << std::endl;
00123     std::cout << "Vector []   : " << timestamp[2] << std::endl;
00124     std::cout << "Vector at   : " << timestamp[3] << std::endl;
00125 
00126     std::cout << std::endl;
00127     std::cout << "***********************************************************" << std::endl;
00128     std::cout << "                    Setters" << std::endl;
00129     std::cout << "***********************************************************" << std::endl;
00130     std::cout << std::endl;
00131 
00132     stopwatch.restart();
00133     for (int i = 0; i < 4; ++i ) { array1[i] = 3; }
00134     timestamp[0] = stopwatch.split();
00135 
00136     for (int i = 0; i < 4; ++i ) { array1 = Array<int,4>::Constant(3); }
00137     timestamp[1] = stopwatch.split();
00138 
00139     for (int i = 0; i < 4; ++i ) { v1[i] = 3; }
00140     timestamp[2] = stopwatch.split();
00141 
00142     for (int i = 0; i < 4; ++i ) { a1[i] = 3; }
00143     timestamp[3] = stopwatch.split();
00144 
00145     std::cout << "carray [manual]   : " << timestamp[3] << std::endl;
00146     std::cout << "Array  [blueprint]: " << timestamp[1] << std::endl;
00147     std::cout << "Array  [manual]   : " << timestamp[0] << std::endl;
00148     std::cout << "Vector [manual]   : " << timestamp[2] << std::endl;
00149 
00150 return 0;
00151 }
00152 


ecl_core_apps
Author(s): Daniel Stonier
autogenerated on Sun Oct 5 2014 23:36:25