Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / histogram / doc / html / histogram / benchmarks.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Benchmarks</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="Chapter&#160;1.&#160;Boost.Histogram">
8 <link rel="up" href="../index.html" title="Chapter&#160;1.&#160;Boost.Histogram">
9 <link rel="prev" href="guide.html" title="User guide">
10 <link rel="next" href="concepts.html" title="Concepts">
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="../../../../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="guide.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.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="concepts.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
24 </div>
25 <div class="section">
26 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
27 <a name="histogram.benchmarks"></a><a class="link" href="benchmarks.html" title="Benchmarks">Benchmarks</a>
28 </h2></div></div></div>
29 <div class="toc"><dl class="toc">
30 <dt><span class="section"><a href="benchmarks.html#histogram.benchmarks.fill_performance">Fill performance</a></span></dt>
31 <dt><span class="section"><a href="benchmarks.html#histogram.benchmarks.iteration_performance">Iteration
32       performance</a></span></dt>
33 </dl></div>
34 <p>
35       The library is designed to be fast. When configured correctly, it is one of
36       the fastest libraries on the market. If you find a library that is faster than
37       Boost.Histogram, please submit an issue on Github. We care about performance.
38     </p>
39 <p>
40       That being said, the time spend in filling the histogram is usually not the
41       bottleneck of an application. Only in processing of really large data sets
42       the performance of the histogram can be important.
43     </p>
44 <p>
45       All benchmarks are compiled on a laptop with a 2,9 GHz Intel Core i5 processor
46       with Apple LLVM (clang-1001.0.46.4) and the flags <code class="computeroutput"><span class="special">-</span><span class="identifier">DNDEBUG</span> <span class="special">-</span><span class="identifier">O3</span> <span class="special">-</span><span class="identifier">funsafe</span><span class="special">-</span><span class="identifier">math</span><span class="special">-</span><span class="identifier">optimizations</span></code>. Adding <code class="computeroutput"><span class="special">-</span><span class="identifier">fno</span><span class="special">-</span><span class="identifier">exceptions</span>
47       <span class="special">-</span><span class="identifier">fno</span><span class="special">-</span><span class="identifier">rtti</span></code> would
48       increase the Boost.Histogram performance by another (10-20) %, but this is
49       not done here out of fairness, since the ROOT histograms do not compile with
50       these options.
51     </p>
52 <div class="section">
53 <div class="titlepage"><div><div><h3 class="title">
54 <a name="histogram.benchmarks.fill_performance"></a><a class="link" href="benchmarks.html#histogram.benchmarks.fill_performance" title="Fill performance">Fill performance</a>
55 </h3></div></div></div>
56 <p>
57         The fill performance of different configurations of Boost.Histogram are compared
58         with histogram classes and functions from other libraries. Random numbers
59         from a uniform and a normal distribution are filled into histograms with
60         1, 2, 3, and 6 axes. 100 bins per axis are used for 1, 2, 3 axes. 10 bins
61         per axis for the case with 6 axes. The histogram can be filled with the call
62         operator <code class="computeroutput"><span class="keyword">operator</span><span class="special">()</span></code>
63         or the more efficient <code class="computeroutput"><span class="identifier">fill</span></code>-method.
64         Results are shown for both. The GSL offers only 1D and 2D histograms, so
65         there are no entries for the higher dimensional benchmarks. Raw timing results
66         are converted to average number of CPU cycles used per input value.
67       </p>
68 <p>
69         There is one bar for each benchmark, and the upper end has a hatched part.
70         The full bar is the result when the histograms are filled with random normally
71         distributed data that falls outside of the axis domain in about 10 % of the
72         cases. This makes the branch predictors in the CPU fail every now and then,
73         which degrades performance. The bar without the hatched part is the result
74         when the histograms are filled with uniform random numbers which are always
75         inside the axis range.
76       </p>
77 <p>
78         <span class="inlinemediaobject"><object type="image/svg+xml" data="../../fill_performance.svg" width="630" height="720"></object></span>
79       </p>
80 <div class="variablelist">
81 <p class="title"><b></b></p>
82 <dl class="variablelist">
83 <dt><span class="term">ROOT 6</span></dt>
84 <dd><p>
85               <a href="https://root.cern.ch" target="_top">ROOT classes</a> (<code class="computeroutput"><span class="identifier">TH1I</span></code> for 1D, <code class="computeroutput"><span class="identifier">TH2I</span></code>
86               for 2D, <code class="computeroutput"><span class="identifier">TH3I</span></code> for 3D
87               and <code class="computeroutput"><span class="identifier">THnI</span></code> for 6D)
88             </p></dd>
89 <dt><span class="term">GSL</span></dt>
90 <dd><p>
91               <a href="https://www.gnu.org/software/gsl/doc/html/histogram.html" target="_top">GSL
92               histograms</a> for 1D and 2D
93             </p></dd>
94 <dt><span class="term">boost-SS</span></dt>
95 <dd><p>
96               Histogram with <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple</span><span class="special">&lt;</span><span class="identifier">axis</span><span class="special">::</span><span class="identifier">regular</span><span class="special">&lt;&gt;&gt;</span></code> and <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span></code>
97             </p></dd>
98 <dt><span class="term">boost-SD</span></dt>
99 <dd><p>
100               Histogram with <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple</span><span class="special">&lt;</span><span class="identifier">axis</span><span class="special">::</span><span class="identifier">regular</span><span class="special">&lt;&gt;&gt;</span></code> with <code class="computeroutput"><a class="link" href="../boost/histogram/unlimited_storage.html" title="Class template unlimited_storage">boost::histogram::unlimited_storage</a></code>
101             </p></dd>
102 <dt><span class="term">boost-DS</span></dt>
103 <dd><p>
104               Histogram with <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">axis</span><span class="special">::</span><span class="identifier">variant</span><span class="special">&lt;</span><span class="identifier">axis</span><span class="special">::</span><span class="identifier">regular</span><span class="special">&lt;&gt;&gt;&gt;</span></code> with <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span></code>
105             </p></dd>
106 <dt><span class="term">boost-DD</span></dt>
107 <dd><p>
108               Histogram with <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">axis</span><span class="special">::</span><span class="identifier">variant</span><span class="special">&lt;</span><span class="identifier">axis</span><span class="special">::</span><span class="identifier">regular</span><span class="special">&lt;&gt;&gt;&gt;</span></code> with <code class="computeroutput"><a class="link" href="../boost/histogram/unlimited_storage.html" title="Class template unlimited_storage">boost::histogram::unlimited_storage</a></code>
109             </p></dd>
110 </dl>
111 </div>
112 <p>
113         Boost.Histogram is faster than other libraries. Simultaneously, it is much
114         more flexible, since the axis and storage types can be customized.
115       </p>
116 <p>
117         When <code class="computeroutput"><span class="keyword">operator</span><span class="special">()</span></code>
118         is used, a histogram with compile-time configured axes is always faster than
119         one with run-time configured axes. The <code class="computeroutput"><a class="link" href="../boost/histogram/unlimited_storage.html" title="Class template unlimited_storage">boost::histogram::unlimited_storage</a></code>
120         is faster than a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span></code> for
121         histograms with many bins, because it uses the cache more effectively due
122         to its smaller memory consumption per bin. If the number of bins is small,
123         it is slower because of the overhead of handling memory dynamically. If the
124         <code class="computeroutput"><span class="identifier">fill</span></code> method is used, histograms
125         with run-time configured axes are as fast for 2D histograms and higher. In
126         this case, using <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span></code> for
127         storage is faster in all benchmarks that were carried out, although the performance
128         gap to <code class="computeroutput"><a class="link" href="../boost/histogram/unlimited_storage.html" title="Class template unlimited_storage">boost::histogram::unlimited_storage</a></code>
129         shrinks for higher dimensions.
130       </p>
131 </div>
132 <div class="section">
133 <div class="titlepage"><div><div><h3 class="title">
134 <a name="histogram.benchmarks.iteration_performance"></a><a class="link" href="benchmarks.html#histogram.benchmarks.iteration_performance" title="Iteration performance">Iteration
135       performance</a>
136 </h3></div></div></div>
137 <p>
138         Boost.Histogram provides the <code class="computeroutput"><a class="link" href="../boost/histogram/indexed.html" title="Function template indexed">boost::histogram::indexed</a></code>
139         range generator for convenient iteration over the histogram cells. Using
140         the range generator is very convenient and it is faster than by writing nested
141         for-loops.
142       </p>
143 <pre class="programlisting"><span class="comment">// nested for loops over 2d histogram</span>
144 <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">h</span><span class="special">.</span><span class="identifier">axis</span><span class="special">(</span><span class="number">0</span><span class="special">).</span><span class="identifier">size</span><span class="special">();</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> <span class="special">{</span>
145   <span class="keyword">for</span> <span class="special">(</span><span class="keyword">int</span> <span class="identifier">j</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">j</span> <span class="special">&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">axis</span><span class="special">(</span><span class="number">1</span><span class="special">).</span><span class="identifier">size</span><span class="special">();</span> <span class="special">++</span><span class="identifier">j</span><span class="special">)</span> <span class="special">{</span>
146     <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">i</span> <span class="special">&lt;&lt;</span> <span class="string">" "</span> <span class="special">&lt;&lt;</span> <span class="identifier">j</span> <span class="special">&lt;&lt;</span> <span class="string">" "</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">at</span><span class="special">(</span><span class="identifier">i</span><span class="special">,</span> <span class="identifier">j</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
147   <span class="special">}</span>
148 <span class="special">}</span>
149
150 <span class="comment">// same, with indexed range generator</span>
151 <span class="keyword">for</span> <span class="special">(</span><span class="keyword">auto</span><span class="special">&amp;&amp;</span> <span class="identifier">x</span> <span class="special">:</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">histogram</span><span class="special">::</span><span class="identifier">indexed</span><span class="special">(</span><span class="identifier">h</span><span class="special">))</span> <span class="special">{</span>
152   <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">index</span><span class="special">(</span><span class="number">0</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="string">" "</span> <span class="special">&lt;&lt;</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">index</span><span class="special">(</span><span class="number">1</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="string">" "</span> <span class="special">&lt;&lt;</span> <span class="special">*</span><span class="identifier">x</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
153 <span class="special">}</span>
154 </pre>
155 <p>
156         The access time per bin is compared for these two iteration strategies for
157         histograms that hold the axes in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple</span></code>
158         (tuple), in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span></code> (vector), and in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">histogram</span><span class="special">::</span><span class="identifier">axis</span><span class="special">::</span><span class="identifier">variant</span><span class="special">&gt;</span></code> (vector of variants). The access time
159         per bin is measured for axis with 4 to 128 bins per axis.
160       </p>
161 <p>
162         <span class="inlinemediaobject"><object type="image/svg+xml" data="../../iteration_performance.svg" width="900" height="450"></object></span>
163       </p>
164 </div>
165 </div>
166 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
167 <td align="left"></td>
168 <td align="right"><div class="copyright-footer">Copyright &#169; 2016-2019 Hans
169       Dembinski<p>
170         Distributed under the Boost Software License, Version 1.0. (See accompanying
171         file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
172       </p>
173 </div></td>
174 </tr></table>
175 <hr>
176 <div class="spirit-nav">
177 <a accesskey="p" href="guide.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.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="concepts.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
178 </div>
179 </body>
180 </html>