files.cpp
Go to the documentation of this file.
00001 
00009 /*****************************************************************************
00010 ** Includes
00011 *****************************************************************************/
00012 
00013 #include <iostream>
00014 #include <fstream>
00015 #include <ecl/threads/priority.hpp>
00016 #include <ecl/time/stopwatch.hpp>
00017 #include <ecl/devices/ofile.hpp>
00018 #include <ecl/devices/shared_file.hpp>
00019 #include <ecl/streams/log_stream.hpp>
00020 #include <ecl/streams/text_stream.hpp>
00021 
00022 /*****************************************************************************
00023 ** Using
00024 *****************************************************************************/
00025 
00026 using ecl::Append;
00027 using ecl::New;
00028 using ecl::OFile;
00029 using ecl::SharedFile;
00030 using ecl::LogStream;
00031 using ecl::TextStream;
00032 using ecl::StandardException;
00033 using ecl::StopWatch;
00034 using ecl::TimeStamp;
00035 
00036 /*****************************************************************************
00037 ** Enums
00038 *****************************************************************************/
00039 
00040 enum LogMode {
00041         Warning,
00042         Error
00043 };
00044 
00045 /*****************************************************************************
00046 ** Main
00047 *****************************************************************************/
00048 
00049 int main() {
00050         try {
00051                 ecl::set_priority(ecl::RealTimePriority4);
00052         } catch ( StandardException &e ) {
00053                 // dont worry about it.
00054         }
00055 
00056     StopWatch stopwatch;
00057         TimeStamp times[22];
00058         unsigned int lines_to_write = 500;// Buffer::buffer_size/10 + 1;
00059     float f = 33.54;
00060 
00061     std::cout << std::endl;
00062     std::cout << "***********************************************************" << std::endl;
00063     std::cout << "                   OFile Write" << std::endl;
00064     std::cout << "***********************************************************" << std::endl;
00065     std::cout << std::endl;
00066 
00067     OFile o_file("odude.txt",New);
00068     for ( unsigned int i = 0; i < lines_to_write; ++i ) { // Avoid speedups from caching affecting times.
00069         o_file.write("Heya Dude\n",10);
00070     }
00071     o_file.flush();
00072     stopwatch.restart();
00073     for ( unsigned int i = 0; i < lines_to_write; ++i ) {
00074         o_file.write("Heya Dude\n",10);
00075     }
00076     o_file.flush();
00077     times[0] = stopwatch.split();
00078 
00079     std::cout << std::endl;
00080     std::cout << "***********************************************************" << std::endl;
00081     std::cout << "                  Shared File Write" << std::endl;
00082     std::cout << "***********************************************************" << std::endl;
00083     std::cout << std::endl;
00084 
00085     SharedFile s_file("sdude.txt",New);
00086     for ( unsigned int i = 0; i < lines_to_write; ++i ) { // Avoid speedups from caching affecting times.
00087         s_file.write("Heya Dude\n",10);
00088     }
00089     s_file.flush();
00090     stopwatch.restart();
00091     for ( unsigned int i = 0; i < lines_to_write; ++i ) {
00092         s_file.write("Heya Dude\n",10);
00093     }
00094     s_file.flush();
00095     times[1] = stopwatch.split();
00096 
00097     std::cout << std::endl;
00098     std::cout << "***********************************************************" << std::endl;
00099     std::cout << "                     TextStream<OFile>" << std::endl;
00100     std::cout << "***********************************************************" << std::endl;
00101     std::cout << std::endl;
00102 
00103     TextStream<OFile> ostream;
00104     ostream.device().open("dude_stream.txt",New);
00105     stopwatch.restart();
00106     for ( unsigned int i = 0; i < lines_to_write; ++i ) {
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     stopwatch.restart();
00117     for ( unsigned int i = 0; i < lines_to_write; ++i ) {
00118         ostream << f << "\n";
00119     }
00120     ostream.flush();
00121     stopwatch.restart();
00122     for ( unsigned int i = 0; i < lines_to_write; ++i ) {
00123         ostream << f << "\n";
00124     }
00125     ostream.flush();
00126     times[3] = stopwatch.split();
00127 
00128     std::cout << std::endl;
00129     std::cout << "***********************************************************" << std::endl;
00130     std::cout << "                     std::ofstream" << std::endl;
00131     std::cout << "***********************************************************" << std::endl;
00132     std::cout << std::endl;
00133 
00134     std::ofstream cpp_ostream("dude_ofstream.txt");
00135     stopwatch.restart();
00136     for ( unsigned int i = 0; i < lines_to_write; ++i ) {
00137         cpp_ostream << "Heya Dude\n";
00138     }
00139     cpp_ostream.flush();
00140     stopwatch.restart();
00141     for ( unsigned int i = 0; i < lines_to_write; ++i ) {
00142         cpp_ostream << "Heya Dude\n";
00143     }
00144     cpp_ostream.flush();
00145     times[4] = stopwatch.split();
00146     stopwatch.restart();
00147     for ( unsigned int i = 0; i < lines_to_write; ++i ) {
00148         cpp_ostream << f << "\n";
00149     }
00150     cpp_ostream.flush();
00151     stopwatch.restart();
00152     for ( unsigned int i = 0; i < lines_to_write; ++i ) {
00153         cpp_ostream << f << "\n";
00154     }
00155     cpp_ostream.flush();
00156     times[5] = stopwatch.split();
00157     cpp_ostream.close();
00158 
00159     std::cout << std::endl;
00160     std::cout << "***********************************************************" << std::endl;
00161     std::cout << "                     LogStream" << std::endl;
00162     std::cout << "***********************************************************" << std::endl;
00163     std::cout << std::endl;
00164 
00165     LogStream log_stream("dude_logstream.txt",New);
00166         log_stream.disableHeader();
00167         log_stream.disableTimeStamp();
00168         log_stream.enableMode(Warning,"WARNING");
00169 
00170     stopwatch.restart();
00171     for ( unsigned int i = 0; i < lines_to_write; ++i ) {
00172         LOG(log_stream,Warning) << "Heya Dude\n";
00173     }
00174     FLUSH(log_stream);
00175     stopwatch.restart();
00176     for ( unsigned int i = 0; i < lines_to_write; ++i ) {
00177         LOG(log_stream,Warning) << "Heya Dude\n";
00178     }
00179     FLUSH(log_stream);
00180     times[9] = stopwatch.split();
00181     stopwatch.restart();
00182     for ( unsigned int i = 0; i < lines_to_write; ++i ) {
00183         LOG(log_stream,Warning) << f << "\n";
00184     }
00185     FLUSH(log_stream);
00186     stopwatch.restart();
00187     for ( unsigned int i = 0; i < lines_to_write; ++i ) {
00188         LOG(log_stream,Warning) << f << "\n";
00189     }
00190     FLUSH(log_stream);
00191     times[10] = stopwatch.split();
00192 
00193     std::cout << std::endl;
00194     std::cout << "***********************************************************" << std::endl;
00195     std::cout << "                      Times" << std::endl;
00196     std::cout << "***********************************************************" << std::endl;
00197     std::cout << std::endl;
00198 
00199     std::cout << "Writing Char Strings:" << std::endl;
00200     std::cout << "   OFile write       : " << times[0].nsec() << " ns" << std::endl;
00201     std::cout << "   SharedFile write  : " << times[1].nsec() << " ns" << std::endl;
00202     std::cout << "   OFile stream      : " << times[2].nsec() << " ns" << std::endl;
00203     std::cout << "   LogStream         : " << times[9].nsec() << " ns" << std::endl;
00204     std::cout << "   C++ ofstream      : " << times[4].nsec() << " ns" << std::endl;
00205     std::cout << "Streaming Floats:" << std::endl;
00206     std::cout << "   OFileStream       : " << times[3].nsec() << " ns" << std::endl;
00207     std::cout << "   Log stream        : " << times[10].nsec() << " ns" << std::endl;
00208     std::cout << "   C++ ofstream      : " << times[5].nsec() << " ns" << std::endl;
00209 
00210     std::cout << std::endl;
00211     std::cout << "***********************************************************" << std::endl;
00212     std::cout << "                      Passed" << std::endl;
00213     std::cout << "***********************************************************" << std::endl;
00214     std::cout << std::endl;
00215 
00216         return 0;
00217 }


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