streams.cpp
Go to the documentation of this file.
00001 
00010 /*****************************************************************************
00011 ** Includes
00012 *****************************************************************************/
00013 
00014 #include <iostream>
00015 #include <ecl/threads/priority.hpp>
00016 #include <ecl/time/stopwatch.hpp>
00017 #include <ecl/streams.hpp>
00018 #include <ecl/formatters.hpp>
00019 
00020 /*****************************************************************************
00021 ** Using
00022 *****************************************************************************/
00023 
00024 using ecl::OConsoleStream;
00025 using ecl::StopWatch;
00026 using ecl::TimeStamp;
00027 using ecl::Format;
00028 using ecl::StandardException;
00029 
00030 /*****************************************************************************
00031 ** Main
00032 *****************************************************************************/
00033 
00034 int main() {
00035         try {
00036                 ecl::set_priority(ecl::RealTimePriority4);
00037         } catch ( StandardException &e ) {
00038                 // dont worry about it.
00039         }
00040 
00041     StopWatch stopwatch;
00042         TimeStamp times[6];
00043         unsigned int lines_to_write = 1;
00044     float f = 33.54235235;
00045     Format<double> format; format.precision(2); format.width(5);
00046 
00047     std::cout << std::endl;
00048     std::cout << "***********************************************************" << std::endl;
00049     std::cout << "                      Printf" << std::endl;
00050     std::cout << "***********************************************************" << std::endl;
00051     std::cout << std::endl;
00052 
00053     for ( unsigned int i = 0; i < lines_to_write; ++i ) { // Avoid speedups from caching affecting times.
00054         printf("Heya Dude\n");
00055     }
00056     stopwatch.restart();
00057     for ( unsigned int i = 0; i < lines_to_write; ++i ) {
00058         printf("Heya Dude\n");
00059     }
00060     times[0] = stopwatch.split();
00061     for ( unsigned int i = 0; i < lines_to_write; ++i ) { // Avoid speedups from caching affecting times.
00062         printf("%4.2f \n",f);
00063     }
00064     stopwatch.restart();
00065     for ( unsigned int i = 0; i < lines_to_write; ++i ) {
00066         printf("%4.2f \n",f);
00067     }
00068     times[3] = stopwatch.split();
00069 
00070     std::cout << std::endl;
00071     std::cout << "***********************************************************" << std::endl;
00072     std::cout << "                      Cout" << std::endl;
00073     std::cout << "***********************************************************" << std::endl;
00074     std::cout << std::endl;
00075 
00076     for ( unsigned int i = 0; i < lines_to_write; ++i ) { // Avoid speedups from caching affecting times.
00077         std::cout << "Heya Dude\n";
00078     }
00079     std::cout.flush();
00080     stopwatch.restart();
00081     for ( unsigned int i = 0; i < lines_to_write; ++i ) {
00082         std::cout << "Heya Dude\n";
00083     }
00084     std::cout.flush();
00085     times[1] = stopwatch.split();
00086 
00087     std::cout.precision(4);
00088     for ( unsigned int i = 0; i < lines_to_write; ++i ) { // Avoid speedups from caching affecting times.
00089         std::cout << f << " \n";
00090     }
00091     std::cout.flush();
00092     stopwatch.restart();
00093     for ( unsigned int i = 0; i < lines_to_write; ++i ) {
00094         std::cout << f << " \n";
00095     }
00096     std::cout.flush();
00097     times[4] = stopwatch.split();
00098 
00099     std::cout << std::endl;
00100     std::cout << "***********************************************************" << std::endl;
00101     std::cout << "                      Ostream" << std::endl;
00102     std::cout << "***********************************************************" << std::endl;
00103     std::cout << std::endl;
00104 
00105     OConsoleStream ostream;
00106     for ( unsigned int i = 0; i < lines_to_write; ++i ) { // Avoid speedups from caching affecting times.
00107         ostream << "Heya Dude\n";
00108     }
00109     ostream.flush();
00110     stopwatch.restart();
00111     for ( unsigned int i = 0; i < lines_to_write; ++i ) {
00112         ostream << "Heya Dude\n";
00113     }
00114     ostream.flush();
00115     times[2] = stopwatch.split();
00116 
00117     for ( unsigned int i = 0; i < lines_to_write; ++i ) { // Avoid speedups from caching affecting times.
00118         ostream << format(f) << " \n";
00119     }
00120     ostream.flush();
00121     stopwatch.restart();
00122     for ( unsigned int i = 0; i < lines_to_write; ++i ) {
00123         ostream << format(f) << " \n";
00124     }
00125     ostream.flush();
00126     times[5] = stopwatch.split();
00127 
00128     std::cout << std::endl;
00129     std::cout << "***********************************************************" << std::endl;
00130     std::cout << "                      Times" << std::endl;
00131     std::cout << "***********************************************************" << std::endl;
00132     std::cout << std::endl;
00133 
00134     std::cout << "Writing Char Strings:" << std::endl;
00135     std::cout << "           printf : " << times[0].nsec() << " ns" << std::endl;
00136     std::cout << "             cout : " << times[1].nsec() << " ns" << std::endl;
00137     std::cout << "   OConsoleStream : " << times[2].nsec() << " ns" << std::endl;
00138     std::cout << "Streaming Floats:" << std::endl;
00139     std::cout << "           printf : " << times[3].nsec() << " ns" << std::endl;
00140     std::cout << "             cout : " << times[4].nsec() << " ns" << std::endl;
00141     std::cout << "   OConsoleStream : " << times[5].nsec() << " ns" << std::endl;
00142 
00143     std::cout << std::endl;
00144     std::cout << "***********************************************************" << std::endl;
00145     std::cout << "                      Passed" << std::endl;
00146     std::cout << "***********************************************************" << std::endl;
00147     std::cout << std::endl;
00148 
00149         return 0;
00150 }


ecl_core_apps
Author(s): Daniel Stonier
autogenerated on Mon Jul 3 2017 02:22:13