• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Comparing the performance of a single int_ 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="../numeric_performance.html" title="Performance of Numeric Generators">
10<link rel="next" href="double_performance.html" title="Comparing the performance of a single double_ generator">
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="../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>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h5 class="title">
27<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
28          the performance of a single int_ 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">int</span></code> integer
33            number using different libraries and methods. The overall execution times
34            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/int_generator.cpp" target="_top">int_generator.cpp</a>.
39            All the measurements have been done by executing <code class="computeroutput"><span class="number">1e7</span></code>
40            iterations for each formatting type (NUMITERATIONS is set to <code class="computeroutput"><span class="number">1e7</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">ltoa</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">65</span><span class="special">];</span> <span class="comment">// we don't expect more than 64 bytes to be generated here</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">&lt;</span> <span class="identifier">MAX_ITERATION</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
49<span class="special">{</span>
50    <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>
51<span class="special">}</span>
52</pre>
53<p>
54          </p>
55<p>
56            Code used to measure the performance for standard C++ iostreams:
57          </p>
58<p>
59</p>
60<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>
61<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">&lt;</span> <span class="identifier">MAX_ITERATION</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
62<span class="special">{</span>
63    <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>
64    <span class="identifier">str</span> <span class="special">&lt;&lt;</span> <span class="identifier">v</span><span class="special">[</span><span class="identifier">i</span><span class="special">];</span>
65<span class="special">}</span>
66</pre>
67<p>
68          </p>
69<p>
70            Code used to measure the performance for <a href="../../../../../../../../libs/format/index.html" target="_top">Boost.Format</a>:
71          </p>
72<p>
73</p>
74<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>
75<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>
76<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">&lt;</span> <span class="identifier">MAX_ITERATION</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
77<span class="special">{</span>
78    <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>
79<span class="special">}</span>
80</pre>
81<p>
82          </p>
83<p>
84            Code used to measure the performance for <span class="emphasis"><em>Spirit.Karma</em></span>
85            using a plain character buffer:
86          </p>
87<p>
88</p>
89<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>
90<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">&lt;</span> <span class="identifier">MAX_ITERATION</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
91<span class="special">{</span>
92    <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>
93    <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>
94    <span class="special">*</span><span class="identifier">ptr</span> <span class="special">=</span> <span class="char">'\0'</span><span class="special">;</span>
95<span class="special">}</span>
96</pre>
97<p>
98          </p>
99<p>
100            The following table shows the overall performance results collected while
101            using different compilers. All times are in seconds measured for <code class="computeroutput"><span class="number">1e7</span></code> iterations (platform: Windows7, Intel
102            Core Duo(tm) Processor, 2.8GHz, 4GByte RAM). For a more readable comparison
103            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>.
104          </p>
105<div class="table">
106<a name="spirit.karma.performance_measurements.numeric_performance.int_performance.performance_comparison_for_a_single_int__all_times_in__s____1e7__iterations_"></a><p class="title"><b>Table 5. Performance comparison for a single int (all times in [s], `1e7`
107            iterations)</b></p>
108<div class="table-contents"><table class="table" summary="Performance comparison for a single int (all times in [s], `1e7`
109            iterations)">
110<colgroup>
111<col>
112<col>
113<col>
114<col>
115<col>
116<col>
117<col>
118</colgroup>
119<thead><tr>
120<th>
121                    <p>
122                      Library
123                    </p>
124                  </th>
125<th>
126                    <p>
127                      gcc 4.4.0 (32 bit)
128                    </p>
129                  </th>
130<th>
131                    <p>
132                      VC++ 10 (32 bit)
133                    </p>
134                  </th>
135<th>
136                    <p>
137                      Intel 11.1 (32 bit)
138                    </p>
139                  </th>
140<th>
141                    <p>
142                      gcc 4.4.0 (64 bit)
143                    </p>
144                  </th>
145<th>
146                    <p>
147                      VC++ 10 (64 bit)
148                    </p>
149                  </th>
150<th>
151                    <p>
152                      Intel 11.1 (64 bit)
153                    </p>
154                  </th>
155</tr></thead>
156<tbody>
157<tr>
158<td>
159                    <p>
160                      ltoa
161                    </p>
162                  </td>
163<td>
164                    <p>
165                      1.542
166                    </p>
167                  </td>
168<td>
169                    <p>
170                      0.895
171                    </p>
172                  </td>
173<td>
174                    <p>
175                      0.884
176                    </p>
177                  </td>
178<td>
179                    <p>
180                      1.163
181                    </p>
182                  </td>
183<td>
184                    <p>
185                      1.099
186                    </p>
187                  </td>
188<td>
189                    <p>
190                      0.906
191                    </p>
192                  </td>
193</tr>
194<tr>
195<td>
196                    <p>
197                      iostreams
198                    </p>
199                  </td>
200<td>
201                    <p>
202                      6.548
203                    </p>
204                  </td>
205<td>
206                    <p>
207                      13.727
208                    </p>
209                  </td>
210<td>
211                    <p>
212                      11.898
213                    </p>
214                  </td>
215<td>
216                    <p>
217                      3.464
218                    </p>
219                  </td>
220<td>
221                    <p>
222                      8.316
223                    </p>
224                  </td>
225<td>
226                    <p>
227                      8.115
228                    </p>
229                  </td>
230</tr>
231<tr>
232<td>
233                    <p>
234                      <a href="../../../../../../../../libs/format/index.html" target="_top">Boost.Format</a>
235                    </p>
236                  </td>
237<td>
238                    <p>
239                      16.998
240                    </p>
241                  </td>
242<td>
243                    <p>
244                      21.813
245                    </p>
246                  </td>
247<td>
248                    <p>
249                      20.477
250                    </p>
251                  </td>
252<td>
253                    <p>
254                      17.464
255                    </p>
256                  </td>
257<td>
258                    <p>
259                      14.662
260                    </p>
261                  </td>
262<td>
263                    <p>
264                      13.646
265                    </p>
266                  </td>
267</tr>
268<tr>
269<td>
270                    <p>
271                      <span class="emphasis"><em>Spirit.Karma</em></span> int_
272                    </p>
273                  </td>
274<td>
275                    <p>
276                      1.421
277                    </p>
278                  </td>
279<td>
280                    <p>
281                      0.744
282                    </p>
283                  </td>
284<td>
285                    <p>
286                      0.697
287                    </p>
288                  </td>
289<td>
290                    <p>
291                      1.072
292                    </p>
293                  </td>
294<td>
295                    <p>
296                      0.953
297                    </p>
298                  </td>
299<td>
300                    <p>
301                      0.606
302                    </p>
303                  </td>
304</tr>
305</tbody>
306</table></div>
307</div>
308<br class="table-break"><p>
309            </p>
310<div class="figure">
311<a name="spirit.karma.int_performance"></a><p class="title"><b>Figure 3. Performance comparison for a single int</b></p>
312<div class="figure-contents"><span class="inlinemediaobject"><img src="../../../.././images/int_performance.png" alt="Performance comparison for a single int"></span></div>
313</div>
314<p><br class="figure-break">
315          </p>
316</div>
317<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
318<td align="left"></td>
319<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
320        Distributed under the Boost Software License, Version 1.0. (See accompanying
321        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>)
322      </p>
323</div></td>
324</tr></table>
325<hr>
326<div class="spirit-nav">
327<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>
328</div>
329</body>
330</html>
331