Go to the documentation of this file.00001 
00013 
00014 
00015 
00016 
00017 #include <iostream>
00018 #include <sstream>
00019 #include <ecl/threads/priority.hpp>
00020 #include <ecl/time/stopwatch.hpp>
00021 #include <ecl/time/timestamp.hpp>
00022 #include <ecl/converters.hpp>
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 using std::string;
00032 using std::ostringstream;
00033 using ecl::StopWatch;
00034 using ecl::TimeStamp;
00035 using ecl::Converter;
00036 using ecl::StandardException;
00037 
00038 
00039 
00040 
00041 
00042 
00043 int main()
00044 {
00045         try {
00046                 ecl::set_priority(ecl::RealTimePriority4);
00047         } catch ( StandardException &e ) {
00048                 
00049         }
00050     StopWatch stopwatch;
00051     TimeStamp time_converters[10], time_sprintf[10], time_iostreams[10];
00052 
00053     string str;
00054     int i = -11;
00055     unsigned int ui = 123;
00056     long l = -211123;
00057     float f = -16.123f;
00058     double d = -2316.1234;
00059     char buffer[30];
00060     char* char_string;
00061     Converter<char*> toCharString;
00062 
00063     ostringstream ostream;
00064 
00065     for (int j = 0; j < 50; ++j ) {
00066         sprintf(buffer,"%d",i);         
00067         sprintf(buffer,"%f",f);         
00068         ostream << i;                   
00069         ostream << l;                   
00070     }
00071 
00072     
00073 
00074 
00075     stopwatch.restart();
00076     sprintf(buffer,"%d",i);
00077     time_sprintf[0] = stopwatch.split();
00078     sprintf(buffer,"%d",ui);
00079     time_sprintf[1] = stopwatch.split();
00080     sprintf(buffer,"%ld",l);
00081     time_sprintf[2] = stopwatch.split();
00082     sprintf(buffer,"%f",f);
00083     time_sprintf[3] = stopwatch.split();
00084     sprintf(buffer,"%lf",d);
00085     time_sprintf[4] = stopwatch.split();
00086 
00087     
00088 
00089 
00090     stopwatch.restart();
00091     ostream << i;
00092     time_iostreams[0] = stopwatch.split();
00093     ostream << ui;
00094     time_iostreams[1] = stopwatch.split();
00095     ostream << l;
00096     time_iostreams[2] = stopwatch.split();
00097     ostream << f;
00098     time_iostreams[3] = stopwatch.split();
00099     ostream << d;
00100     time_iostreams[4] = stopwatch.split();
00101 
00102 
00103 
00104 
00105 
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 
00114 
00116 
00118 
00119 
00120     
00121 
00122 
00123     char_string = toCharString(f);
00124     char_string = toCharString(f);
00125     char_string = toCharString(f);
00126     char_string = toCharString(f);
00127     stopwatch.restart();
00128     char_string = toCharString(i);
00129     time_converters[0] = stopwatch.split();
00130     char_string = toCharString(ui);
00131     time_converters[1] = stopwatch.split();
00132     char_string = toCharString(l);
00133     time_converters[2] = stopwatch.split();
00134     char_string = toCharString(f);
00135     time_converters[3] = stopwatch.split();
00136     char_string = toCharString(d);
00137     time_converters[4] = stopwatch.split();
00138 
00139 
00140     std::cout << std::endl;
00141     std::cout << "***********************************************************" << std::endl;
00142     std::cout << "  Performance comparison of char string conversion apis" << std::endl;
00143     std::cout << "***********************************************************" << std::endl;
00144     std::cout << std::endl;
00145 
00146     std::cout << "Converter<char*>(int)          " << " Time: " << time_converters[0] <<  std::endl;
00147     std::cout << "Converter<char*>(unsigned int) " << " Time: " << time_converters[1] <<  std::endl;
00148     std::cout << "Converter<char*>(long)         " << " Time: " << time_converters[2] <<  std::endl;
00149     std::cout << "Converter<char*>(float)        " << " Time: " << time_converters[3] << std::endl;
00150     std::cout << "Converter<char*>(double)       " << " Time: " << time_converters[4] << std::endl;
00151     std::cout << std::endl;
00152     std::cout << "sprintf(int)                   " << " Time: " << time_sprintf[0] <<  std::endl;
00153     std::cout << "sprintf(unsigned int)          " << " Time: " << time_sprintf[1] <<  std::endl;
00154     std::cout << "sprintf(long)                  " << " Time: " << time_sprintf[2] <<  std::endl;
00155     std::cout << "sprintf(float)                 " << " Time: " << time_sprintf[3] <<  std::endl;
00156     std::cout << "sprintf(double)                " << " Time: " << time_sprintf[4] <<  std::endl;
00157     std::cout << std::endl;
00158     std::cout << "ostringstream(int)             " << " Time: " << time_iostreams[0] <<  std::endl;
00159     std::cout << "ostringstream(unsigned int)    " << " Time: " << time_iostreams[1] <<  std::endl;
00160     std::cout << "ostringstream(long)            " << " Time: " << time_iostreams[2] <<  std::endl;
00161     std::cout << "ostringstream(float)           " << " Time: " << time_iostreams[3] <<  std::endl;
00162     std::cout << "ostringstream(double)          " << " Time: " << time_iostreams[4] <<  std::endl;
00163     std::cout << std::endl;
00164 
00165 
00166 
00167 
00168 
00169 
00170     return 0;
00171 }
00172