mikereedell / sunrisesunsetlib-java

Library for computing the sunrise/sunset from GPS coordinates and a date, in Java.
http://mikereedell.github.com/sunrisesunsetlib-java/
Apache License 2.0
299 stars 69 forks source link

Improve Performance by Avoiding Recalculating Constants #46

Open luckylsk34 opened 1 year ago

luckylsk34 commented 1 year ago

In convertRadiansToDegrees and convertDegreesToRadians methods, we are creating BigDecimals of PI/180 and 180/PI. These values have high precision and BigDecimal is too slow. We move these into a static variable to avoid repeated creations.

This change nets us about 50-66% speedup. The following table contains the testing on my machine. Index Total Operations(ops) Total Time(s) Speed(ops/s) Speedup
Default 5,000,000 92 5.43E+04 1.00
Moved to Static Variables 5,000,000 55 9.09E+04 1.67
luckylsk34 commented 1 year ago

@mikereedell Hi Mike, please review.