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 | |
---|
13 | bjam -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 | |
---|
20 | intel-linux-7.1 |
---|
21 | |
---|
22 | for 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 |
---|
30 | done |
---|
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 |
---|
36 | printf time :2.16 |
---|
37 | ostream time : 3.69, = 1.70833 * printf |
---|
38 | parsed-once time : 8.45, = 3.91204 * printf , = 2.28997 * nullStream |
---|
39 | reused format time :10.94, = 5.06481 * printf , = 2.96477 * nullStream |
---|
40 | format time :10.97, = 5.0787 * printf , = 2.9729 * nullStream |
---|
41 | |
---|
42 | |
---|
43 | Pour 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 |
---|
49 | printf time :2.21 |
---|
50 | ostream time : 3.57, = 1.61538 * printf |
---|
51 | parsed-once time : 4.93, = 2.23077 * printf , = 1.38095 * nullStream |
---|
52 | reused format time : 9.25, = 4.18552 * printf , = 2.59104 * nullStream |
---|
53 | format 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 |
---|
57 | printf time :2.2 |
---|
58 | ostream time : 3.57, = 1.62273 * printf |
---|
59 | parsed-once time : 4.85, = 2.20455 * printf , = 1.35854 * nullStream |
---|
60 | reused format time : 9.25, = 4.20455 * printf , = 2.59104 * nullStream |
---|
61 | format 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 |
---|
65 | printf time :2.27 |
---|
66 | ostream time : 3.47, = 1.52863 * printf |
---|
67 | parsed-once time : 4.79, = 2.11013 * printf , = 1.3804 * nullStream |
---|
68 | reused format time : 9.88, = 4.35242 * printf , = 2.84726 * nullStream |
---|
69 | format time :10.97, = 4.8326 * printf , = 3.16138 * nullStream |
---|
70 | |
---|
71 | ------------------------------------------------------------------------------------------------- |
---|
72 | Overload : 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 |
---|
119 | printf time :2.13 |
---|
120 | ostream time : 2.91, = 1.3662 * printf |
---|
121 | parsed-once time : 4.48, = 2.10329 * printf , = 1.53952 * nullStream |
---|
122 | reused format time : 9.42, = 4.42254 * printf , = 3.23711 * nullStream |
---|
123 | format time : 11.1, = 5.21127 * printf , = 3.81443 * nullStream |
---|
124 | |
---|
125 | RERUN |
---|
126 | printf time :2.09 |
---|
127 | ostream time : 2.92, = 1.39713 * printf |
---|
128 | parsed-once time : 4.43, = 2.11962 * printf , = 1.51712 * nullStream |
---|
129 | reused format time : 9.29, = 4.44498 * printf , = 3.18151 * nullStream |
---|
130 | format 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 |
---|
134 | printf time :2.16 |
---|
135 | ostream time : 3.01, = 1.39352 * printf |
---|
136 | parsed-once time : 4.41, = 2.04167 * printf , = 1.46512 * nullStream |
---|
137 | reused format time : 9.61, = 4.44907 * printf , = 3.19269 * nullStream |
---|
138 | format 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 |
---|
142 | printf time :2.1 |
---|
143 | ostream time : 2.87, = 1.36667 * printf |
---|
144 | parsed-once time : 4.44, = 2.11429 * printf , = 1.54704 * nullStream |
---|
145 | reused format time : 8.21, = 3.90952 * printf , = 2.86063 * nullStream |
---|
146 | format 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 |
---|
150 | printf time :2.18 |
---|
151 | ostream time : 2.92, = 1.33945 * printf |
---|
152 | parsed-once time : 5.75, = 2.63761 * printf , = 1.96918 * nullStream |
---|
153 | reused 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 |
---|
178 | printf time :2.16 |
---|
179 | ostream time : 2.81, = 1.30093 * printf |
---|
180 | stored format time :11.56, = 5.35185 * printf , = 4.11388 * nullStream |
---|
181 | format 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 |
---|
185 | printf time :2.1 |
---|
186 | ostream time : 2.79, = 1.32857 * printf |
---|
187 | stored format time : 4.5, = 2.14286 * printf , = 1.6129 * nullStream |
---|
188 | format 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 |
---|
192 | printf time :2.22 |
---|
193 | ostream time : 2.88, = 1.2973 * printf |
---|
194 | stored format time : 4.45, = 2.0045 * printf , = 1.54514 * nullStream |
---|
195 | format time :11.67, = 5.25676 * printf , = 4.05208 * nullStream |
---|
196 | |
---|
197 | |
---|
198 | |
---|
199 | |
---|
200 | |
---|
201 | The 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 |
---|
206 | printf time :2.21 |
---|
207 | ostream time : 3.1, = 1.40271 * printf |
---|
208 | stored format time :11.53, = 3.71935 * stream |
---|
209 | format 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 |
---|
213 | printf time :2.19 |
---|
214 | ostream time : 3.09, = 1.41096 * printf |
---|
215 | stored format time : 4.63, = 1.49838 * stream |
---|
216 | format 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 |
---|
220 | printf time :2.23 |
---|
221 | ostream time : 3.14, = 1.40807 * printf |
---|
222 | stored format time : 4.61, = 1.46815 * stream |
---|
223 | format time :11.33, = 3.60828 * stream |
---|
224 | |
---|
225 | |
---|
226 | |
---|
227 | |
---|
228 | |
---|
229 | |
---|
230 | |
---|
231 | ------------------- Compiler gcc : ---------------- |
---|
232 | -- Variant _normal : |
---|
233 | printf time :2.15 |
---|
234 | ostream time :4.42, = 2.05581 * printf |
---|
235 | stored format time :5.85, = 1.32353 * stream |
---|
236 | format time :11.53, = 2.6086 * stream |
---|
237 | -- Variant _no_reuse_stream : |
---|
238 | printf time :2.13 |
---|
239 | ostream time :4.4, = 2.06573 * printf |
---|
240 | stored format time :11.1, = 2.52273 * stream |
---|
241 | format time :14.3, = 3.25 * stream |
---|
242 | -- Variant _stringstr : |
---|
243 | printf time :2.01 |
---|
244 | ostream time :4.42, = 2.199 * printf |
---|
245 | stored format time :7.92, = 1.79186 * stream |
---|
246 | format time :12.8, = 2.89593 * stream |
---|
247 | |
---|
248 | ------------------- Compiler intel-linux-7.1 : ---------------- |
---|
249 | -- Variant _normal : |
---|
250 | printf time :2.08 |
---|
251 | ostream time :4.49, = 2.15865 * printf |
---|
252 | stored format time :5.3, = 1.1804 * stream |
---|
253 | format time :17.8, = 3.96437 * stream |
---|
254 | -- Variant _no_reuse_stream : |
---|
255 | printf time :2.09 |
---|
256 | ostream time :4.37, = 2.09091 * printf |
---|
257 | stored format time :10.07, = 2.30435 * stream |
---|
258 | format time :14.46, = 3.30892 * stream |
---|
259 | -- Variant _stringstr : |
---|
260 | printf time :1.99 |
---|
261 | ostream time :5.16, = 2.59296 * printf |
---|
262 | stored format time :5.83, = 1.12984 * stream |
---|
263 | format 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 | /*** |
---|
273 | printf time :1.2 |
---|
274 | ostream time :2.84, = 2.36667 * printf |
---|
275 | stored format time :8.91, = 3.13732 * stream |
---|
276 | format time :15.35, = 5.40493 * stream |
---|
277 | format3 time :21.83, = 7.68662 * stream |
---|
278 | ***/ |
---|
279 | |
---|
280 | |
---|
281 | // With flag -O |
---|
282 | |
---|
283 | /*** |
---|
284 | printf time :1.16 |
---|
285 | ostream time :1.94, = 1.67241 * printf |
---|
286 | stored format time :3.68, = 1.89691 * stream |
---|
287 | format time :6.31, = 3.25258 * stream |
---|
288 | format3 time :9.04, = 4.65979 * stream |
---|
289 | ***/ |
---|
290 | |
---|
291 | // ==> that's quite acceptable. |
---|
292 | |
---|
293 | // ------------------------------------------------------------------------------ |
---|