1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Comparing the performance of a single double_ generator</title> 5<link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../../../index.html" title="Spirit 2.5.8"> 8<link rel="up" href="../numeric_performance.html" title="Performance of Numeric Generators"> 9<link rel="prev" href="int_performance.html" title="Comparing the performance of a single int_ generator"> 10<link rel="next" href="format_performance.html" title="Comparing the performance of a sequence of several generators"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="int_performance.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../numeric_performance.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="format_performance.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h5 class="title"> 27<a name="spirit.karma.performance_measurements.numeric_performance.double_performance"></a><a class="link" href="double_performance.html" title="Comparing the performance of a single double_ generator">Comparing 28 the performance of a single double_ generator</a> 29</h5></div></div></div> 30<p> 31 These performance measurements are centered around default formatting 32 of a single <code class="computeroutput"><span class="keyword">double</span></code> floating 33 point number using different libraries and methods. The overall execution 34 times for those examples are compared below. We compare using <code class="computeroutput"><span class="identifier">sprintf</span></code>, C++ iostreams, <a href="../../../../../../../../libs/format/index.html" target="_top">Boost.Format</a>, 35 and <span class="emphasis"><em>Spirit.Karma</em></span>. 36 </p> 37<p> 38 For the full source code of the performance test please see here: <a href="../../../../../../workbench/karma/double_performance.cpp" target="_top">double_performance.cpp</a>. 39 All the measurements have been done by executing <code class="computeroutput"><span class="number">1e6</span></code> 40 iterations for each formatting type (NUMITERATIONS is set to <code class="computeroutput"><span class="number">1e6</span></code> in the code shown below). 41 </p> 42<p> 43 Code used to measure the performance for <code class="computeroutput"><span class="identifier">sprintf</span></code>: 44 </p> 45<p> 46</p> 47<pre class="programlisting"><span class="keyword">char</span> <span class="identifier">buffer</span><span class="special">[</span><span class="number">256</span><span class="special">];</span> 48<span class="keyword">for</span> <span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="identifier">NUMITERATIONS</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> <span class="special">{</span> 49 <span class="identifier">sprintf</span><span class="special">(</span><span class="identifier">buffer</span><span class="special">,</span> <span class="string">"%f"</span><span class="special">,</span> <span class="number">12345.12345</span><span class="special">);</span> 50<span class="special">}</span> 51</pre> 52<p> 53 </p> 54<p> 55 Code used to measure the performance for standard C++ iostreams: 56 </p> 57<p> 58</p> 59<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">stringstream</span> <span class="identifier">strm</span><span class="special">;</span> 60<span class="keyword">for</span> <span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="identifier">NUMITERATIONS</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> <span class="special">{</span> 61 <span class="identifier">strm</span><span class="special">.</span><span class="identifier">str</span><span class="special">(</span><span class="string">""</span><span class="special">);</span> 62 <span class="identifier">strm</span> <span class="special"><<</span> <span class="number">12345.12345</span><span class="special">;</span> 63<span class="special">}</span> 64</pre> 65<p> 66 </p> 67<p> 68 Code used to measure the performance for <a href="../../../../../../../../libs/format/index.html" target="_top">Boost.Format</a>: 69 </p> 70<p> 71</p> 72<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">generated</span><span class="special">;</span> 73<span class="identifier">boost</span><span class="special">::</span><span class="identifier">format</span> <span class="identifier">double_format</span><span class="special">(</span><span class="string">"%f"</span><span class="special">);</span> 74<span class="keyword">for</span> <span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="identifier">NUMITERATIONS</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> 75 <span class="identifier">generated</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">str</span><span class="special">(</span><span class="identifier">double_format</span> <span class="special">%</span> <span class="number">12345.12345</span><span class="special">);</span> 76</pre> 77<p> 78 </p> 79<p> 80 The following code shows the common definitions used by all <span class="emphasis"><em>Spirit.Karma</em></span> 81 performance measurements as listed below: 82 </p> 83<p> 84</p> 85<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">karma</span><span class="special">::</span><span class="identifier">double_</span><span class="special">;</span> 86</pre> 87<p> 88 </p> 89<p> 90 Code used to measure the performance for <span class="emphasis"><em>Spirit.Karma</em></span> 91 using a plain character buffer: 92 </p> 93<p> 94</p> 95<pre class="programlisting"><span class="keyword">char</span> <span class="identifier">buffer</span><span class="special">[</span><span class="number">256</span><span class="special">];</span> 96<span class="keyword">for</span> <span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="identifier">NUMITERATIONS</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> <span class="special">{</span> 97 <span class="keyword">char</span> <span class="special">*</span><span class="identifier">p</span> <span class="special">=</span> <span class="identifier">buffer</span><span class="special">;</span> 98 <span class="identifier">generate</span><span class="special">(</span><span class="identifier">p</span><span class="special">,</span> <span class="identifier">double_</span><span class="special">,</span> <span class="number">12345.12345</span><span class="special">);</span> 99 <span class="special">*</span><span class="identifier">p</span> <span class="special">=</span> <span class="char">'\0'</span><span class="special">;</span> 100<span class="special">}</span> 101</pre> 102<p> 103 </p> 104<p> 105 The following table shows the overall performance results collected while 106 using different compilers. All times are in seconds measured for <code class="computeroutput"><span class="number">1e6</span></code> iterations (platform: Windows7, Intel 107 Core Duo(tm) Processor, 2.8GHz, 4GByte RAM). For a more readable comparison 108 of the results see this <a class="link" href="double_performance.html#spirit.karma.double_performance" title="Figure 4. Performance comparison for a single double">figure</a>. 109 </p> 110<div class="table"> 111<a name="spirit.karma.performance_measurements.numeric_performance.double_performance.performance_comparison_for_a_single_double__all_times_in__s____1e6__iterations_"></a><p class="title"><b>Table 6. Performance comparison for a single double (all times in [s], 112 `1e6` iterations)</b></p> 113<div class="table-contents"><table class="table" summary="Performance comparison for a single double (all times in [s], 114 `1e6` iterations)"> 115<colgroup> 116<col> 117<col> 118<col> 119<col> 120<col> 121<col> 122<col> 123</colgroup> 124<thead><tr> 125<th> 126 <p> 127 Library 128 </p> 129 </th> 130<th> 131 <p> 132 gcc 4.4.0 (32 bit) 133 </p> 134 </th> 135<th> 136 <p> 137 VC++ 10 (32 bit) 138 </p> 139 </th> 140<th> 141 <p> 142 Intel 11.1 (32 bit) 143 </p> 144 </th> 145<th> 146 <p> 147 gcc 4.4.0 (64 bit) 148 </p> 149 </th> 150<th> 151 <p> 152 VC++ 10 (64 bit) 153 </p> 154 </th> 155<th> 156 <p> 157 Intel 11.1 (64 bit) 158 </p> 159 </th> 160</tr></thead> 161<tbody> 162<tr> 163<td> 164 <p> 165 sprintf 166 </p> 167 </td> 168<td> 169 <p> 170 0.755 171 </p> 172 </td> 173<td> 174 <p> 175 0.965 176 </p> 177 </td> 178<td> 179 <p> 180 0.880 181 </p> 182 </td> 183<td> 184 <p> 185 0.713 186 </p> 187 </td> 188<td> 189 <p> 190 0.807 191 </p> 192 </td> 193<td> 194 <p> 195 0.694 196 </p> 197 </td> 198</tr> 199<tr> 200<td> 201 <p> 202 iostreams 203 </p> 204 </td> 205<td> 206 <p> 207 2.316 208 </p> 209 </td> 210<td> 211 <p> 212 2.624 213 </p> 214 </td> 215<td> 216 <p> 217 1.964 218 </p> 219 </td> 220<td> 221 <p> 222 1.634 223 </p> 224 </td> 225<td> 226 <p> 227 1.468 228 </p> 229 </td> 230<td> 231 <p> 232 1.354 233 </p> 234 </td> 235</tr> 236<tr> 237<td> 238 <p> 239 <a href="../../../../../../../../libs/format/index.html" target="_top">Boost.Format</a> 240 </p> 241 </td> 242<td> 243 <p> 244 3.188 245 </p> 246 </td> 247<td> 248 <p> 249 3.737 250 </p> 251 </td> 252<td> 253 <p> 254 2.878 255 </p> 256 </td> 257<td> 258 <p> 259 3.217 260 </p> 261 </td> 262<td> 263 <p> 264 2.672 265 </p> 266 </td> 267<td> 268 <p> 269 2.011 270 </p> 271 </td> 272</tr> 273<tr> 274<td> 275 <p> 276 <span class="emphasis"><em>Spirit.Karma</em></span> double_ 277 </p> 278 </td> 279<td> 280 <p> 281 0.813 282 </p> 283 </td> 284<td> 285 <p> 286 0.561 287 </p> 288 </td> 289<td> 290 <p> 291 0.368 292 </p> 293 </td> 294<td> 295 <p> 296 0.426 297 </p> 298 </td> 299<td> 300 <p> 301 0.260 302 </p> 303 </td> 304<td> 305 <p> 306 0.218 307 </p> 308 </td> 309</tr> 310</tbody> 311</table></div> 312</div> 313<br class="table-break"><p> 314 </p> 315<div class="figure"> 316<a name="spirit.karma.double_performance"></a><p class="title"><b>Figure 4. Performance comparison for a single double</b></p> 317<div class="figure-contents"><span class="inlinemediaobject"><img src="../../../.././images/double_performance.png" alt="Performance comparison for a single double"></span></div> 318</div> 319<p><br class="figure-break"> 320 </p> 321</div> 322<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 323<td align="left"></td> 324<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p> 325 Distributed under the Boost Software License, Version 1.0. (See accompanying 326 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 327 </p> 328</div></td> 329</tr></table> 330<hr> 331<div class="spirit-nav"> 332<a accesskey="p" href="int_performance.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../numeric_performance.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="format_performance.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 333</div> 334</body> 335</html> 336