• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>The Overhead in the Number Class Wrapper</title>
5<link rel="stylesheet" href="../../multiprecision.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
8<link rel="up" href="../perf.html" title="Performance Comparison">
9<link rel="prev" href="../perf.html" title="Performance Comparison">
10<link rel="next" href="realworld.html" title="Floating-Point Real World Tests">
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="../perf.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../perf.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="realworld.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h3 class="title">
27<a name="boost_multiprecision.perf.overhead"></a><a class="link" href="overhead.html" title="The Overhead in the Number Class Wrapper">The Overhead in the
28      Number Class Wrapper</a>
29</h3></div></div></div>
30<p>
31        Using a simple <a href="http://www.boost.org/doc/libs/release/libs/multiprecision/doc/html/../../performance/arithmetic_backend.hpp" target="_top">backend
32        class</a> that wraps any <a href="https://en.cppreference.com/w/cpp/language/types" target="_top">fundamental
33        (built-in)</a> arithmetic type we can measure the overhead involved in
34        wrapping a type inside the <code class="computeroutput"><span class="identifier">number</span></code>
35        frontend, and the effect that turning on expression templates has. The following
36        table compares the performance between <code class="computeroutput"><span class="keyword">double</span></code>
37        and a <code class="computeroutput"><span class="keyword">double</span></code> wrapped inside
38        class <code class="computeroutput"><span class="identifier">number</span></code>:
39      </p>
40<div class="table">
41<a name="boost_multiprecision.perf.overhead.bessel_functions_16_digit_precis"></a><p class="title"><b>Table 1.12. Bessel Functions (16 digit precision)</b></p>
42<div class="table-contents"><table class="table" summary="Bessel Functions (16 digit precision)">
43<colgroup>
44<col>
45<col>
46</colgroup>
47<thead><tr>
48<th>
49                <p>
50                  Type
51                </p>
52              </th>
53<th>
54                <p>
55                  Time
56                </p>
57              </th>
58</tr></thead>
59<tbody>
60<tr>
61<td>
62                <p>
63                  arithmetic_backend&lt;double&gt;
64                </p>
65              </td>
66<td>
67                <p>
68                  2.09301 (0.00133409s)
69                </p>
70              </td>
71</tr>
72<tr>
73<td>
74                <p>
75                  arithmetic_backend&lt;double&gt; - no expression templates
76                </p>
77              </td>
78<td>
79                <p>
80                  1 (0.000637403s)
81                </p>
82              </td>
83</tr>
84<tr>
85<td>
86                <p>
87                  double
88                </p>
89              </td>
90<td>
91                <p>
92                  1.07956 (0.000688113s)
93                </p>
94              </td>
95</tr>
96</tbody>
97</table></div>
98</div>
99<br class="table-break"><p>
100        As you can see whether or not there is an overhead, and how large it is depends
101        on the actual situation, but the overhead is in any cases small. Expression
102        templates generally add a greater overhead the more complex the expression
103        becomes due to the logic of figuring out how to best unpack and evaluate
104        the expression, but of course this is also the situation where you save more
105        temporaries. For a "trivial" backend like this, saving temporaries
106        has no benefit, but for larger types it becomes a bigger win.
107      </p>
108<p>
109        The following table compares arithmetic using either <code class="computeroutput"><span class="keyword">long</span>
110        <span class="keyword">long</span></code> or <code class="computeroutput"><span class="identifier">number</span><span class="special">&lt;</span><span class="identifier">arithmetic_backend</span><span class="special">&lt;</span><span class="keyword">long</span> <span class="keyword">long</span><span class="special">&gt;</span> <span class="special">&gt;</span></code> for the <a href="http://www.boost.org/doc/libs/release/libs/multiprecision/doc/html/../../performance/voronoi_performance.cpp" target="_top">voronoi-diagram
111        builder test</a>:
112      </p>
113<div class="informaltable"><table class="table">
114<colgroup>
115<col>
116<col>
117</colgroup>
118<thead><tr>
119<th>
120                <p>
121                  Type
122                </p>
123              </th>
124<th>
125                <p>
126                  Relative time
127                </p>
128              </th>
129</tr></thead>
130<tbody>
131<tr>
132<td>
133                <p>
134                  <code class="computeroutput"><span class="identifier">int64_t</span></code>
135                </p>
136              </td>
137<td>
138                <p>
139                  <span class="bold"><strong>1.0</strong></span>(0.0128646s)
140                </p>
141              </td>
142</tr>
143<tr>
144<td>
145                <p>
146                  <code class="computeroutput"><span class="identifier">number</span><span class="special">&lt;</span><span class="identifier">arithmetic_backend</span><span class="special">&lt;</span><span class="identifier">int64_t</span><span class="special">&gt;,</span>
147                  <span class="identifier">et_off</span><span class="special">&gt;</span></code>
148                </p>
149              </td>
150<td>
151                <p>
152                  1.005 (0.0129255s)
153                </p>
154              </td>
155</tr>
156</tbody>
157</table></div>
158<p>
159        This test involves mainly creating a lot of temporaries and performing a
160        small amount of arithmetic on them, with very little difference in performance
161        between the native and "wrapped" types.
162      </p>
163<div class="table">
164<a name="boost_multiprecision.perf.overhead.platform"></a><p class="title"><b>Table 1.13. Platform Details</b></p>
165<div class="table-contents"><table class="table" summary="Platform Details">
166<colgroup>
167<col>
168<col>
169</colgroup>
170<thead><tr>
171<th>
172                <p>
173                  Platform
174                </p>
175              </th>
176<th>
177                <p>
178                  Linux 5.3.0-24-generic, version #26-Ubuntu SMP Thu Nov 14 01:33:18
179                  UTC 2019, x86_64
180                </p>
181              </th>
182</tr></thead>
183<tbody>
184<tr>
185<td>
186                <p>
187                  Compiler
188                </p>
189              </td>
190<td>
191                <p>
192                  GNU C++ version 9.2.1 20191008
193                </p>
194              </td>
195</tr>
196<tr>
197<td>
198                <p>
199                  Boost
200                </p>
201              </td>
202<td>
203                <p>
204                  1.72.0
205                </p>
206              </td>
207</tr>
208<tr>
209<td>
210                <p>
211                  Run date
212                </p>
213              </td>
214<td>
215                <p>
216                  Dec 13 2019
217                </p>
218              </td>
219</tr>
220</tbody>
221</table></div>
222</div>
223<br class="table-break">
224</div>
225<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
226<td align="left"></td>
227<td align="right"><div class="copyright-footer">Copyright © 2002-2020 John
228      Maddock and Christopher Kormanyos<p>
229        Distributed under the Boost Software License, Version 1.0. (See accompanying
230        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>)
231      </p>
232</div></td>
233</tr></table>
234<hr>
235<div class="spirit-nav">
236<a accesskey="p" href="../perf.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../perf.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="realworld.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
237</div>
238</body>
239</html>
240