Performance of Elementary Functions

by Pavel Holoborodko on April 27, 2016

UPDATE (November 17, 2016): All timings in table have been updated to reflect speed improvements in new version of toolbox (4.3.0). Now toolbox computes elementary functions using multi-core parallelism. Also we included timings for the the latest version of MATLAB2016b.



UPDATE (June 1, 2016): Initial version of the post included statement that newest version of MATLAB R2016a uses MAPLE engine for variable precision arithmetic (instead of MuPAD as in previous versions). After more detailed checks we have detected that this is not true. As it turned out, MAPLE 2016 silently replaced VPA functionality of MATLAB during installation. Thus we (without knowing it) tested MAPLE Toolbox for MATLAB instead of MathWorks Symbolic Math Toolbox. We apologize for misinformation. Now post provides correct comparison results with Symbolic Math Toolbox/VPA.

Thanks to Nick Higham, Massimiliano Fasi and Samuel Relton for their help in finding this mistake!



From the very beginning we have been focusing on improving performance of matrix computations, linear algebra, solvers and other high level algorithms (e.g. 3.8.0 release notes).

With time, as speed of advanced algorithms has been increasing, elementary functions started to bubble up in top list of hot-spots more frequently. For example the main bottleneck of the multiquadric collocation method in extended precision was the coefficient-wise power function (.^).

Thus we decided to polish our library for computing elementary functions. Here we present intermediate results of this work and traditional comparison with the latest MATLAB R2016b (Symbolic Math Toolbox/Variable Precision Arithmetic) and MAPLE 2016.

Timing of logarithmic and power functions in 3.9.4.10481:

>> mp.Digits(34);
>> A = mp(rand(2000)-0.5);
>> B = mp(rand(2000)-0.5);
 
>> tic; C = A.^B; toc;
Elapsed time is 67.199782 seconds.
 
>> tic; C = log(A); toc;
Elapsed time is 22.570701 seconds.

Speed of the same functions after optimization, in 4.3.0.12057:

>> mp.Digits(34);
>> A = mp(rand(2000)-0.5);
>> B = mp(rand(2000)-0.5);
 
>> tic; C = A.^B; toc;             % 130 times faster
Elapsed time is 0.514553 seconds.
 
>> tic; C = log(A); toc;           % 95 times faster
Elapsed time is 0.238416 seconds.

Now toolbox computes 4 millions of logarithms in quadruple precision (including negative arguments) in less than a second!

Inspired by this result, we have applied our ideas to speed-up some other elementary functions. Summary table with timings and comparison against MATLAB R2016b (VPA) and MAPLE 2016 on Core i7 990x / Windows 7 64-bit:

Computation of elementary functions using quadruple precision
(argument is real pseudo-random 2Kx2K matrix)
Function Timing (sec)Speed-up (times)
MATLAB R2016b (VPA) Maple 2016Advanpix 4.3.0Over VPAOver Maple
Power & exponential:
EXP107.34756.140.12886.34 6243.90
LOG1161.18593.980.235133.40 2625.91
LOG101438.91639.460.245958.23 2647.88
LOG21442.71643.170.255789.35 2580.94
SQRT28.75427.400.27105.74 1571.90
Trigonometric:
SIN85.28736.890.15570.804932.33
COS78.96513.730.15516.443359.92
TAN1261.92844.050.177277.514867.64
ASIN105.121181.830.39266.402995.01
ACOS100.491330.990.39257.553411.03
ATAN131.921039.550.14974.287677.64
SEC1466.09778.140.188199.594352.01
CSC1503.75793.870.188490.954482.60
COT1511.671014.760.207728.365187.95
ASEC1610.291962.870.285815.447088.72
ACSC1648.311720.760.285965.656227.86
ACOT140.371179.840.16867.587291.96
SINH117.85781.780.13910.786041.59
COSH117.73795.340.13924.066242.87
TANH121.37976.780.101198.149642.45
ASINH92.55778.460.14656.385521.02
ACOSH103.781349.790.31332.104319.31
ATANH121.462287.940.32378.497129.76
SECH1922.54978.910.1711602.535907.73
CSCH1947.11960.780.1711652.355749.72
COTH1958.511268.980.1216266.7210539.72
ASECH2378.242921.780.435476.046727.56
ACSCH2087.721188.180.1612831.717302.87
ACOTH2117.192335.230.268083.958916.49
Selected special:
gamma2491.817734.530.763266.2313018.78
erf104.11321.200.16669.962163.26
bessely(0,x)7855.7014923.530.839482.9818014.89
bessely(1,x)7302.2914964.260.838786.2918005.36
besselj(0,x)7273.299998.600.759684.8113313.72
besselj(1,x)5987.6710153.130.748077.2513696.38

Advanpix toolbox outperforms MATLAB/VPA by 5000 times and MAPLE by 6766 times by speed in average. Test scripts are available for download:

Run timing_elementary_advanpix to test Advanpix toolbox, and timing_elementary_vpa to test VPA. Don’t forget to add toolbox directory to search path before running the toolbox tests!

***
Toolbox’s timings are higher on GNU Linux & Apple Mac OSX. We can do deeper performance optimization on Windows since we have full license of Intel Developer tools on the platform.

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: