comparison UnitTestsSources/GenericToolboxTests.cpp @ 1189:09fc591d8ff9 broker

replacing boost::chrono by boost::posix_time for older compilers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 23 Nov 2019 11:57:03 +0100
parents 2e52d1f4c9e3
children 0ca50d275b9a
comparison
equal deleted inserted replaced
1188:4092b6e71d45 1189:09fc591d8ff9
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/ 19 **/
20 20
21 #include <Framework/Toolbox/GenericToolbox.h> 21 #include <Framework/Toolbox/GenericToolbox.h>
22 22
23 #include <boost/chrono.hpp> 23 #include <boost/date_time/posix_time/posix_time.hpp>
24 #include <boost/lexical_cast.hpp> 24 #include <boost/lexical_cast.hpp>
25 25
26 #include "gtest/gtest.h" 26 #include "gtest/gtest.h"
27 27
28 #include "stdint.h" 28 #include "stdint.h"
3876 double r = 0.0; 3876 double r = 0.0;
3877 3877
3878 bool ok = true; 3878 bool ok = true;
3879 3879
3880 { 3880 {
3881 boost::chrono::system_clock::time_point start = boost::chrono::system_clock::now(); 3881 boost::posix_time::ptime start = boost::posix_time::microsec_clock::local_time();
3882 for (size_t i = 0; i < NUM_TIMINGS_CONVS; ++i) 3882 for (size_t i = 0; i < NUM_TIMINGS_CONVS; ++i)
3883 { 3883 {
3884 ok = StringToDouble(r, txt); 3884 ok = StringToDouble(r, txt);
3885 } 3885 }
3886 boost::chrono::system_clock::time_point end = boost::chrono::system_clock::now(); 3886 boost::posix_time::ptime end = boost::posix_time::microsec_clock::local_time();
3887 boost::chrono::microseconds elapsed = 3887 total_us_StringToDouble += (end - start).total_microseconds();
3888 boost::chrono::duration_cast<boost::chrono::microseconds>(end - start);
3889 total_us_StringToDouble += elapsed.count();
3890 } 3888 }
3891 3889
3892 { 3890 {
3893 boost::chrono::system_clock::time_point start = boost::chrono::system_clock::now(); 3891 boost::posix_time::ptime start = boost::posix_time::microsec_clock::local_time();
3894 for (size_t i = 0; i < NUM_TIMINGS_CONVS; ++i) 3892 for (size_t i = 0; i < NUM_TIMINGS_CONVS; ++i)
3895 { 3893 {
3896 try 3894 try
3897 { 3895 {
3898 r = boost::lexical_cast<double>(txt); 3896 r = boost::lexical_cast<double>(txt);
3901 catch (boost::bad_lexical_cast& ) 3899 catch (boost::bad_lexical_cast& )
3902 { 3900 {
3903 ok = false; 3901 ok = false;
3904 } 3902 }
3905 } 3903 }
3906 boost::chrono::system_clock::time_point end = boost::chrono::system_clock::now(); 3904 boost::posix_time::ptime end = boost::posix_time::microsec_clock::local_time();
3907 boost::chrono::microseconds elapsed = 3905 total_us_lexical_cast += (end - start).total_microseconds();
3908 boost::chrono::duration_cast<boost::chrono::microseconds>(end - start);
3909 total_us_lexical_cast += elapsed.count();
3910 } 3906 }
3911 numConversions += NUM_TIMINGS_CONVS; 3907 numConversions += NUM_TIMINGS_CONVS;
3912 3908
3913 #if 0 3909 #if 0
3914 if (ok) 3910 if (ok)
4093 double r = 0.0; 4089 double r = 0.0;
4094 4090
4095 bool ok = true; 4091 bool ok = true;
4096 4092
4097 { 4093 {
4098 boost::chrono::system_clock::time_point start = boost::chrono::system_clock::now(); 4094 boost::posix_time::ptime start = boost::posix_time::microsec_clock::local_time();
4099 for (size_t i = 0; i < NUM_TIMINGS_CONVS; ++i) 4095 for (size_t i = 0; i < NUM_TIMINGS_CONVS; ++i)
4100 { 4096 {
4101 ok = StringToDouble(r, txt); 4097 ok = StringToDouble(r, txt);
4102 } 4098 }
4103 boost::chrono::system_clock::time_point end = boost::chrono::system_clock::now(); 4099 boost::posix_time::ptime end = boost::posix_time::microsec_clock::local_time();
4104 boost::chrono::microseconds elapsed = 4100 total_us_StringToDouble += (end - start).total_microseconds();
4105 boost::chrono::duration_cast<boost::chrono::microseconds>(end - start);
4106 total_us_StringToDouble += elapsed.count();
4107 } 4101 }
4108 4102
4109 { 4103 {
4110 boost::chrono::system_clock::time_point start = boost::chrono::system_clock::now(); 4104 boost::posix_time::ptime start = boost::posix_time::microsec_clock::local_time();
4111 for (size_t i = 0; i < NUM_TIMINGS_CONVS; ++i) 4105 for (size_t i = 0; i < NUM_TIMINGS_CONVS; ++i)
4112 { 4106 {
4113 try 4107 try
4114 { 4108 {
4115 r = boost::lexical_cast<double>(txt); 4109 r = boost::lexical_cast<double>(txt);
4118 catch (boost::bad_lexical_cast& ) 4112 catch (boost::bad_lexical_cast& )
4119 { 4113 {
4120 ok = false; 4114 ok = false;
4121 } 4115 }
4122 } 4116 }
4123 boost::chrono::system_clock::time_point end = boost::chrono::system_clock::now(); 4117 boost::posix_time::ptime end = boost::posix_time::microsec_clock::local_time();
4124 boost::chrono::microseconds elapsed = 4118 total_us_lexical_cast += (end - start).total_microseconds();
4125 boost::chrono::duration_cast<boost::chrono::microseconds>(end - start);
4126 total_us_lexical_cast += elapsed.count();
4127 } 4119 }
4128 numConversions += NUM_TIMINGS_CONVS; 4120 numConversions += NUM_TIMINGS_CONVS;
4129 4121
4130 #if 0 4122 #if 0
4131 if (ok) 4123 if (ok)