Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Apache Math3 FastMath where appropriate #5

Open
magneticflux- opened this issue Jun 14, 2017 · 1 comment
Open

Use Apache Math3 FastMath where appropriate #5

magneticflux- opened this issue Jun 14, 2017 · 1 comment
Assignees

Comments

@magneticflux-
Copy link

The FastMath utility often gives better performance than Java's standard Math class. These are the results of a benchmark on my PC of StrictMath, FastMath, and Math.

Name     StrictMath      FastMath          Math Runs=10000000 Java 1.8.0_131 (1.8.0_131-b11) Java HotSpot(TM) Client VM (25.131-b11)
abs        4    1.0     13 3.1702      4 1.0171
acos      58    1.0    145 2.5009     57 0.9924
asin      55    1.0    115 2.0705     55 0.9955
atan      84    1.0     68 0.8105     84 1.0007
atan2    101    1.0    108 1.0697    100 0.9917
cbrt     121    1.0     95 0.7920    119 0.9898
cos       95    1.0     53 0.5573     73 0.7737
cosh     113    1.0     48 0.4292    113 0.9971
exp       91    1.0     33 0.3717     76 0.8419
expm1    104    1.0     43 0.4113    103 0.9916
hypot    100    1.0    108 1.0786    100 0.9997
log       82    1.0     72 0.8818     38 0.4740
log10    112    1.0    143 1.2806     38 0.3448
log1p     92    1.0    144 1.5593     92 0.9971
pow      258    1.0    184 0.7138    105 0.4074
sin       95    1.0     54 0.5717     77 0.8137
sinh     132    1.0     49 0.3723    128 0.9688
sqrt      12    1.0     12 0.9929     12 0.9934
tan      131    1.0     78 0.5965    110 0.8391
tanh      79    1.0     34 0.4302     79 0.9995

The integer number is the number of nanoseconds per operation (smaller is better) and the float number is the percentage of the time of the StrictMath class (smaller is better, < 1 is faster than StrictMath). As you can see, the exp() function is 2.3x faster in the FastMath class than standard.

@daipenger daipenger self-assigned this Jun 18, 2017
@daipenger
Copy link
Owner

I will look into it, thanks for the overall benchmarking.
I guess most of the exponential functions aren't even needed with much accuracy in the mod so it may be worth to implement them with low-degree taylor polynomials and tweaked development points.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants