Skip to content

Added benchmarks vs S2, Boost.Geometry, GeographicLib#14

Open
gistrec wants to merge 4 commits intomasterfrom
add-benchmarks
Open

Added benchmarks vs S2, Boost.Geometry, GeographicLib#14
gistrec wants to merge 4 commits intomasterfrom
add-benchmarks

Conversation

@gistrec
Copy link
Copy Markdown
Owner

@gistrec gistrec commented May 9, 2026

Summary

Adds an opt-in benchmarks/ directory with Google Benchmark micro-benchmarks for:

  • distance_between;
  • heading;
  • contains;
  • area;
  • path_length.

The benchmarks compare geo-utils-cpp against:

  • S2 Geometry;
  • Boost.Geometry with spherical strategy;
  • GeographicLib using WGS84;
  • a naive haversine baseline.

Conversion policy is documented and normalized across libraries: streams of points are converted inside the timed loop (the realistic cost when the input is lat/lng), long-lived polygons are pre-built once outside the loop (matches the geofence-loaded-once-queried-many-times pattern).

Also adds disk-footprint measurement via benchmarks/size/measure.sh. The script builds minimal consumer programs against each library and reports:

  • stripped binary size;
  • on-disk install size.

Documentation changes:

  • adds docs/benchmarks.md with methodology, full results per operation, and a "when to use which library" guide;
  • adds a short summary table to the README;
  • column winners are highlighted in bold (with co-winners marked when within ~5% noise).

Headline numbers on Apple M1, clang 17, -O2 -DNDEBUG:

  • tied with hand-written haversine on distance_between, showing zero header-only overhead;
  • tied with Boost.Geometry on distance / heading within ~5% noise; ahead on every polygon operation;
  • about 9–13× faster than Boost.Geometry on contains (depending on polygon size);
  • ahead of S2 on distance, heading, area, path_length, and on contains against ~10-vertex polygons. S2 wins contains from ~100 vertices onward via its bounding-rectangle prefilter — the documented caveat;
  • 36 KB install size vs:
    • 32.8 MB for S2 (with abseil);
    • 12.3 MB for the Boost.Geometry geometry subset alone;
    • 4.6 MB for GeographicLib.

That makes geo-utils-cpp roughly 130× to 900× smaller, depending on the comparison target.

Build / CI hygiene:

  • URL_HASH SHA256=... pinned for the Google Benchmark FetchContent;
  • size-consumer programs use strtod (not the UB-on-bad-input atof);
  • measure.sh persists failed build logs to build-bench/size-logs/ and reports failure status via a sentinel file (works correctly across command-substitution boundaries);
  • find_package(s2 NAMES s2 S2) accepts both casings of the installed config file.

Benchmarks are off by default via GEO_UTILS_CPP_BUILD_BENCHMARKS=OFF and are not run in CI (would require S2 / Boost / GeographicLib installs). A small smoke-build job in CI compiles bench_geo_utils and bench_naive (the dependency-free portion) so the benchmark plumbing can't bitrot silently.

@gistrec gistrec requested a review from MrHerrn May 9, 2026 01:24
@gistrec gistrec self-assigned this May 9, 2026
@gistrec gistrec marked this pull request as draft May 9, 2026 01:32
@gistrec gistrec marked this pull request as ready for review May 9, 2026 14:20
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