1// Copyright (c) 2001 Samuel Krempp 2// krempp@crans.ens-cachan.fr 3// Distributed under the Boost Software License, Version 1.0. (See accompany- 4// ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 6// This benchmark is provided purely for information. 7// It might not even compile as-is, 8// or not give any sensible results. 9// (e.g., it expects sprintf to be POSIX compliant) 10 11 new results ( with outsstream vs. stringstream) 12 13bjam -sTOOLS="gcc intel-linux-7.1" -sBUILD="release" 14 15( -sBUILD="profile" for profiling..) 16 17 18 "_no_reuse_stream" "_stringstr" "_strstream" _no_locale 19 20intel-linux-7.1 21 22for comp in gcc ; do 23 echo "\n------------------- Compiler $comp : ---------------- " 24 for var in _overloads _basicfmt _normal; do 25 echo "\n-- Variant **" $var "**" : 26 texe=$EXEBOOST/libs/format/benchmark/bench_format${var}/${comp}/release/bench_format${var} ; 27 ls -l $texe; 28 $texe 29 done 30done 31 32 33// stringstream recr�� chaque fois. 34-- Variant ** _normal ** : 35-rwx--x--x 1 sam users 61952 Sep 17 03:13 /home/data/zStore/BBoost/bin/boost//libs/format/benchmark/bench_format_normal/gcc/release/bench_format_normal 36printf time :2.16 37ostream time : 3.69, = 1.70833 * printf 38parsed-once time : 8.45, = 3.91204 * printf , = 2.28997 * nullStream 39reused format time :10.94, = 5.06481 * printf , = 2.96477 * nullStream 40format time :10.97, = 5.0787 * printf , = 2.9729 * nullStream 41 42 43Pour le parsing. step 1 : scan_not + str2int (version Iter const& qques % mieux) 44 45------------------- Compiler gcc : ---------------- 46 47-- Variant ** _overloads ** : 48-rwx--x--x 1 sam users 52864 2003-09-12 02:59 /home/sam/progs/Boost/bin/BBoost//libs/format/benchmark/bench_format_overloads/gcc/release/bench_format_overloads 49printf time :2.21 50ostream time : 3.57, = 1.61538 * printf 51parsed-once time : 4.93, = 2.23077 * printf , = 1.38095 * nullStream 52reused format time : 9.25, = 4.18552 * printf , = 2.59104 * nullStream 53format time :10.33, = 4.67421 * printf , = 2.89356 * nullStream 54 55-- Variant ** _basicfmt ** : 56-rwx--x--x 1 sam users 52864 2003-09-12 03:00 /home/sam/progs/Boost/bin/BBoost//libs/format/benchmark/bench_format_basicfmt/gcc/release/bench_format_basicfmt 57printf time :2.2 58ostream time : 3.57, = 1.62273 * printf 59parsed-once time : 4.85, = 2.20455 * printf , = 1.35854 * nullStream 60reused format time : 9.25, = 4.20455 * printf , = 2.59104 * nullStream 61format time :10.29, = 4.67727 * printf , = 2.88235 * nullStream 62 63-- Variant ** _normal ** : 64-rwx--x--x 1 sam users 53088 2003-09-12 03:00 /home/sam/progs/Boost/bin/BBoost//libs/format/benchmark/bench_format_normal/gcc/release/bench_format_normal 65printf time :2.27 66ostream time : 3.47, = 1.52863 * printf 67parsed-once time : 4.79, = 2.11013 * printf , = 1.3804 * nullStream 68reused format time : 9.88, = 4.35242 * printf , = 2.84726 * nullStream 69format time :10.97, = 4.8326 * printf , = 3.16138 * nullStream 70 71------------------------------------------------------------------------------------------------- 72Overload : int, double char * -> put_simple : 73#if defined(BOOST_FORMAT_OVERLOADS) 74 template<class T> 75 basic_format& operator%(const char* x) 76 { return io::detail::feed_overloaded(*this,x); } 77 template<class T> 78 basic_format& operator%(const double x) 79 { return io::detail::feed_overloaded(*this,x); } 80 template<class T> 81 basic_format& operator%(const int x) 82 { return io::detail::feed_overloaded(*this,x); } 83#endif 84 85 // put overloads for common types (-> faster) 86 template< class Ch, class Tr, class T> 87 void put_simple( T x, 88 const format_item<Ch, Tr>& specs, 89 std::basic_string<Ch, Tr> & res, 90 io::basic_outsstream<Ch, Tr>& oss_ ) 91 { 92 typedef std::basic_string<Ch, Tr> string_t; 93 typedef format_item<Ch, Tr> format_item_t; 94 95 specs.fmtstate_.apply_on(oss_); 96 const std::ios_base::fmtflags fl=oss_.flags(); 97 const std::streamsize w = oss_.width(); 98 99 if(w!=0) 100 oss_.width(0); 101 put_last( oss_, x); 102 const Ch * res_beg = oss_.begin(); 103 std::streamsize res_size = std::min(specs.truncate_, oss_.pcount()); 104 int prefix_space = 0; 105 if(specs.pad_scheme_ & format_item_t::spacepad) 106 if( res_size == 0 || ( res_beg[0] !='+' && res_beg[0] !='-' )) 107 prefix_space = 1; 108 mk_str(res, res_beg, res_size, w, oss_.fill(), fl, 109 prefix_space, (specs.pad_scheme_ & format_item_t::centered) !=0 ); 110 clear_buffer( oss_); 111 } // end- put_simple(..) 112 113 114 115------------------- Compiler gcc : ---------------- 116 117-- Variant ** _overloads ** : 118-rwx--x--x 1 sam users 52832 2003-09-12 00:17 /home/sam/progs/Boost/bin/BBoost//libs/format/benchmark/bench_format_overloads/gcc/release/bench_format_overloads 119printf time :2.13 120ostream time : 2.91, = 1.3662 * printf 121parsed-once time : 4.48, = 2.10329 * printf , = 1.53952 * nullStream 122reused format time : 9.42, = 4.42254 * printf , = 3.23711 * nullStream 123format time : 11.1, = 5.21127 * printf , = 3.81443 * nullStream 124 125RERUN 126printf time :2.09 127ostream time : 2.92, = 1.39713 * printf 128parsed-once time : 4.43, = 2.11962 * printf , = 1.51712 * nullStream 129reused format time : 9.29, = 4.44498 * printf , = 3.18151 * nullStream 130format time :11.05, = 5.28708 * printf , = 3.78425 * nullStream 131 132-- Variant ** _basicfmt ** : 133-rwx--x--x 1 sam users 52832 2003-09-12 00:17 /home/sam/progs/Boost/bin/BBoost//libs/format/benchmark/bench_format_basicfmt/gcc/release/bench_format_basicfmt 134printf time :2.16 135ostream time : 3.01, = 1.39352 * printf 136parsed-once time : 4.41, = 2.04167 * printf , = 1.46512 * nullStream 137reused format time : 9.61, = 4.44907 * printf , = 3.19269 * nullStream 138format time :11.02, = 5.10185 * printf , = 3.66113 * nullStream 139 140-- Variant ** _no_locale ** : 141-rwx--x--x 1 sam users 52192 2003-09-12 00:09 /home/sam/progs/Boost/bin/BBoost//libs/format/benchmark/bench_format_no_locale/gcc/release/bench_format_no_locale 142printf time :2.1 143ostream time : 2.87, = 1.36667 * printf 144parsed-once time : 4.44, = 2.11429 * printf , = 1.54704 * nullStream 145reused format time : 8.21, = 3.90952 * printf , = 2.86063 * nullStream 146format time : 9.25, = 4.40476 * printf , = 3.223 * nullStream 147 148-- Variant ** _normal ** : 149-rwx--x--x 1 sam users 53056 2003-09-12 00:17 /home/sam/progs/Boost/bin/BBoost//libs/format/benchmark/bench_format_normal/gcc/release/bench_format_normal 150printf time :2.18 151ostream time : 2.92, = 1.33945 * printf 152parsed-once time : 5.75, = 2.63761 * printf , = 1.96918 * nullStream 153reused format time :10.27, = 4.71101 * printf , = 3.51712 * nullStream 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174------------------- Compiler gcc : ---------------- 175 176-- Variant ** _normal ** : 177-rwx--x--x 1 sam users 49280 2003-09-10 21:12 /home/sam/progs/Boost/bin/BBoost//libs/format/benchmark/bench_format_normal/gcc/release/bench_format_normal 178printf time :2.16 179ostream time : 2.81, = 1.30093 * printf 180stored format time :11.56, = 5.35185 * printf , = 4.11388 * nullStream 181format time :18.69, = 8.65278 * printf , = 6.65125 * nullStream 182 183-- Variant ** _static_stream ** : 184-rwx--x--x 1 sam users 45856 2003-09-10 21:13 /home/sam/progs/Boost/bin/BBoost//libs/format/benchmark/bench_format_static_stream/gcc/release/bench_format_static_stream 185printf time :2.1 186ostream time : 2.79, = 1.32857 * printf 187stored format time : 4.5, = 2.14286 * printf , = 1.6129 * nullStream 188format time :10.05, = 4.78571 * printf , = 3.60215 * nullStream 189 190-- Variant ** _basicfmt ** : 191-rwx--x--x 1 sam users 47200 2003-09-10 21:13 /home/sam/progs/Boost/bin/BBoost//libs/format/benchmark/bench_format_basicfmt/gcc/release/bench_format_basicfmt 192printf time :2.22 193ostream time : 2.88, = 1.2973 * printf 194stored format time : 4.45, = 2.0045 * printf , = 1.54514 * nullStream 195format time :11.67, = 5.25676 * printf , = 4.05208 * nullStream 196 197 198 199 200 201The cost of imbuing locale after each object is fed : 202 203------------------- Compiler gcc : ---------------- 204-- Variant _normal : 205-rwx--x--x 1 sam users 49920 2003-09-10 20:23 /home/sam/progs/Boost/bin/BBoost//libs/format/benchmark/bench_format_normal/gcc/release/bench_format_normal 206printf time :2.21 207ostream time : 3.1, = 1.40271 * printf 208stored format time :11.53, = 3.71935 * stream 209format time :18.86, = 6.08387 * stream 210 211-- Variant _static_stream : 212-rwx--x--x 1 sam users 43232 2003-09-10 20:24 /home/sam/progs/Boost/bin/BBoost//libs/format/benchmark/bench_format_static_stream/gcc/release/bench_format_static_stream 213printf time :2.19 214ostream time : 3.09, = 1.41096 * printf 215stored format time : 4.63, = 1.49838 * stream 216format time :10.12, = 3.27508 * stream 217 218-- Variant _basicfmt : 219-rwx--x--x 1 sam users 45760 2003-09-10 20:24 /home/sam/progs/Boost/bin/BBoost//libs/format/benchmark/bench_format_basicfmt/gcc/release/bench_format_basicfmt 220printf time :2.23 221ostream time : 3.14, = 1.40807 * printf 222stored format time : 4.61, = 1.46815 * stream 223format time :11.33, = 3.60828 * stream 224 225 226 227 228 229 230 231------------------- Compiler gcc : ---------------- 232-- Variant _normal : 233printf time :2.15 234ostream time :4.42, = 2.05581 * printf 235stored format time :5.85, = 1.32353 * stream 236format time :11.53, = 2.6086 * stream 237-- Variant _no_reuse_stream : 238printf time :2.13 239ostream time :4.4, = 2.06573 * printf 240stored format time :11.1, = 2.52273 * stream 241format time :14.3, = 3.25 * stream 242-- Variant _stringstr : 243printf time :2.01 244ostream time :4.42, = 2.199 * printf 245stored format time :7.92, = 1.79186 * stream 246format time :12.8, = 2.89593 * stream 247 248------------------- Compiler intel-linux-7.1 : ---------------- 249-- Variant _normal : 250printf time :2.08 251ostream time :4.49, = 2.15865 * printf 252stored format time :5.3, = 1.1804 * stream 253format time :17.8, = 3.96437 * stream 254-- Variant _no_reuse_stream : 255printf time :2.09 256ostream time :4.37, = 2.09091 * printf 257stored format time :10.07, = 2.30435 * stream 258format time :14.46, = 3.30892 * stream 259-- Variant _stringstr : 260printf time :1.99 261ostream time :5.16, = 2.59296 * printf 262stored format time :5.83, = 1.12984 * stream 263format time :17.42, = 3.37597 * stream 264 265 266 267 268// older Result with gcc-3.03 on linux : 269 270// With flag -g : 271 272/*** 273printf time :1.2 274ostream time :2.84, = 2.36667 * printf 275stored format time :8.91, = 3.13732 * stream 276format time :15.35, = 5.40493 * stream 277format3 time :21.83, = 7.68662 * stream 278***/ 279 280 281// With flag -O 282 283/*** 284printf time :1.16 285ostream time :1.94, = 1.67241 * printf 286stored format time :3.68, = 1.89691 * stream 287format time :6.31, = 3.25258 * stream 288format3 time :9.04, = 4.65979 * stream 289***/ 290 291// ==> that's quite acceptable. 292 293// ------------------------------------------------------------------------------ 294