Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ jobs:
- name: Install CSPICE
run: sh dev-env-setup.sh && cd .. # Return to root

- uses: taiki-e/install-action@cargo-binstall
- name: Install iai-callgrind-runner
run: |
version=$(cargo metadata --format-version=1 |\
jq '.packages[] | select(.name == "iai-callgrind").version' |\
tr -d '"'
)
cargo binstall --no-confirm iai-callgrind-runner --version $version
sudo apt-get install -y valgrind


- name: Bench JPL Ephemerides
run: cargo bench --bench "*_jpl_ephemerides" --workspace --exclude anise-py

Expand Down
10 changes: 8 additions & 2 deletions anise/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ rust-spice = "0.7.6"
parquet = "55.0.0"
arrow = "55.0.0"
criterion = "0.6"
iai = "0.1"
iai-callgrind = "0.14"
pretty_env_logger = { workspace = true }
rstest = { workspace = true }
approx = "0.5.1"
polars = { version = "0.46.0", features = ["lazy", "parquet"] }
rayon = "1.7"
serde_yml = "0.0.12"
rand_pcg = "0.9.0"
rand = "0.9.1"

[build-dependencies]
ureq = { version = "3.0.10", default-features = false, optional = true, features = [
Expand All @@ -71,7 +73,11 @@ embed_ephem = ["rust-embed", "ureq"]
spkezr_validation = []

[[bench]]
name = "iai_jpl_ephemerides"
name = "iai_jpl_ephemeris"
harness = false

[[bench]]
name = "iai_spacecraft_ephemeris"
harness = false

[[bench]]
Expand Down
3 changes: 2 additions & 1 deletion anise/benches/crit_bpc_rotation.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anise::{constants::orientations::ITRF93, prelude::*};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use criterion::{criterion_group, criterion_main, Criterion};
use std::hint::black_box;

const NUM_QUERIES_PER_PAIR: f64 = 100.0;

Expand Down
3 changes: 2 additions & 1 deletion anise/benches/crit_jpl_ephemerides.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use anise::{
file2heap,
prelude::*,
};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use criterion::{criterion_group, criterion_main, Criterion};
use std::hint::black_box;

const NUM_QUERIES_PER_PAIR: f64 = 100.0;

Expand Down
3 changes: 2 additions & 1 deletion anise/benches/crit_planetary_data.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::path::PathBuf;

use anise::{constants::frames::EARTH_ITRF93, naif::kpl::parser::convert_tpc, prelude::*};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use criterion::{criterion_group, criterion_main, Criterion};
use std::hint::black_box;

fn benchmark_fetch(almanac: &Almanac, frame: Frame) {
black_box(almanac.frame_from_uid(frame).unwrap());
Expand Down
45 changes: 26 additions & 19 deletions anise/benches/crit_spacecraft_ephemeris.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
use anise::{constants::frames::EARTH_J2000, file2heap, prelude::*};
use criterion::{criterion_group, criterion_main, Criterion};
use rand::seq::SliceRandom;
use rand::SeedableRng;
use rand_pcg::Pcg64;
use std::hint::black_box;

use criterion::{black_box, criterion_group, criterion_main, Criterion};
const NUM_QUERIES: f64 = 1000.0;
const RNG_SEED: u64 = 1234567890;

const NUM_QUERIES: f64 = 100.0;

fn benchmark_spice_single_hop_type13_hermite(time_it: TimeSeries) {
fn benchmark_spice_single_hop_type13_hermite(time_vec: &[Epoch]) {
// SPICE load
spice::furnsh("../data/gmat-hermite.bsp");
spice::furnsh("../data/de440s.bsp");
spice::furnsh("../data/lro.bsp");

for epoch in time_it {
for epoch in time_vec {
black_box(spice::spkezr(
"-10000001",
"-85",
epoch.to_et_seconds(),
"J2000",
"NONE",
"EARTH",
));
}

spice::unload("../data/gmat-hermite.bsp");
spice::unload("../data/lro.bsp");
spice::unload("../data/de440s.bsp");
}

fn benchmark_anise_single_hop_type13_hermite(ctx: &Almanac, time_it: TimeSeries) {
let my_sc_j2k = Frame::from_ephem_j2000(-10000001);
for epoch in time_it {
fn benchmark_anise_single_hop_type13_hermite(ctx: &Almanac, time_vec: &[Epoch]) {
let my_sc_j2k = Frame::from_ephem_j2000(-85);
for epoch in time_vec.iter().copied() {
black_box(
ctx.translate_geometric(my_sc_j2k, EARTH_J2000, epoch)
.unwrap(),
Expand All @@ -32,32 +38,33 @@ fn benchmark_anise_single_hop_type13_hermite(ctx: &Almanac, time_it: TimeSeries)
}

pub fn criterion_benchmark(c: &mut Criterion) {
let start_epoch = Epoch::from_gregorian_at_noon(2000, 1, 1, TimeScale::UTC);
let end_epoch = Epoch::from_gregorian_hms(2000, 1, 1, 15, 0, 0, TimeScale::UTC);
let start_epoch = Epoch::from_gregorian_at_noon(2023, 12, 15, TimeScale::UTC);
let end_epoch = Epoch::from_gregorian_at_midnight(2024, 1, 9, TimeScale::UTC);
let time_step = ((end_epoch - start_epoch).to_seconds() / NUM_QUERIES).seconds();
let time_it = TimeSeries::exclusive(start_epoch, end_epoch - time_step, time_step);
// Shuffle the time iterator
let mut rng = Pcg64::seed_from_u64(RNG_SEED);
let mut time_vec: Vec<Epoch> = time_it.collect();
time_vec.shuffle(&mut rng);

let path = "../data/de440s.bsp";
let buf = file2heap!(path).unwrap();
let spk = SPK::parse(buf).unwrap();

let buf = file2heap!("../data/gmat-hermite.bsp").unwrap();
let buf = file2heap!("../data/lro.bsp").unwrap();
let spacecraft = SPK::parse(buf).unwrap();

let ctx = Almanac::from_spk(spk)
.unwrap()
.with_spk(spacecraft)
.unwrap();

// Load SPICE data
spice::furnsh("../data/de440s.bsp");

c.bench_function("ANISE hermite", |b| {
b.iter(|| benchmark_anise_single_hop_type13_hermite(&ctx, time_it.clone()))
b.iter(|| benchmark_anise_single_hop_type13_hermite(&ctx, &time_vec))
});

c.bench_function("SPICE hermite", |b| {
b.iter(|| benchmark_spice_single_hop_type13_hermite(time_it.clone()))
b.iter(|| benchmark_spice_single_hop_type13_hermite(&time_vec))
});
}

Expand Down
55 changes: 0 additions & 55 deletions anise/benches/iai_jpl_ephemerides.rs

This file was deleted.

43 changes: 43 additions & 0 deletions anise/benches/iai_jpl_ephemeris.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use anise::{
constants::frames::{EARTH_J2000, MOON_J2000},
file2heap,
prelude::*,
};
use iai_callgrind::{library_benchmark, library_benchmark_group, main};
use std::hint::black_box;

#[library_benchmark]
fn benchmark_spice_single_hop_type2_cheby() {
let epoch = Epoch::from_gregorian_at_noon(2025, 5, 25, TimeScale::ET);

// SPICE load
spice::furnsh("../data/de440s.bsp");

black_box(spice::spkezr(
"EARTH",
epoch.to_et_seconds(),
"J2000",
"NONE",
"MOON",
));

spice::unload("../data/de440s.bsp");
}

#[library_benchmark]
fn benchmark_anise_single_hop_type2_cheby() {
let epoch = Epoch::from_gregorian_at_noon(2025, 5, 25, TimeScale::ET);

let path = "../data/de440s.bsp";
let buf = file2heap!(path).unwrap();
let spk = SPK::parse(buf).unwrap();
let ctx = Almanac::from_spk(spk).unwrap();

black_box(
ctx.translate_geometric(EARTH_J2000, MOON_J2000, epoch)
.unwrap(),
);
}

library_benchmark_group!(name = bench_jpl_ephem; benchmarks = benchmark_anise_single_hop_type2_cheby, benchmark_spice_single_hop_type2_cheby);
main!(library_benchmark_groups = bench_jpl_ephem);
28 changes: 15 additions & 13 deletions anise/benches/iai_spacecraft_ephemeris.rs
Original file line number Diff line number Diff line change
@@ -1,48 +1,50 @@
use anise::{constants::frames::EARTH_J2000, file2heap, prelude::*};
use iai_callgrind::{library_benchmark, library_benchmark_group, main};
use std::hint::black_box;

use iai::black_box;

#[library_benchmark]
fn benchmark_spice_single_hop_type13_hermite() {
let epoch = Epoch::from_gregorian_hms(2000, 1, 1, 14, 0, 0, TimeScale::UTC);
let epoch = Epoch::from_gregorian_hms(2023, 12, 15, 14, 0, 0, TimeScale::UTC);

// SPICE load
spice::furnsh("../data/gmat-hermite.bsp");
spice::furnsh("../data/de440s.bsp");
spice::furnsh("../data/lro.bsp");

black_box(spice::spkezr(
"-10000001",
"-85",
epoch.to_et_seconds(),
"J2000",
"NONE",
"EARTH",
));

spice::unload("../data/gmat-hermite.bsp");
spice::unload("../data/lro.bsp");
spice::unload("../data/de440s.bsp");
}

#[library_benchmark]
fn benchmark_anise_single_hop_type13_hermite() {
let epoch = Epoch::from_gregorian_hms(2000, 1, 1, 14, 0, 0, TimeScale::UTC);
let epoch = Epoch::from_gregorian_hms(2023, 12, 15, 14, 0, 0, TimeScale::UTC);

let path = "../data/de440s.bsp";
let buf = file2heap!(path).unwrap();
let spk = SPK::parse(buf).unwrap();

let buf = file2heap!("../data/gmat-hermite.bsp").unwrap();
let buf = file2heap!("../data/lro.bsp").unwrap();
let spacecraft = SPK::parse(buf).unwrap();

let ctx = Almanac::from_spk(spk)
.unwrap()
.with_spk(spacecraft)
.unwrap();

let my_sc_j2k = Frame::from_ephem_j2000(-10000001);
let my_sc_j2k = Frame::from_ephem_j2000(-85);

black_box(
ctx.translate_geometric(my_sc_j2k, EARTH_J2000, epoch)
.unwrap(),
);
}

iai::main!(
benchmark_spice_single_hop_type13_hermite,
benchmark_anise_single_hop_type13_hermite
);
library_benchmark_group!(name = bench_spacecraft_ephem; benchmarks = benchmark_anise_single_hop_type13_hermite, benchmark_spice_single_hop_type13_hermite);
main!(library_benchmark_groups = bench_spacecraft_ephem);
4 changes: 1 addition & 3 deletions anise/src/math/interpolation/hermite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
/* - SPICELIB Version 1.0.0, 01-MAR-2000 (NJB) */

use crate::errors::MathError;
use log::error;

use super::{InterpolationError, MAX_SAMPLES};

Expand All @@ -84,15 +83,14 @@ pub fn hermite_eval(
what: "list of abscissas (xs) is empty",
});
} else if xs.len() > MAX_SAMPLES {
error!("More than {MAX_SAMPLES} samples provided, which is the maximum number of items allowed for a Hermite interpolation");
return Err(InterpolationError::CorruptedData {
what: "list of abscissas (xs) contains more items than MAX_SAMPLES (32)",
});
}

// At this point, we know that the lengths of items is correct, so we can directly address them without worry for overflowing the array.

let work: &mut [f64] = &mut [0.0; 8 * MAX_SAMPLES];
let work: &mut [f64] = &mut [0.0; 4 * MAX_SAMPLES];
let n: usize = xs.len();

/* Copy the input array into WORK. After this, the first column */
Expand Down
Loading