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

Implement geo-traits for writing to WKT & perf improvement #124

Draft
wants to merge 7 commits into
base: kyle/geo-traits
Choose a base branch
from
Draft
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
28 changes: 27 additions & 1 deletion benches/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,31 @@ fn geo_write_wkt(c: &mut criterion::Criterion) {
});
}

criterion_group!(benches, wkt_to_string, geo_to_wkt_string, geo_write_wkt);
fn geo_write_wkt_as_trait(c: &mut criterion::Criterion) {
c.bench_function("geo: write small wkt using trait", |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(|| {
wkt::to_wkt::write_geometry(&g, &mut String::new()).unwrap();
});
});

c.bench_function("geo: write big wkt using trait", |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(|| {
wkt::to_wkt::write_geometry(&g, &mut String::new()).unwrap();
});
});
}

criterion_group!(
benches,
wkt_to_string,
geo_to_wkt_string,
geo_write_wkt,
geo_write_wkt_as_trait
);
criterion_main!(benches);
13 changes: 3 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@ use geo_traits::{
};
use num_traits::{Float, Num, NumCast};

use crate::to_wkt::write_geometry;
use crate::tokenizer::{PeekableTokens, Token, Tokens};
use crate::types::{
Dimension, GeometryCollection, LineString, MultiLineString, MultiPoint, MultiPolygon, Point,
Polygon,
};

mod to_wkt;
pub mod to_wkt;
mod tokenizer;

/// `WKT` primitive types and collections
Expand Down Expand Up @@ -359,15 +360,7 @@ where
T: WktNum + fmt::Display,
{
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
match self {
Wkt::Point(point) => point.fmt(f),
Wkt::LineString(linestring) => linestring.fmt(f),
Wkt::Polygon(polygon) => polygon.fmt(f),
Wkt::MultiPoint(multipoint) => multipoint.fmt(f),
Wkt::MultiLineString(multilinstring) => multilinstring.fmt(f),
Wkt::MultiPolygon(multipolygon) => multipolygon.fmt(f),
Wkt::GeometryCollection(geometrycollection) => geometrycollection.fmt(f),
}
write_geometry(self, f)
}
}

Expand Down
Loading
Loading