Skip to content

Commit

Permalink
Use faster loop iter (despite clippy's advice)
Browse files Browse the repository at this point in the history
    $ cargo bench --bench="*" rust --  --baseline=main-2024-01-25
    direct (rust impl)/default
                            time:   [27.773 µs 27.806 µs 27.842 µs]
                            change: [-4.9255% -4.6540% -4.3868%] (p = 0.00 < 0.05)
                            Performance has improved.

    inverse (rust impl)/default
                            time:   [70.088 µs 70.139 µs 70.194 µs]
                            change: [-9.8981% -9.7426% -9.5881%] (p = 0.00 < 0.05)
                            Performance has improved.
  • Loading branch information
michaelkirk committed Jan 25, 2024
1 parent 9f2b3b9 commit f41bfdc
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/geodesic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,26 @@ impl Geodesic {
pub fn _C3f(&self, eps: f64, c: &mut [f64]) {
let mut mult = 1.0;
let mut o = 0;
for (l, c_item) in c.iter_mut().enumerate().take(self.GEODESIC_ORDER).skip(1) {
let m = self.GEODESIC_ORDER - l - 1;
// Clippy wants us to turn this into `c.iter_mut().enumerate().take(geodesic_order + 1).skip(1)`
// but benching (rust-1.75) shows that it would be slower.
#[allow(clippy::needless_range_loop)]
for l in 1..GEODESIC_ORDER {
let m = GEODESIC_ORDER - l - 1;
mult *= eps;
*c_item = mult * geomath::polyval(m, &self._C3x[o..], eps);
c[l] = mult * geomath::polyval(m, &self._C3x[o..], eps);
o += m + 1;
}
}

pub fn _C4f(&self, eps: f64, c: &mut [f64]) {
let mut mult = 1.0;
let mut o = 0;
for (l, c_item) in c.iter_mut().enumerate().take(self.GEODESIC_ORDER) {
let m = self.GEODESIC_ORDER - l - 1;
*c_item = mult * geomath::polyval(m, &self._C4x[o..], eps);
// Clippy wants us to turn this into `c.iter_mut().enumerate().take(geodesic_order + 1).skip(1)`
// but benching (rust-1.75) shows that it would be slower.
#[allow(clippy::needless_range_loop)]
for l in 0..GEODESIC_ORDER {
let m = GEODESIC_ORDER - l - 1;
c[l] = mult * geomath::polyval(m, &self._C4x[o..], eps);
o += m + 1;
mult *= eps;
}
Expand Down

0 comments on commit f41bfdc

Please sign in to comment.