Skip to content

Drop BigDecimal#46

Merged
rhannequin merged 1 commit intomainfrom
drop-bigdecimal
Apr 4, 2024
Merged

Drop BigDecimal#46
rhannequin merged 1 commit intomainfrom
drop-bigdecimal

Conversation

@rhannequin
Copy link
Owner

@rhannequin rhannequin commented Apr 2, 2024

BigDecimal was introduced early in the project from my belief that high accuracy was needed.

It turns out that the number of digits in floats are enough to keep a precision up to 0.0001 arcseconds in most calculations.

Using BigDecimal has a cost over the overall performance of the library. If it is not absolutely necessary for the calculations, it's better not to use it. Calculations are performed 11 times faster using only floats, for the same precision (see benchmark below).

Benchmark

The benchmark simply executes usual calculations enabled by the library at the moment, many times.

Benchmark.bmbm do |x|
  x.report do
    10_000.times do
      time = Time.utc(2023, 2, 17, 11, 0, 0)
      epoch = Astronoby::Epoch.from_time(time)

      observer = Astronoby::Observer.new(
        latitude: Astronoby::Angle.from_degrees(38),
        longitude: Astronoby::Angle.from_degrees(-78)
      )

      sun = Astronoby::Sun.new(epoch: epoch)

      sun
        .apparent_ecliptic_coordinates
        .to_apparent_equatorial(epoch: epoch)
        .to_horizontal(
          time: time,
          latitude: observer.latitude,
          longitude: observer.longitude
        )

      sun.rising_time(observer: observer)
      sun.rising_azimuth(observer: observer).str(:dms)
      sun.setting_time(observer: observer)
      sun.setting_azimuth(observer: observer).str(:dms)

      year = 2024
      Astronoby::EquinoxSolstice.march_equinox(year)
      Astronoby::EquinoxSolstice.june_solstice(year)
    end
  end
end
                         user    system      total         real
with BigDecimal     61.342663  0.351669  61.694332  (61.892873)
without BigDecimal   5.286487  0.004743   5.291230   (5.308093)

@rhannequin rhannequin self-assigned this Apr 2, 2024
`BigDecimal` was introduced early in the project from my belief that
high accuracy was needed.

It turns out that the number of digits in floats are enough to keep a
precision up to 0.0001 arcseconds in most calculations.

Using `BigDecimal` has a cost over the overall performance of the
library. If it is not absolutely necessary for the calculations, it's
better not to use it.
@rhannequin rhannequin marked this pull request as ready for review April 3, 2024 13:19
@rhannequin rhannequin merged commit e3d862f into main Apr 4, 2024
@rhannequin rhannequin deleted the drop-bigdecimal branch April 4, 2024 06:23
rhannequin added a commit that referenced this pull request Apr 29, 2024
 ## What's Changed

_If you are upgrading: please see [UPGRADING.md]._

[UPGRADING.md]: https://github.com/rhannequin/astronoby/blob/main/UPGRADING.md

 ### Bug fixes

* Fix ecliptic to equatorial epoch ([#56])

[#56]: #56

 ### Features

* Add twilight times ([#49])
* Add interpolation method ([#52])
* Add decimal_hour_to_time util ([#53])
* Calculate leap seconds for an instant ([#54])
* Add `Angle#-@` ([#55])
* Enable equivalence and hash equality to `Observer` ([#57])
* Twilight events dedicated class ([#61])

[#49]: #49
[#52]: #52
[#53]: #53
[#54]: #54
[#55]: #55
[#57]: #57
[#61]: #61

 ### Improvements

* Upgrade bundler from 2.3.11 to 2.5.7 by @dorianmariecom ([#45])
* Drop `BigDecimal` ([#46])
* Bump rake from 13.1.0 to 13.2.0 ([#47])
* Increase Ruby versions support ([#48])
* Bump rake from 13.2.0 to 13.2.1 ([#51])
* Dedicated constants class ([#62])
* Improve accuracy of equation of time ([#63])
* Twilight times better accuracy ([#65])
* Update UPGRADING.md ([#66])
* release: Bump version to 0.4.0 ([#67])

[#45]: #45
[#46]: #46
[#47]: #47
[#48]: #48
[#51]: #51
[#62]: #62
[#63]: #63
[#65]: #65
[#66]: #66
[#67]: #67

 ### Backward-incompatible changes

* More accurate rising, transit and setting times ([#50])
* Observation events dedicated and centralized class ([#60])
* Change `Astronoby::Sun` constructor ([#64])

[#50]: #50
[#60]: #60
[#64]: #64

 ## New Contributors

* @dorianmariecom made their first contribution in [#45]

[#45]: #45

**Full Changelog**: v0.3.0...v0.4.0
rhannequin added a commit that referenced this pull request Apr 29, 2024
## What's Changed

_If you are upgrading: please see [UPGRADING.md]._

[UPGRADING.md]: https://github.com/rhannequin/astronoby/blob/main/UPGRADING.md

 ### Bug fixes

* Fix ecliptic to equatorial epoch ([#56])

[#56]: #56

 ### Features

* Add twilight times ([#49])
* Add interpolation method ([#52])
* Add decimal_hour_to_time util ([#53])
* Calculate leap seconds for an instant ([#54])
* Add `Angle#-@` ([#55])
* Enable equivalence and hash equality to `Observer` ([#57])
* Twilight events dedicated class ([#61])

[#49]: #49
[#52]: #52
[#53]: #53
[#54]: #54
[#55]: #55
[#57]: #57
[#61]: #61

 ### Improvements

* Upgrade bundler from 2.3.11 to 2.5.7 by @dorianmariecom ([#45])
* Drop `BigDecimal` ([#46])
* Bump rake from 13.1.0 to 13.2.0 ([#47])
* Increase Ruby versions support ([#48])
* Bump rake from 13.2.0 to 13.2.1 ([#51])
* Dedicated constants class ([#62])
* Improve accuracy of equation of time ([#63])
* Twilight times better accuracy ([#65])
* Update UPGRADING.md ([#66])
* release: Bump version to 0.4.0 ([#67])

[#45]: #45
[#46]: #46
[#47]: #47
[#48]: #48
[#51]: #51
[#62]: #62
[#63]: #63
[#65]: #65
[#66]: #66
[#67]: #67

 ### Backward-incompatible changes

* More accurate rising, transit and setting times ([#50])
* Observation events dedicated and centralized class ([#60])
* Change `Astronoby::Sun` constructor ([#64])

[#50]: #50
[#60]: #60
[#64]: #64

 ## New Contributors

* @dorianmariecom made their first contribution in [#45]

[#45]: #45

**Full Changelog**: v0.3.0...v0.4.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant