...one of the most highly
regarded and expertly designed C++ library projects in the
world.

— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards

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 |

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 |

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 |

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 |

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 |

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 20.3. Polynomial Method Comparison with Microsoft Visual C++ version 14.0
on Windows x64**

Function |
Method 0 |
Method 0 |
Method 1 |
Method 1 |
Method 2 |
Method 2 |
Method 3 |
Method 3 |
---|---|---|---|---|---|---|---|---|

Order 2 |
- |
- |
1.00 |
1.00 |
1.00 |
1.00 |
1.00 |
1.00 |

Order 3 |
2.08 |
2.75 |
1.08 |
1.08 |
1.08 |
1.08 |
1.08 |
1.00 |

Order 4 |
2.06 |
2.71 |
1.06 |
1.00 |
1.06 |
1.06 |
1.00 |
1.00 |

Order 5 |
1.32 |
2.00 |
1.00 |
1.00 |
1.05 |
1.05 |
1.05 |
1.05 |

Order 6 |
1.38 |
2.04 |
1.08 |
1.00 |
1.08 |
1.08 |
1.35 |
1.38 |

Order 7 |
1.43 |
2.13 |
1.03 |
1.00 |
1.10 |
1.03 |
1.10 |
1.13 |

Order 8 |
1.65 |
2.22 |
1.00 |
1.08 |
1.14 |
1.05 |
1.08 |
1.11 |

Order 9 |
1.39 |
2.05 |
1.17 |
1.17 |
1.00 |
1.05 |
1.15 |
1.12 |

Order 10 |
1.37 |
2.20 |
1.22 |
1.24 |
1.00 |
1.00 |
1.17 |
1.17 |

Order 11 |
1.59 |
2.24 |
1.37 |
1.29 |
1.22 |
1.00 |
1.22 |
1.22 |

Order 12 |
1.46 |
2.16 |
1.28 |
1.26 |
1.02 |
1.00 |
1.07 |
1.05 |

Order 13 |
1.61 |
2.55 |
1.32 |
1.39 |
1.04 |
1.00 |
1.11 |
1.07 |

Order 14 |
1.61 |
2.23 |
1.45 |
1.45 |
1.02 |
1.02 |
1.00 |
1.09 |

Order 15 |
1.49 |
2.10 |
1.35 |
1.35 |
1.00 |
1.00 |
1.00 |
1.02 |

Order 16 |
1.54 |
1.99 |
1.49 |
1.45 |
1.07 |
1.00 |
1.08 |
1.02 |

Order 17 |
1.51 |
2.02 |
1.57 |
1.50 |
1.02 |
1.00 |
1.07 |
1.06 |

Order 18 |
1.53 |
2.16 |
1.49 |
1.57 |
1.11 |
1.09 |
1.00 |
1.08 |

Order 19 |
1.90 |
2.27 |
1.62 |
1.62 |
1.08 |
1.00 |
1.17 |
1.19 |

Order 20 |
1.65 |
2.08 |
1.45 |
1.44 |
1.00 |
1.00 |
1.01 |
1.03 |

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

Function |
Method 0 |
Method 0 |
Method 1 |
Method 1 |
Method 2 |
Method 2 |
Method 3 |
Method 3 |
---|---|---|---|---|---|---|---|---|

Order 2 |
- |
- |
2.12 |
1.95 |
1.00 |
1.00 |
1.00 |
1.00 |

Order 3 |
2.10 |
2.10 |
2.05 |
2.10 |
1.05 |
1.00 |
1.00 |
1.00 |

Order 4 |
2.12 |
2.21 |
1.98 |
2.10 |
1.02 |
1.02 |
1.02 |
1.00 |

Order 5 |
1.07 |
1.15 |
1.08 |
1.00 |
1.45 |
1.46 |
1.45 |
1.45 |

Order 6 |
1.16 |
1.58 |
1.00 |
1.03 |
1.44 |
1.44 |
1.41 |
1.38 |

Order 7 |
1.29 |
1.44 |
1.01 |
1.00 |
1.38 |
1.36 |
1.33 |
1.36 |

Order 8 |
1.33 |
1.52 |
1.00 |
1.08 |
1.38 |
1.31 |
1.39 |
1.37 |

Order 9 |
1.18 |
1.45 |
1.00 |
1.08 |
1.13 |
1.26 |
1.26 |
1.27 |

Order 10 |
1.29 |
1.28 |
1.05 |
1.00 |
1.06 |
1.06 |
1.18 |
1.17 |

Order 11 |
1.28 |
1.28 |
1.06 |
1.05 |
1.03 |
1.00 |
1.19 |
1.47 |

Order 12 |
1.22 |
1.38 |
1.04 |
1.04 |
1.00 |
1.04 |
1.22 |
1.52 |

Order 13 |
1.23 |
1.29 |
1.15 |
1.10 |
1.00 |
1.15 |
1.22 |
1.61 |

Order 14 |
1.28 |
1.39 |
1.15 |
1.14 |
1.00 |
1.01 |
1.49 |
1.53 |

Order 15 |
1.28 |
1.34 |
1.12 |
1.15 |
1.00 |
1.00 |
1.38 |
1.47 |

Order 16 |
1.35 |
1.40 |
1.22 |
1.18 |
1.00 |
1.23 |
1.43 |
1.52 |

Order 17 |
1.16 |
1.47 |
1.15 |
1.35 |
1.00 |
1.22 |
1.50 |
1.52 |

Order 18 |
1.10 |
1.46 |
1.10 |
1.75 |
1.00 |
1.30 |
1.41 |
1.46 |

Order 19 |
1.26 |
1.35 |
1.24 |
1.33 |
1.00 |
1.22 |
1.44 |
1.46 |

Order 20 |
1.24 |
1.60 |
1.22 |
1.56 |
1.00 |
1.19 |
1.57 |
1.56 |

[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]