Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#13 partial. Added geomath::ang_diff test and benchmark #14

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "test_fixtures/geographiclib-instrumented"]
path = test_fixtures/geographiclib-instrumented
url = https://[email protected]/u/alephknot/geographiclib
branch = instrumented-crude
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ license = "MIT"
edition = "2018"

description = "A port of geographiclib in Rust."
authors = ["Federico Dolce <[email protected]>", "Michael Kirk <[email protected]>"]
authors = ["Federico Dolce <[email protected]>", "Michael Kirk <[email protected]>", "Stony Lohr <[email protected]>"]
repository = "https://github.com/georust/geographiclib-rs"
keywords = ["gis", "geo", "geography", "geospatial"]
documentation = "https://docs.rs/geographiclib-rs"
Expand All @@ -18,7 +18,12 @@ lazy_static = "1.4.0"
assert_approx_eq = "1.1.0"
criterion = "0.3.1"
geographiclib = "0.1.0"
utilities = { path = "utilities" }

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

[[bench]]
name = "geomath_benchmark"
harness = false
188 changes: 186 additions & 2 deletions benches/geodesic_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ extern crate geographiclib;
extern crate geographiclib_rs;

use criterion::{criterion_group, criterion_main, Criterion};

use geographiclib_rs::{DirectGeodesic, InverseGeodesic};
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::sync::{Arc, Mutex};
use std::time::Duration;
use utilities::nC_;

fn geodesic_direct_benchmark(c: &mut Criterion) {
const INPUT_FOR_DIRECT: &'static str = "test_fixtures/GeodTest-100.dat";
Expand Down Expand Up @@ -76,9 +78,191 @@ fn geodesic_inverse_benchmark(c: &mut Criterion) {
});
}

// Benchmarks using logged cpp values as inputs

// Note that using Arc and Mutex to access a shared dataset results
// in much lower overhead than cloning the dataset in each iteration.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


// placeholder: Geodesic_A1m1f
// placeholder: Geodesic_A2m1f
// placeholder: Geodesic_A3coeff
// placeholder: Geodesic_A3f

// Note: For Geodesic_Astroid, see geomath_benchmark.rs

// placeholder: Geodesic_C1f
// placeholder: Geodesic_C1pf
// placeholder: Geodesic_C2f
// placeholder: Geodesic_C3coeff
// placeholder: Geodesic_C3f
// placeholder: Geodesic_C4coeff
// placeholder: Geodesic_C4f

fn benchmark_geodesic_gen_direct(c: &mut Criterion) {
// Format: this-in[_a _f] lat1 lon1 azi1 arcmode s12_a12 outmask result=a12 lat2-out lon2-out azi2-out s12-out m12-out M12-out M21-out S12-out
let data = utilities::as_vecs_basic("Geodesic_GenDirect", 8);
let geods = utilities::get_geodesic_lookup(&data);
let data_arc = Arc::new(Mutex::new((data, geods)));
c.bench_function("Geodesic._gen_direct (rust impl, cpp log inputs)", |b| {
let pair = data_arc.lock().unwrap();
let data = &pair.0;
let geods = &pair.1;
b.iter(|| {
for i in 0..data.len() {
let line = &data[i];
let g = utilities::get_geodesic(line[0], line[1], &geods);
let _result = g._gen_direct(line[2], line[3], line[4], line[5] != 0.0, line[6], line[7] as u64);
}
})
});
}

// placeholder: Geodesic_GenDirectLine

fn benchmark_geodesic_gen_inverse_azi(c: &mut Criterion) {
// Format: this-in[_a _f] lat1 lon1 lat2 lon2 outmask result=a12 s12-out azi1-out azi2-out m12-out M12-out M21-out S12-out
let data = utilities::as_vecs_basic("Geodesic_GenInverse_out7", 7);
let geods = utilities::get_geodesic_lookup(&data);
let data_arc = Arc::new(Mutex::new((data, geods)));
c.bench_function("Geodesic._gen_inverse_azi (rust impl, cpp log inputs)", |b| {
let pair = data_arc.lock().unwrap();
let data = &pair.0;
let geods = &pair.1;
b.iter(|| {
for i in 0..data.len() {
let line = &data[i];
let g = utilities::get_geodesic(line[0], line[1], &geods);
let _result = g._gen_inverse_azi(line[2], line[3], line[4], line[5], line[6] as u64);
}
})
});
}

fn benchmark_geodesic_gen_inverse(c: &mut Criterion) {
// Format: this-in[_a _f] lat1 lon1 lat2 lon2 outmask result=a12 s12-out salp1-out calp1-out salp2-out calp2-out m12-out M12-out M21-out S12-out
let data = utilities::as_vecs_basic("Geodesic_GenInverse_out9", 7);
let geods = utilities::get_geodesic_lookup(&data);
let data_arc = Arc::new(Mutex::new((data, geods)));
c.bench_function("Geodesic._gen_inverse (rust impl, cpp log inputs)", |b| {
let pair = data_arc.lock().unwrap();
let data = &pair.0;
let geods = &pair.1;
b.iter(|| {
for i in 0..data.len() {
let line = &data[i];
let g = utilities::get_geodesic(line[0], line[1], &geods);
let _result = g._gen_inverse(line[2], line[3], line[4], line[5], line[6] as u64);
}
})
});
}

fn benchmark_geodesic_new(c: &mut Criterion) {
// Format: this-in[_a _f] lat1 lon1 lat2 lon2 outmask result=a12 s12-out salp1-out calp1-out salp2-out calp2-out m12-out M12-out M21-out S12-out
let data_arc = Arc::new(Mutex::new(utilities::as_vecs_basic("Geodesic_Geodesic", 2)));
c.bench_function("Geodesic.new (rust impl, cpp log inputs)", |b| {
let data = data_arc.lock().unwrap();
b.iter(|| {
for i in 0..data.len() {
let line = &data[i];
let _result = geographiclib_rs::Geodesic::new(line[0], line[1]);
}
})
});
}

// placeholder: Geodesic_InverseLine

fn benchmark_geodesic_inverse_start(c: &mut Criterion) {
// Format: this-in[_a _f] sbet1 cbet1 dn1 sbet2 cbet2 dn2 lam12 slam12 clam12 result=sig12 salp1-out calp1-out salp2-out calp2-out dnm-out
let mut group = c.benchmark_group("Geodesic._InverseStart adjustmented");
group.measurement_time(Duration::from_secs_f64(7.5));

let data = utilities::as_vecs_basic("Geodesic_InverseStart", 11);
let geods = utilities::get_geodesic_lookup(&data);
let data_arc = Arc::new(Mutex::new((data, geods)));
group.bench_function("Geodesic._InverseStart (rust impl, cpp log inputs)", |b| {
let pair = data_arc.lock().unwrap();
let data = &pair.0;
let geods = &pair.1;
#[allow(non_snake_case)]
let mut C1a: [f64; nC_] = [0.0 ; nC_];
#[allow(non_snake_case)]
let mut C2a: [f64; nC_] = [0.0 ; nC_];
b.iter(|| {
for i in 0..data.len() {
let line = &data[i];
let g = utilities::get_geodesic(line[0], line[1], &geods);
let _result = g._InverseStart(line[2], line[3], line[4], line[5], line[6], line[7], line[8], line[9], line[10], &mut C1a, &mut C2a);
}
})
});

group.finish();
}

fn benchmark_geodesic_lambda12(c: &mut Criterion) {
// Format: this-in[_a _f] sbet1 cbet1 dn1 sbet2 cbet2 dn2 salp1 calp1 slam120 clam120 diffp result=lam12 salp2-out calp2-out sig12-out ssig1-out csig1-out ssig2-out csig2-out eps-out domg12-out dlam12-out
let data = utilities::as_vecs_basic("Geodesic_Lambda12", 13);
let geods = utilities::get_geodesic_lookup(&data);
let data_arc = Arc::new(Mutex::new((data, geods)));
c.bench_function("Geodesic._Lambda12 (rust impl, cpp log inputs)", |b| {
let pair = data_arc.lock().unwrap();
let data = &pair.0;
let geods = &pair.1;
#[allow(non_snake_case)]
let mut C1a: [f64; nC_] = [0.0 ; nC_];
#[allow(non_snake_case)]
let mut C2a: [f64; nC_] = [0.0 ; nC_];
#[allow(non_snake_case)]
let mut C3a: [f64; nC_] = [0.0 ; nC_];
b.iter(|| {
for i in 0..data.len() {
let line = &data[i];
let g = utilities::get_geodesic(line[0], line[1], &geods);
let mut calp1 = line[9];
let _result = g._Lambda12(line[2], line[3], line[4], line[5], line[6], line[7], line[8], &mut calp1, line[10], line[11], line[12] != 0.0, &mut C1a, &mut C2a, &mut C3a);
}
})
});
}

fn benchmark_geodesic_lengths(c: &mut Criterion) {
// Format: this-in[_a _f] eps sig12 ssig1 csig1 dn1 ssig2 csig2 dn2 cbet1 cbet2 outmask s12b-out m12b-out m0-out M12-out M21-out
let data = utilities::as_vecs_basic("Geodesic_Lengths", 13);
let geods = utilities::get_geodesic_lookup(&data);
let data_arc = Arc::new(Mutex::new((data, geods)));
c.bench_function("Geodesic._Lengths (rust impl, cpp log inputs)", |b| {
let pair = data_arc.lock().unwrap();
let data = &pair.0;
let geods = &pair.1;
#[allow(non_snake_case)]
let mut C1a: [f64; nC_] = [0.0 ; nC_];
#[allow(non_snake_case)]
let mut C2a: [f64; nC_] = [0.0 ; nC_];
b.iter(|| {
for i in 0..data.len() {
let line = &data[i];
let g = utilities::get_geodesic(line[0], line[1], &geods);
let _result = g._Lengths(line[2], line[3], line[4], line[5], line[6], line[7], line[8], line[9], line[10], line[11], line[12] as u64, &mut C1a, &mut C2a);
}
})
});
}

// Note: For Geodesic_SinCosSeries see geomath_benchmark.rs


criterion_group!(
benches,
geodesic_direct_benchmark,
geodesic_inverse_benchmark
geodesic_inverse_benchmark,
benchmark_geodesic_gen_direct,
benchmark_geodesic_gen_inverse_azi,
benchmark_geodesic_gen_inverse,
benchmark_geodesic_new,
benchmark_geodesic_inverse_start,
benchmark_geodesic_lambda12,
benchmark_geodesic_lengths,
);
criterion_main!(benches);
Loading