| <html> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> |
| <title>Comparing the performance of a single int_ generator</title> |
| <link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css"> |
| <meta name="generator" content="DocBook XSL Stylesheets V1.75.0"> |
| <link rel="home" href="../../../../index.html" title="Spirit 2.4.1"> |
| <link rel="up" href="../numeric_performance.html" title="Performance of Numeric Generators"> |
| <link rel="prev" href="../numeric_performance.html" title="Performance of Numeric Generators"> |
| <link rel="next" href="double_performance.html" title="Comparing the performance of a single double_ generator"> |
| </head> |
| <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> |
| <table cellpadding="2" width="100%"><tr> |
| <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td> |
| <td align="center"><a href="../../../../../../../../index.html">Home</a></td> |
| <td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td> |
| <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> |
| <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> |
| <td align="center"><a href="../../../../../../../../more/index.htm">More</a></td> |
| </tr></table> |
| <hr> |
| <div class="spirit-nav"> |
| <a accesskey="p" href="../numeric_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="double_performance.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> |
| </div> |
| <div class="section"> |
| <div class="titlepage"><div><div><h5 class="title"> |
| <a name="spirit.karma.performance_measurements.numeric_performance.int_performance"></a><a class="link" href="int_performance.html" title="Comparing the performance of a single int_ generator">Comparing |
| the performance of a single int_ generator</a> |
| </h5></div></div></div> |
| <p> |
| These performance measurements are centered around default formatting |
| of a single <code class="computeroutput"><span class="keyword">int</span></code> integer |
| number using different libraries and methods. The overall execution 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>, |
| and <span class="emphasis"><em>Spirit.Karma</em></span>. |
| </p> |
| <p> |
| For the full source code of the performance test please see here: <a href="../../../../../../optimization/karma/int_generator.cpp" target="_top">int_generator.cpp</a>. |
| All the measurements have been done by executing <code class="computeroutput"><span class="number">1e7</span></code> |
| iterations for each formatting type (NUMITERATIONS is set to <code class="computeroutput"><span class="number">1e7</span></code> in the code shown below). |
| </p> |
| <p> |
| Code used to measure the performance for <code class="computeroutput"><span class="identifier">ltoa</span></code>: |
| </p> |
| <p> |
| |
| </p> |
| <pre class="programlisting"><span class="keyword">char</span> <span class="identifier">buffer</span><span class="special">[</span><span class="number">65</span><span class="special">];</span> <span class="comment">// we don't expect more than 64 bytes to be generated here |
| </span><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">MAX_ITERATION</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> |
| <span class="special">{</span> |
| <span class="identifier">ltoa</span><span class="special">(</span><span class="identifier">v</span><span class="special">[</span><span class="identifier">i</span><span class="special">],</span> <span class="identifier">buffer</span><span class="special">,</span> <span class="number">10</span><span class="special">);</span> |
| <span class="special">}</span> |
| </pre> |
| <p> |
| </p> |
| <p> |
| Code used to measure the performance for standard C++ iostreams: |
| </p> |
| <p> |
| |
| </p> |
| <pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">stringstream</span> <span class="identifier">str</span><span class="special">;</span> |
| <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">MAX_ITERATION</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> |
| <span class="special">{</span> |
| <span class="identifier">str</span><span class="special">.</span><span class="identifier">str</span><span class="special">(</span><span class="string">""</span><span class="special">);</span> |
| <span class="identifier">str</span> <span class="special"><<</span> <span class="identifier">v</span><span class="special">[</span><span class="identifier">i</span><span class="special">];</span> |
| <span class="special">}</span> |
| </pre> |
| <p> |
| </p> |
| <p> |
| Code used to measure the performance for <a href="../../../../../../../../libs/format/index.html" target="_top">Boost.Format</a>: |
| </p> |
| <p> |
| |
| </p> |
| <pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">str</span><span class="special">;</span> |
| <span class="identifier">boost</span><span class="special">::</span><span class="identifier">format</span> <span class="identifier">int_format</span><span class="special">(</span><span class="string">"%d"</span><span class="special">);</span> |
| <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">MAX_ITERATION</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> |
| <span class="special">{</span> |
| <span class="identifier">str</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">int_format</span> <span class="special">%</span> <span class="identifier">v</span><span class="special">[</span><span class="identifier">i</span><span class="special">]);</span> |
| <span class="special">}</span> |
| </pre> |
| <p> |
| </p> |
| <p> |
| Code used to measure the performance for <span class="emphasis"><em>Spirit.Karma</em></span> |
| using a plain character buffer: |
| </p> |
| <p> |
| |
| </p> |
| <pre class="programlisting"><span class="keyword">char</span> <span class="identifier">buffer</span><span class="special">[</span><span class="number">65</span><span class="special">];</span> <span class="comment">// we don't expect more than 64 bytes to be generated here |
| </span><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">MAX_ITERATION</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> |
| <span class="special">{</span> |
| <span class="keyword">char</span> <span class="special">*</span><span class="identifier">ptr</span> <span class="special">=</span> <span class="identifier">buffer</span><span class="special">;</span> |
| <span class="identifier">karma</span><span class="special">::</span><span class="identifier">generate</span><span class="special">(</span><span class="identifier">ptr</span><span class="special">,</span> <span class="identifier">int_</span><span class="special">,</span> <span class="identifier">v</span><span class="special">[</span><span class="identifier">i</span><span class="special">]);</span> |
| <span class="special">*</span><span class="identifier">ptr</span> <span class="special">=</span> <span class="char">'\0'</span><span class="special">;</span> |
| <span class="special">}</span> |
| </pre> |
| <p> |
| </p> |
| <p> |
| The following table shows the overall performance results collected while |
| using different compilers. All times are in seconds measured for <code class="computeroutput"><span class="number">1e7</span></code> iterations (platform: Windows7, Intel |
| Core Duo(tm) Processor, 2.8GHz, 4GByte RAM). For a more readable comparison |
| of the results see this <a class="link" href="int_performance.html#spirit.karma.int_performance" title="Figure 3. Performance comparison for a single int">figure</a>. |
| </p> |
| <div class="table"> |
| <a name="id1111473"></a><p class="title"><b>Table 5. Performance comparison for a single int (all times in [s], `1e7` |
| iterations)</b></p> |
| <div class="table-contents"><table class="table" summary="Performance comparison for a single int (all times in [s], `1e7` |
| iterations)"> |
| <colgroup> |
| <col> |
| <col> |
| <col> |
| <col> |
| <col> |
| <col> |
| <col> |
| </colgroup> |
| <thead><tr> |
| <th> |
| <p> |
| Library |
| </p> |
| </th> |
| <th> |
| <p> |
| gcc 4.4.0 (32 bit) |
| </p> |
| </th> |
| <th> |
| <p> |
| VC++ 10 (32 bit) |
| </p> |
| </th> |
| <th> |
| <p> |
| Intel 11.1 (32 bit) |
| </p> |
| </th> |
| <th> |
| <p> |
| gcc 4.4.0 (64 bit) |
| </p> |
| </th> |
| <th> |
| <p> |
| VC++ 10 (64 bit) |
| </p> |
| </th> |
| <th> |
| <p> |
| Intel 11.1 (64 bit) |
| </p> |
| </th> |
| </tr></thead> |
| <tbody> |
| <tr> |
| <td> |
| <p> |
| ltoa |
| </p> |
| </td> |
| <td> |
| <p> |
| 1.542 |
| </p> |
| </td> |
| <td> |
| <p> |
| 0.895 |
| </p> |
| </td> |
| <td> |
| <p> |
| 0.884 |
| </p> |
| </td> |
| <td> |
| <p> |
| 1.163 |
| </p> |
| </td> |
| <td> |
| <p> |
| 1.099 |
| </p> |
| </td> |
| <td> |
| <p> |
| 0.906 |
| </p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p> |
| iostreams |
| </p> |
| </td> |
| <td> |
| <p> |
| 6.548 |
| </p> |
| </td> |
| <td> |
| <p> |
| 13.727 |
| </p> |
| </td> |
| <td> |
| <p> |
| 11.898 |
| </p> |
| </td> |
| <td> |
| <p> |
| 3.464 |
| </p> |
| </td> |
| <td> |
| <p> |
| 8.316 |
| </p> |
| </td> |
| <td> |
| <p> |
| 8.115 |
| </p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p> |
| <a href="../../../../../../../../libs/format/index.html" target="_top">Boost.Format</a> |
| </p> |
| </td> |
| <td> |
| <p> |
| 16.998 |
| </p> |
| </td> |
| <td> |
| <p> |
| 21.813 |
| </p> |
| </td> |
| <td> |
| <p> |
| 20.477 |
| </p> |
| </td> |
| <td> |
| <p> |
| 17.464 |
| </p> |
| </td> |
| <td> |
| <p> |
| 14.662 |
| </p> |
| </td> |
| <td> |
| <p> |
| 13.646 |
| </p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p> |
| <span class="emphasis"><em>Spirit.Karma</em></span> int_ |
| </p> |
| </td> |
| <td> |
| <p> |
| 1.421 |
| </p> |
| </td> |
| <td> |
| <p> |
| 0.744 |
| </p> |
| </td> |
| <td> |
| <p> |
| 0.697 |
| </p> |
| </td> |
| <td> |
| <p> |
| 1.072 |
| </p> |
| </td> |
| <td> |
| <p> |
| 0.953 |
| </p> |
| </td> |
| <td> |
| <p> |
| 0.606 |
| </p> |
| </td> |
| </tr> |
| </tbody> |
| </table></div> |
| </div> |
| <br class="table-break"><p> |
| </p> |
| <div class="figure"> |
| <a name="spirit.karma.int_performance"></a><p class="title"><b>Figure 3. Performance comparison for a single int</b></p> |
| <div class="figure-contents"><span class="inlinemediaobject"><img src="../../../.././images/int_performance.png" alt="Performance comparison for a single int"></span></div> |
| </div> |
| <p><br class="figure-break"> |
| </p> |
| </div> |
| <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> |
| <td align="left"></td> |
| <td align="right"><div class="copyright-footer">Copyright © 2001-2010 Joel de Guzman, Hartmut Kaiser<p> |
| Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 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>) |
| </p> |
| </div></td> |
| </tr></table> |
| <hr> |
| <div class="spirit-nav"> |
| <a accesskey="p" href="../numeric_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="double_performance.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> |
| </div> |
| </body> |
| </html> |