diff --git a/benches/parse.rs b/benches/parse.rs index 58da456..af85dc8 100644 --- a/benches/parse.rs +++ b/benches/parse.rs @@ -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(|| { @@ -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::::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::::from_str(s).unwrap()); + }); + }); +} + +criterion_group!(benches, bench_parse, bench_parse_to_geo); criterion_main!(benches); diff --git a/benches/write.rs b/benches/write.rs new file mode 100644 index 0000000..50f5356 --- /dev/null +++ b/benches/write.rs @@ -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::::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::::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::::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::::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::::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::::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); diff --git a/src/geo_types_from_wkt.rs b/src/geo_types_from_wkt.rs index 0d78413..a23d3bd 100644 --- a/src/geo_types_from_wkt.rs +++ b/src/geo_types_from_wkt.rs @@ -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"); diff --git a/src/lib.rs b/src/lib.rs index 8d784d2..801ae5a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,7 +27,6 @@ //! use wkt::Wkt; //! let point: Wkt = 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 @@ -58,9 +57,6 @@ //! } //! _ => unreachable!(), //! }; -//! -//! -//! use std::default::Default; use std::fmt; use std::str::FromStr; @@ -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; @@ -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`")] diff --git a/src/towkt.rs b/src/to_wkt.rs similarity index 99% rename from src/towkt.rs rename to src/to_wkt.rs index cbbd66b..be6c8b3 100644 --- a/src/towkt.rs +++ b/src/to_wkt.rs @@ -12,7 +12,6 @@ where fn to_wkt(&self) -> Wkt; /// 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). @@ -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).