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

Add some benches and some internal cleanup #94

Merged
merged 3 commits into from
Apr 28, 2022
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
20 changes: 18 additions & 2 deletions benches/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extern crate wkt;

use std::str::FromStr;

fn criterion_benchmark(c: &mut criterion::Criterion) {
fn bench_parse(c: &mut criterion::Criterion) {
c.bench_function("parse small", |bencher| {
let s = include_str!("./small.wkt");
bencher.iter(|| {
Expand All @@ -20,5 +20,21 @@ fn criterion_benchmark(c: &mut criterion::Criterion) {
});
}

criterion_group!(benches, criterion_benchmark);
fn bench_parse_to_geo(c: &mut criterion::Criterion) {
c.bench_function("parse small to geo", |bencher| {
let s = include_str!("./small.wkt");
bencher.iter(|| {
let _ = geo_types::Geometry::try_from(wkt::Wkt::<f64>::from_str(s).unwrap());
});
});

c.bench_function("parse big to geo", |bencher| {
let s = include_str!("./big.wkt");
bencher.iter(|| {
let _ = geo_types::Geometry::try_from(wkt::Wkt::<f64>::from_str(s).unwrap());
});
});
}

criterion_group!(benches, bench_parse, bench_parse_to_geo);
criterion_main!(benches);
68 changes: 68 additions & 0 deletions benches/write.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#[macro_use]
extern crate criterion;

extern crate wkt;
use wkt::ToWkt;

use std::str::FromStr;

fn wkt_to_string(c: &mut criterion::Criterion) {
c.bench_function("to_string small wkt", |bencher| {
let s = include_str!("./small.wkt");
let w = wkt::Wkt::<f64>::from_str(s).unwrap();
bencher.iter(|| {
let _ = w.to_string();
});
});

c.bench_function("to_string big wkt", |bencher| {
let s = include_str!("./big.wkt");
let w = wkt::Wkt::<f64>::from_str(s).unwrap();
bencher.iter(|| {
let _ = w.to_string();
});
});
}

fn geo_to_wkt_string(c: &mut criterion::Criterion) {
c.bench_function("geo: serialize small wkt string", |bencher| {
let s = include_str!("./small.wkt");
let w = wkt::Wkt::<f64>::from_str(s).unwrap();
let g = geo_types::Geometry::try_from(w).unwrap();
bencher.iter(|| {
let _ = g.wkt_string();
});
});

c.bench_function("geo: serialize big wkt string", |bencher| {
let s = include_str!("./big.wkt");
let w = wkt::Wkt::<f64>::from_str(s).unwrap();
let g = geo_types::Geometry::try_from(w).unwrap();
bencher.iter(|| {
let _ = g.wkt_string();
});
});
}

fn geo_write_wkt(c: &mut criterion::Criterion) {
c.bench_function("geo: write small wkt", |bencher| {
let s = include_str!("./small.wkt");
let w = wkt::Wkt::<f64>::from_str(s).unwrap();
let g = geo_types::Geometry::try_from(w).unwrap();
bencher.iter(|| {
let _ = g.write_wkt(std::io::sink());
});
});

c.bench_function("geo: write big wkt", |bencher| {
let s = include_str!("./big.wkt");
let w = wkt::Wkt::<f64>::from_str(s).unwrap();
let g = geo_types::Geometry::try_from(w).unwrap();
bencher.iter(|| {
let _ = g.write_wkt(std::io::sink());
});
});
}

criterion_group!(benches, wkt_to_string, geo_to_wkt_string, geo_write_wkt);
criterion_main!(benches);
5 changes: 0 additions & 5 deletions src/geo_types_from_wkt.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
//! This module provides conversions between WKT primitives and [`geo_types`] primitives.
//!
//! See the [`std::convert::From`] and [`std::convert::TryFrom`] impls on individual [`crate::types`] and [`Wkt`] for details.
//!
//!
//!
//!
//!
// Copyright 2014-2018 The GeoRust Developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
8 changes: 2 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
//! use wkt::Wkt;
//! let point: Wkt<f64> = Wkt::from_str("POINT(10 20)").unwrap();
//! ```
//!
#![cfg_attr(feature = "geo-types", doc = "```")]
#![cfg_attr(not(feature = "geo-types"), doc = "```ignore")]
//! // Convert to a geo_types primitive from a Wkt struct
Expand Down Expand Up @@ -58,9 +57,6 @@
//! }
//! _ => unreachable!(),
//! };
//!
//!
//!
use std::default::Default;
use std::fmt;
use std::str::FromStr;
Expand All @@ -74,8 +70,8 @@ use crate::types::MultiPolygon;
use crate::types::Point;
use crate::types::Polygon;

mod to_wkt;
mod tokenizer;
mod towkt;

/// `WKT` primitive types and collections
pub mod types;
Expand All @@ -85,7 +81,7 @@ extern crate geo_types;

extern crate thiserror;

pub use crate::towkt::ToWkt;
pub use crate::to_wkt::ToWkt;

#[cfg(feature = "geo-types")]
#[deprecated(note = "renamed module to `wkt::geo_types_from_wkt`")]
Expand Down
2 changes: 0 additions & 2 deletions src/towkt.rs → src/to_wkt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ where
fn to_wkt(&self) -> Wkt<T>;

/// Serialize as a WKT string
///
#[cfg_attr(feature = "geo-types", doc = "```")]
#[cfg_attr(not(feature = "geo-types"), doc = "```ignore")]
/// // This example requires the geo-types feature (on by default).
Expand All @@ -25,7 +24,6 @@ where
}

/// Write a WKT string to a [`File`](std::fs::File), or anything else that implements [`Write`](std::io::Write).
///
#[cfg_attr(feature = "geo-types", doc = "```")]
#[cfg_attr(not(feature = "geo-types"), doc = "```ignore")]
/// // This example requires the geo-types feature (on by default).
Expand Down