Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Performance Tuning Macros

There are a small number of performance tuning options that are determined by configuration macros. These should be set in boost/math/tools/user.hpp; or else reported to the Boost-development mailing list so that the appropriate option for a given compiler and OS platform can be set automatically in our configuration setup.

Macro

Meaning

BOOST_MATH_POLY_METHOD

Determines how polynomials and most rational functions are evaluated. Define to one of the values 0, 1, 2 or 3: see below for the meaning of these values.

BOOST_MATH_RATIONAL_METHOD

Determines how symmetrical rational functions are evaluated: mostly this only effects how the Lanczos approximation is evaluated, and how the evaluate_rational function behaves. Define to one of the values 0, 1, 2 or 3: see below for the meaning of these values.

BOOST_MATH_MAX_POLY_ORDER

The maximum order of polynomial or rational function that will be evaluated by a method other than 0 (a simple "for" loop).

BOOST_MATH_INT_TABLE_TYPE(RT, IT)

Many of the coefficients to the polynomials and rational functions used by this library are integers. Normally these are stored as tables as integers, but if mixed integer / floating point arithmetic is much slower than regular floating point arithmetic then they can be stored as tables of floating point values instead. If mixed arithmetic is slow then add:

#define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT

to boost/math/tools/user.hpp, otherwise the default of:

#define BOOST_MATH_INT_TABLE_TYPE(RT, IT) IT

Set in boost/math/config.hpp is fine, and may well result in smaller code.

The values to which BOOST_MATH_POLY_METHOD and BOOST_MATH_RATIONAL_METHOD may be set are as follows:

Value

Effect

0

The polynomial or rational function is evaluated using Horner's method, and a simple for-loop.

Note that if the order of the polynomial or rational function is a runtime parameter, or the order is greater than the value of BOOST_MATH_MAX_POLY_ORDER, then this method is always used, irrespective of the value of BOOST_MATH_POLY_METHOD or BOOST_MATH_RATIONAL_METHOD.

1

The polynomial or rational function is evaluated without the use of a loop, and using Horner's method. This only occurs if the order of the polynomial is known at compile time and is less than or equal to BOOST_MATH_MAX_POLY_ORDER.

2

The polynomial or rational function is evaluated without the use of a loop, and using a second order Horner's method. In theory this permits two operations to occur in parallel for polynomials, and four in parallel for rational functions. This only occurs if the order of the polynomial is known at compile time and is less than or equal to BOOST_MATH_MAX_POLY_ORDER.

3

The polynomial or rational function is evaluated without the use of a loop, and using a second order Horner's method. In theory this permits two operations to occur in parallel for polynomials, and four in parallel for rational functions. This differs from method "2" in that the code is carefully ordered to make the parallelisation more obvious to the compiler: rather than relying on the compiler's optimiser to spot the parallelisation opportunities. This only occurs if the order of the polynomial is known at compile time and is less than or equal to BOOST_MATH_MAX_POLY_ORDER.

The performance test suite generates a report for your particular compiler showing which method is likely to work best, the following tables show the results for MSVC-14.0 and GCC-5.1.0 (Linux). There's not much to choose between the various methods, but generally loop-unrolled methods perform better. Interestingly, ordering the code to try and "second guess" possible optimizations seems not to be such a good idea (method 3 below).

Table 16.3. Polynomial Method Comparison with Microsoft Visual C++ version 14.0 on Windows x64

Function

Method 0
(Double Coefficients)

Method 0
(Integer Coefficients)

Method 1
(Double Coefficients)

Method 1
(Integer Coefficients)

Method 2
(Double Coefficients)

Method 2
(Integer Coefficients)

Method 3
(Double Coefficients)

Method 3
(Integer Coefficients)

Order 2

-

-

1.00
(9ns)

1.00
(9ns)

1.11
(10ns)

1.00
(9ns)

1.11
(10ns)

1.11
(10ns)

Order 3

2.15
(28ns)

2.46
(32ns)

1.00
(13ns)

1.08
(14ns)

1.00
(13ns)

1.00
(13ns)

1.08
(14ns)

1.08
(14ns)

Order 4

2.38
(38ns)

3.06
(49ns)

1.13
(18ns)

1.06
(17ns)

1.06
(17ns)

1.06
(17ns)

1.00
(16ns)

1.00
(16ns)

Order 5

1.43
(30ns)

2.14
(45ns)

1.10
(23ns)

1.05
(22ns)

1.00
(21ns)

1.00
(21ns)

1.00
(21ns)

1.14
(24ns)

Order 6

1.44
(39ns)

1.93
(52ns)

1.07
(29ns)

1.00
(27ns)

1.04
(28ns)

1.07
(29ns)

1.33
(36ns)

1.33
(36ns)

Order 7

1.43
(43ns)

2.20
(66ns)

1.03
(31ns)

1.07
(32ns)

1.03
(31ns)

1.00
(30ns)

1.20
(36ns)

1.20
(36ns)

Order 8

1.46
(54ns)

2.05
(76ns)

1.11
(41ns)

1.11
(41ns)

1.00
(37ns)

1.03
(38ns)

1.19
(44ns)

1.14
(42ns)

Order 9

1.58
(60ns)

2.39
(91ns)

1.29
(49ns)

1.26
(48ns)

1.05
(40ns)

1.00
(38ns)

1.13
(43ns)

1.16
(44ns)

Order 10

1.50
(69ns)

2.17
(100ns)

1.24
(57ns)

1.22
(56ns)

1.00
(46ns)

1.02
(47ns)

1.15
(53ns)

1.15
(53ns)

Order 11

1.56
(81ns)

2.15
(112ns)

1.25
(65ns)

1.19
(62ns)

1.04
(54ns)

1.00
(52ns)

1.13
(59ns)

1.13
(59ns)

Order 12

1.37
(86ns)

2.02
(127ns)

1.13
(71ns)

1.14
(72ns)

1.02
(64ns)

1.00
(63ns)

1.03
(65ns)

1.03
(65ns)

Order 13

1.62
(99ns)

2.38
(145ns)

1.33
(81ns)

1.44
(88ns)

1.02
(62ns)

1.00
(61ns)

1.08
(66ns)

1.05
(64ns)

Order 14

1.64
(105ns)

2.45
(157ns)

1.56
(100ns)

1.52
(97ns)

1.03
(66ns)

1.00
(64ns)

1.03
(66ns)

1.09
(70ns)

Order 15

1.62
(123ns)

2.33
(177ns)

1.53
(116ns)

1.61
(122ns)

1.00
(76ns)

1.07
(81ns)

1.07
(81ns)

1.11
(84ns)

Order 16

1.37
(126ns)

1.87
(172ns)

1.41
(130ns)

1.28
(118ns)

1.01
(93ns)

1.00
(92ns)

1.00
(92ns)

1.00
(92ns)

Order 17

1.41
(135ns)

1.88
(180ns)

1.54
(148ns)

1.48
(142ns)

1.00
(96ns)

1.00
(96ns)

1.04
(100ns)

1.04
(100ns)

Order 18

1.57
(159ns)

2.01
(203ns)

1.54
(156ns)

1.56
(158ns)

1.00
(101ns)

1.03
(104ns)

1.05
(106ns)

1.08
(109ns)

Order 19

1.44
(160ns)

2.09
(232ns)

1.54
(171ns)

1.49
(165ns)

1.04
(115ns)

1.00
(111ns)

1.02
(113ns)

1.08
(120ns)

Order 20

1.50
(179ns)

2.11
(251ns)

1.59
(189ns)

1.55
(184ns)

1.07
(127ns)

1.09
(130ns)

1.04
(124ns)

1.00
(119ns)


Table 16.4. Rational Method Comparison with Microsoft Visual C++ version 14.0 on Windows x64

Function

Method 0
(Double Coefficients)

Method 0
(Integer Coefficients)

Method 1
(Double Coefficients)

Method 1
(Integer Coefficients)

Method 2
(Double Coefficients)

Method 2
(Integer Coefficients)

Method 3
(Double Coefficients)

Method 3
(Integer Coefficients)

Order 2

-

-

2.14
(92ns)

2.12
(91ns)

1.07
(46ns)

1.00
(43ns)

1.02
(44ns)

1.00
(43ns)

Order 3

2.07
(89ns)

1.95
(84ns)

2.19
(94ns)

2.16
(93ns)

1.05
(45ns)

1.07
(46ns)

1.00
(43ns)

1.02
(44ns)

Order 4

1.98
(85ns)

2.23
(96ns)

2.33
(100ns)

2.16
(93ns)

1.00
(43ns)

1.02
(44ns)

1.05
(45ns)

1.02
(44ns)

Order 5

1.00
(89ns)

1.02
(91ns)

1.09
(97ns)

1.17
(104ns)

1.46
(130ns)

1.51
(134ns)

1.46
(130ns)

1.42
(126ns)

Order 6

1.02
(96ns)

1.13
(106ns)

1.00
(94ns)

1.13
(106ns)

1.35
(127ns)

1.44
(135ns)

1.36
(128ns)

1.37
(129ns)

Order 7

1.00
(101ns)

1.30
(131ns)

1.14
(115ns)

1.04
(105ns)

1.40
(141ns)

1.28
(129ns)

1.32
(133ns)

1.32
(133ns)

Order 8

1.06
(117ns)

1.46
(161ns)

1.05
(115ns)

1.00
(110ns)

1.22
(134ns)

1.20
(132ns)

1.32
(145ns)

1.33
(146ns)

Order 9

1.08
(142ns)

1.23
(163ns)

1.00
(132ns)

1.12
(148ns)

1.08
(143ns)

1.11
(146ns)

1.21
(160ns)

1.20
(159ns)

Order 10

1.01
(150ns)

1.15
(170ns)

1.11
(165ns)

1.05
(155ns)

1.01
(149ns)

1.00
(148ns)

1.16
(171ns)

1.16
(172ns)

Order 11

1.19
(178ns)

1.32
(196ns)

1.16
(173ns)

1.14
(170ns)

1.00
(149ns)

1.01
(151ns)

1.21
(180ns)

1.49
(222ns)

Order 12

1.17
(189ns)

1.32
(214ns)

1.23
(199ns)

1.20
(194ns)

1.00
(162ns)

1.02
(165ns)

1.41
(228ns)

1.52
(246ns)

Order 13

1.26
(220ns)

1.34
(234ns)

1.22
(213ns)

1.35
(235ns)

1.07
(187ns)

1.00
(174ns)

1.22
(213ns)

1.55
(269ns)

Order 14

1.22
(234ns)

1.29
(247ns)

1.29
(247ns)

1.30
(250ns)

1.08
(208ns)

1.00
(192ns)

1.44
(277ns)

1.56
(299ns)

Order 15

1.18
(240ns)

1.43
(291ns)

1.44
(293ns)

1.37
(279ns)

1.03
(211ns)

1.00
(204ns)

1.40
(285ns)

1.50
(307ns)

Order 16

1.66
(357ns)

1.72
(369ns)

1.29
(277ns)

1.27
(273ns)

1.00
(215ns)

1.19
(256ns)

1.46
(314ns)

1.55
(334ns)

Order 17

1.35
(298ns)

1.63
(361ns)

1.37
(302ns)

1.40
(309ns)

1.00
(221ns)

1.27
(281ns)

1.52
(336ns)

1.57
(348ns)

Order 18

1.32
(316ns)

1.60
(382ns)

1.26
(300ns)

1.45
(347ns)

1.00
(239ns)

1.23
(294ns)

1.50
(358ns)

1.56
(373ns)

Order 19

1.31
(337ns)

1.73
(446ns)

1.24
(319ns)

1.40
(362ns)

1.00
(258ns)

1.24
(319ns)

1.51
(389ns)

1.48
(383ns)

Order 20

1.35
(364ns)

1.51
(408ns)

1.18
(319ns)

1.44
(390ns)

1.00
(270ns)

1.22
(329ns)

1.52
(411ns)

1.52
(411ns)


[table_Polynomial_Method_Comparison_with_GNU_C_version_5_1_0_on_linux]

[table_Rational_Method_Comparison_with_GNU_C_version_5_1_0_on_linux]


PrevUpHomeNext