• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
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 1. Boost.Histogram">
8<link rel="up" href="../index.html" title="Chapter 1. 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 are filled with the call
62        operator <code class="computeroutput"><span class="keyword">operator</span><span class="special">()</span></code>
63        and the more efficient <code class="computeroutput"><span class="identifier">fill</span></code>-method,
64        which accepts large chunks of values at once. The GSL offers only 1D and
65        2D histograms, so there are no entries for the higher dimensional benchmarks.
66        Raw timing results are converted to average number of CPU cycles used per
67        input value.
68      </p>
69<p>
70        There is one bar for each benchmark and the upper end has a hatched part.
71        The full bar is the result when the histograms are filled with random normally
72        distributed data that falls outside of the axis domain in about 10 % of the
73        cases. This makes the branch predictors in the CPU fail every now and then,
74        which degrades performance. The bar without the hatched part is the result
75        when the histograms are filled with uniform random numbers which are always
76        inside the axis range.
77      </p>
78<p>
79        <span class="inlinemediaobject"><object type="image/svg+xml" data="../../fill_performance.svg" width="630" height="540"></object></span>
80      </p>
81<div class="variablelist">
82<p class="title"><b></b></p>
83<dl class="variablelist">
84<dt><span class="term">ROOT 6</span></dt>
85<dd><p>
86              <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>
87              for 2D, <code class="computeroutput"><span class="identifier">TH3I</span></code> for 3D
88              and <code class="computeroutput"><span class="identifier">THnI</span></code> for 6D)
89            </p></dd>
90<dt><span class="term">GSL</span></dt>
91<dd><p>
92              <a href="https://www.gnu.org/software/gsl/doc/html/histogram.html" target="_top">GSL
93              histograms</a> for 1D and 2D
94            </p></dd>
95<dt><span class="term">boost-sta</span></dt>
96<dd><p>
97              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> storage
98            </p></dd>
99<dt><span class="term">boost-dyn</span></dt>
100<dd><p>
101              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> 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> storage
102            </p></dd>
103</dl>
104</div>
105<p>
106        Boost.Histogram is faster than other libraries. Simultaneously, it is much
107        more flexible, since the axis and storage types can be customized. When
108        <code class="computeroutput"><span class="keyword">operator</span><span class="special">()</span></code>
109        is used, a histogram with compile-time configured axes (boost-sta-...) is
110        always faster than the equivalent alternatives from other libraries. The
111        histogram with run-time configured axes (boost-dyn-...) is comparable or
112        slower than other libraries, but offers a run-time flexibility that the alternatives
113        do not. If the <code class="computeroutput"><span class="identifier">fill</span></code> method
114        is used, filling either type of histogram is much faster (up to a factor
115        6) than filling histograms in other libraries, and the performance difference
116        between compile-time and run-time configured axes is mostly vanishes.
117      </p>
118</div>
119<div class="section">
120<div class="titlepage"><div><div><h3 class="title">
121<a name="histogram.benchmarks.iteration_performance"></a><a class="link" href="benchmarks.html#histogram.benchmarks.iteration_performance" title="Iteration performance">Iteration
122      performance</a>
123</h3></div></div></div>
124<p>
125        Boost.Histogram provides the <code class="computeroutput"><a class="link" href="../boost/histogram/indexed.html" title="Function template indexed">boost::histogram::indexed</a></code>
126        range generator for convenient iteration over the histogram cells. Using
127        the range generator is very convenient and it is faster than by writing nested
128        for-loops.
129      </p>
130<pre class="programlisting"><span class="comment">// nested for loops over 2d histogram</span>
131<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>
132  <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>
133    <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>
134  <span class="special">}</span>
135<span class="special">}</span>
136
137<span class="comment">// same, with indexed range generator</span>
138<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>
139  <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>
140<span class="special">}</span>
141</pre>
142<p>
143        The access time per bin is compared for these two iteration strategies for
144        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>
145        (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
146        per bin is measured for axis with 4 to 128 bins per axis.
147      </p>
148<p>
149        <span class="inlinemediaobject"><object type="image/svg+xml" data="../../iteration_performance.svg" width="900" height="450"></object></span>
150      </p>
151</div>
152</div>
153<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
154<td align="left"></td>
155<td align="right"><div class="copyright-footer">Copyright © 2016-2019 Hans
156      Dembinski<p>
157        Distributed under the Boost Software License, Version 1.0. (See accompanying
158        file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
159      </p>
160</div></td>
161</tr></table>
162<hr>
163<div class="spirit-nav">
164<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>
165</div>
166</body>
167</html>
168