Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
StrictMath vs FastMath vs Math
Intel Core i7 CPU 860 2.80GHz
Running org.apache.commons.math.util.FastMathTestPerformance
Name StrictMath FastMath Math Runs=10000000 Java 1.6.0_25-ea (1.6.0_25-ea-b01) Java HotSpot(TM) 64-Bit Server VM (20.0-b08)
log 71 1.0 39 0.5555 21 0.2953
log10 94 1.0 108 1.1466 20 0.2174
log1p 74 1.0 103 1.3986 76 1.0269
pow 244 1.0 140 0.5726 238 0.9752
powII 159 1.0 120 0.7582 149 0.9415
exp 53 1.0 26 0.4959 39 0.7323
sin 42 1.0 34 0.8286 35 0.8464
asin 345 1.0 135 0.3911 347 1.0055
cos 46 1.0 37 0.8064 34 0.7414
acos 340 1.0 139 0.4079 354 1.0383
tan 80 1.0 68 0.8462 51 0.6461
atan 64 1.0 64 0.9931 66 1.0285
atan2 103 1.0 95 0.9257 104 1.0069
hypot 598 1.0 34 0.0573 592 0.9906
cbrt 95 1.0 67 0.7088 96 1.0151
sqrt 9 1.0 9 0.9818 9 1.0069
cosh 84 1.0 60 0.7248 85 1.0221
sinh 95 1.0 68 0.7159 98 1.0352
tanh 120 1.0 86 0.7193 117 0.9751
expm1 66 1.0 66 0.9961 66 1.0102
abs 1 1.0 5 2.8708 2 1.4429
Running org.apache.commons.math.util.FastMathTestPerformance
Name StrictMath FastMath Math Runs=10000000 Java 1.7.0-ea (1.7.0-ea-b130) Java HotSpot(TM) 64-Bit Server VM (21.0-b02)
log 66 1.0 39 0.5900 20 0.3102
log10 86 1.0 107 1.2369 20 0.2415
log1p 68 1.0 105 1.5388 70 1.0281
pow 214 1.0 139 0.6499 202 0.9434
powII 135 1.0 125 0.9273 125 0.9327
exp 56 1.0 27 0.4892 37 0.6726
sin 40 1.0 34 0.8710 35 0.8797
asin 323 1.0 134 0.4164 327 1.0121
cos 43 1.0 37 0.8695 33 0.7779
acos 320 1.0 142 0.4439 325 1.0140
tan 60 1.0 67 1.1187 47 0.7807
atan 52 1.0 65 1.2566 53 1.0168
atan2 94 1.0 97 1.0329 93 0.9834
hypot 576 1.0 33 0.0589 575 0.9971
cbrt 93 1.0 67 0.7252 94 1.0129
sqrt 9 1.0 9 1.0103 9 0.9810
cosh 85 1.0 62 0.7313 86 1.0116
sinh 96 1.0 67 0.6998 99 1.0296
tanh 105 1.0 82 0.7823 106 1.0037
expm1 66 1.0 69 1.0505 70 1.0537
abs 2 1.0 5 2.5366 2 0.9077

For comparison:
Intel(R) Core i5-3210M CPU @ 2.50GHz

Name     StrictMath      FastMath          Math Runs=10000000 Java 1.8.0_51 (1.8.0_51-b16) Java HotSpot(TM) 64-Bit Server VM (25.51-b03)
log       62    1,0     42 0,6853     24 0,3903
log10     88    1,0    108 1,2269     24 0,2725
log1p     68    1,0    104 1,5245     72 1,0475
pow      216    1,0    147 0,6785     83 0,3869
powII    135    1,0    231 1,7094    401 2,9659
exp       52    1,0     31 0,6070     61 1,1822
sin       34    1,0     20 0,5833     41 1,1827
asin     324    1,0    123 0,3810    326 1,0046
cos       39    1,0     38 0,9767     40 1,0390
acos     318    1,0    138 0,4356    319 1,0020
tan       59    1,0     64 1,0869     54 0,9143
atan      52    1,0     61 1,1830     51 0,9848
atan2     82    1,0     87 1,0499     86 1,0416
hypot    572    1,0     24 0,0435    575 1,0051
cbrt     103    1,0     72 0,7036    105 1,0205
sqrt       8    1,0      8 1,0336      8 1,0451
cosh      82    1,0     66 0,8036     81 0,9874
sinh      91    1,0     71 0,7840     93 1,0224
tanh     103    1,0     80 0,7809    105 1,0239
expm1     61    1,0     66 1,0782     63 1,0377
abs        1    1,0      1 0,7298      2 1,1563
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment