========== Benchmarks ========== To check the overall performance of the :cpp:class:`mdarray` template provided by the library benchmark programs have been written whose results will be presented in this chapter. Three particular aspects are investigated by the benchmarks * linear data access via iterators * data access via multidimensional indexes * performance of the arithmetic operators To keep the number of benchmark results within reasonable bounds all benchmarks have been performend with the three predefined specializations of the :cpp:class:`mdarray` template: :cpp:class:`dynamic_array`, :cpp:class:`fixed_dim_array`, and :cpp:class:`static_array`. In addition to the plain array templates also their view types have been taken into account. The view types are interesting as they add some additional code which may cause some overhead. Its (presumed) outstanding performance is the reason why so much scientific software is written in C. In order to show that the code provided by *libpnicore* can be used in high performance applications all benchmarks are normalized to the runtime of equivalient C code. In most situations this means that data access is done via simple pointers. Iterator benchmarks =================== Results for the iterator benchmark. *r* and *w* denote reading and writing results respectively. +------------------------------+----------------+---------------------+ | array type | iterator (r/w) | view iterator (r/w) | +==============================+================+=====================+ | :cpp:class:`dynamic_array` | 1.02/1.04 | 2.50/2.96 | +------------------------------+----------------+---------------------+ | :cpp:class:`fixed_dim_array` | 0.99/1.00 | 2.52/2.89 | +------------------------------+----------------+---------------------+ | :cpp:class:`static_array` | 1.00/1.00 | 2.07/2.40 | +------------------------------+----------------+---------------------+ All numbers in this table are normalized to the raw pointer performance and thus reflect directly any performance penalty or advantage over direct pointer access. Only the :cpp:class:`dynamic_array` class shows a small performance penalty of 2 to 4 % over the C code. The other two array classes run as fast as plain C programs. In all cases iterating over a view shows significant performance penalties. Using iterators on views is about 2 up to 3 times slower than accessing the data via a pointer. This is simply due to additional overhead the view template introduces. The iterator write benchmarks run basically the following code for *libpnicore* .. code-block:: cpp for(auto &x: data) x = buffer; which must compete with .. code-block:: c T *data = new T[N]; for(size_t i=0;i