1 // speed_test.cpp --------------------------------------------------------------------//
3 // Copyright Beman Dawes 2013
5 // Distributed under the Boost Software License, Version 1.0.
6 // http://www.boost.org/LICENSE_1_0.txt
8 //--------------------------------------------------------------------------------------//
10 //#define BOOST_ENDIAN_NO_INTRINSICS
11 //#define BOOST_ENDIAN_LOG
13 #include <boost/endian/detail/disable_warnings.hpp>
15 #include "speed_test_functions.hpp"
16 #include <boost/endian/conversion.hpp>
17 #include <boost/endian/arithmetic.hpp>
18 #include <boost/cstdint.hpp>
19 #include <boost/timer/timer.hpp>
22 #include <boost/detail/lightweight_main.hpp>
24 using namespace boost
;
25 using namespace boost::endian
;
32 typedef boost::timer::nanosecond_type nanosecond_t
;
33 std::string command_args
;
34 uint64_t n
; // number of test cases to run
35 int places
= 2; // decimal places for times
38 void process_command_line(int argc
, char * argv
[])
40 for (int a
= 0; a
< argc
; ++a
)
42 command_args
+= argv
[a
];
47 // cout << command_args << '\n';;
56 for (; argc
> 2; ++argv
, --argc
)
58 if ( *(argv
[2]+1) == 'p' )
59 places
= atoi( argv
[2]+2 );
60 else if ( *(argv
[2]+1) == 'v' )
64 cout
<< "Error - unknown option: " << argv
[2] << "\n\n";
72 cout
<< "Usage: speed_test n [Options]\n"
73 " The argument n specifies the number of test cases to run\n"
75 " -v Verbose messages\n"
76 " -p# Decimal places for times; default -p" << places
<< "\n";
81 //--------------------------------------------------------------------------------------//
83 template <class T
, class EndianT
, class Function
>
88 boost::timer::cpu_timer t
;
89 for (uint64_t i
= 0; i
< n
; ++i
)
94 cout
<< "<td align=\"right\">" << t
.format(places
, "%t") << " s</td>";
99 cout
<< "<tr><td>16-bit aligned big endian</td>";
100 time
<int16_t, big_int16_t
>(user::return_x_big_int16
);
101 time
<int16_t, big_int16_t
>(user::return_x_value_big_int16
);
102 time
<int16_t, big_int16_t
>(user::return_x_inplace_big_int16
);
103 time
<int16_t, big_int16_t
>(user::return_y_big_int16
);
107 void test_little_int16()
109 cout
<< "<tr><td>16-bit aligned little endian</td>";
110 time
<int16_t, little_int16_t
>(user::return_x_little_int16
);
111 time
<int16_t, little_int16_t
>(user::return_x_value_little_int16
);
112 time
<int16_t, little_int16_t
>(user::return_x_inplace_little_int16
);
113 time
<int16_t, little_int16_t
>(user::return_y_little_int16
);
117 void test_big_int32()
119 cout
<< "<tr><td>32-bit aligned big endian</td>";
120 time
<int32_t, big_int32_t
>(user::return_x_big_int32
);
121 time
<int32_t, big_int32_t
>(user::return_x_value_big_int32
);
122 time
<int32_t, big_int32_t
>(user::return_x_inplace_big_int32
);
123 time
<int32_t, big_int32_t
>(user::return_y_big_int32
);
127 void test_little_int32()
129 cout
<< "<tr><td>32-bit aligned little endian</td>";
130 time
<int32_t, little_int32_t
>(user::return_x_little_int32
);
131 time
<int32_t, little_int32_t
>(user::return_x_value_little_int32
);
132 time
<int32_t, little_int32_t
>(user::return_x_inplace_little_int32
);
133 time
<int32_t, little_int32_t
>(user::return_y_little_int32
);
137 void test_big_int64()
139 cout
<< "<tr><td>64-bit aligned big endian</td>";
140 time
<int64_t, big_int64_t
>(user::return_x_big_int64
);
141 time
<int64_t, big_int64_t
>(user::return_x_value_big_int64
);
142 time
<int64_t, big_int64_t
>(user::return_x_inplace_big_int64
);
143 time
<int64_t, big_int64_t
>(user::return_y_big_int64
);
147 void test_little_int64()
149 cout
<< "<tr><td>64-bit aligned little endian</td>";
150 time
<int64_t, little_int64_t
>(user::return_x_little_int64
);
151 time
<int64_t, little_int64_t
>(user::return_x_value_little_int64
);
152 time
<int64_t, little_int64_t
>(user::return_x_inplace_little_int64
);
153 time
<int64_t, little_int64_t
>(user::return_y_little_int64
);
157 } // unnamed namespace
159 //--------------------------------------------------------------------------------------//
161 int cpp_main(int argc
, char* argv
[])
163 process_command_line(argc
, argv
);
166 << "<html>\n<head>\n<title>Endian Speed Test</title>\n</head>\n<body>\n"
167 << "<table border=\"1\" cellpadding=\"5\" cellspacing=\"0\""
168 << "style=\"border-collapse: collapse\" bordercolor=\"#111111\">\n"
169 << "<tr><td colspan=\"6\" align=\"center\"><b>"
170 << BOOST_COMPILER
<< "</b></td></tr>\n"
171 << "<tr><td colspan=\"6\" align=\"center\"><b>"
172 << " Iterations: " << n
173 << ", Intrinsics: " BOOST_ENDIAN_INTRINSIC_MSG
174 << "</b></td></tr>\n"
175 << "<tr><td><b>Test Case</b></td>\n"
176 "<td align=\"center\"><b>int<br>arg</b></td>\n"
177 "<td align=\"center\"><b>int<br>value(arg)</b></td>\n"
178 "<td align=\"center\"><b>int<br>in place(arg)</b></td>\n"
179 "<td align=\"center\"><b>Endian<br>arg</b></td>\n"
190 cout
<< "\n</table>\n</body>\n</html>\n";
195 #include <boost/endian/detail/disable_warnings_pop.hpp>