Exponential Functions: Benchmarks, 8 Times Faster Math.pow()
I have updated the code for the Math.pow() approximation, now it is 11 times faster on my Pentium IV. Read Optimized Exponential Functions for Java for more information. Now I can also give you some benchmarks:
Benchmarks
Math.log() — 11.7 times faster
- 6.233 sec, Math.log(x)
- 0.531 sec, 6*(x-1)/ (x + 1 + 4*(Math.sqrt(x)))
Math.exp() — 5.3 times faster
- 5.920 sec, Math.exp(x)
- 1.108 sec, exp optimized with IEEE 754 trick
Math.pow() — 8.7 times faster
- 15.967 sec, Math.pow(a, b)
- 11.014 sec, e^(b * log(a))
- 7.607 sec, e^(b * log(a)) + IEEE 754 trick
- 2.109 sec, e^(b * log(a)) + IEEE 754 trick + LOG approximation
- 1.827 sec, simplified everything, see Optimized Exponential Functions for Java
For accurate measurements I have performed each calculation 20 million times and used a random number generator to prevent optimization. I have measured the overhead of iterating and random number generation (3.969 sec) and substracted this from each measurement so that only the pure functional code is measured.
Tags: approximation, benchmark, java, math, pow


February 15th, 2007 at 8:50 pm
Nice work
I used approximation before in J2ME applications, worked like a charm.
This one is also very nice, you might have seen it before:
http://www.beyond3d.com/articles/fastinvsqrt/
btw, I started a little side-project too, a general selection API for Java JDBC (no over-the-top Hibernate stuff).
http://www.redcode.nl/blog11.html