Skip to content

Commit

Permalink
Optimize a lot and deprecate to_u8 methods (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja authored Aug 28, 2024
1 parent 8052170 commit 0817f28
Show file tree
Hide file tree
Showing 11 changed files with 514 additions and 282 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
- ubuntu-latest
- windows-latest
- macos-latest
features:
- []
- [tracing]
steps:
- uses: actions/checkout@v4
- name: Setup Rust
Expand All @@ -52,6 +55,10 @@ jobs:
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}-${{ matrix.rust-toolchain }}
- name: Run
if: matrix.features[0] != null
run: cargo test -p svg-path-cst --features ${{ join(matrix.features, ',') }}
- name: Run
if: matrix.features[0] == null
run: cargo test -p svg-path-cst

test-release-crate:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
target/
Cargo.lock
.prettier-cache
*.svg
*.data
*.data.old
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ repos:
-D,
clippy::semicolon_if_nothing_returned,
]
- repo: https://github.com/mondeja/rust-pc-hooks
rev: v1.2.0
hooks:
- id: cargo-machete
19 changes: 14 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "svg-path-cst"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
readme = "README.md"
description = "CST SVG path parser."
Expand All @@ -12,12 +12,21 @@ repository = "https://github.com/mondeja/svg-path-cst"
name = "svg_path_cst"
path = "src/lib.rs"

[[bin]]
name = "svg-path-cst"
path = "src/main.rs"

[features]
tracing = ["dep:tracing"]

[dependencies]
snafu = { version = "0.8.0", default_features = false }
tracing = { version = "0.1", optional = true }
snafu = { version = "0.8", default-features = false }
tracing = { version = "0.1", optional = true, default-features = false, features = ["attributes"]}

[dev-dependencies]
doc-comment = "0.3.3"
criterion = { version = "0.5", features = ["html_reports"] }

[features]
tracing = ["dep:tracing"]
[[bench]]
name = "performance"
harness = false
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ This crate is compatible with SVG v1.1 paths, as defined in the [W3C SVG 1.1](ht

## Features

- **Tracing support**: `tracing` (see [`tracing`])
- **`tracing`**: Adds [`tracing`] support.

[`tracing`]: https://docs.rs/tracing/latest/tracing
23 changes: 23 additions & 0 deletions benches/performance.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use criterion::{criterion_group, criterion_main, Criterion};
use std::hint::black_box;
use svg_path_cst::{svg_path_cst, SVGPathCSTNode, SyntaxError};

fn parse(data: &[u8]) -> Result<Vec<SVGPathCSTNode>, SyntaxError> {
svg_path_cst(data)
}

fn performance(c: &mut Criterion) {
let data = b"M 10 10 L 20 20";
c.bench_function("basic", |b| b.iter(|| parse(black_box(data))));

let simpleicons_data = include_bytes!("../fuzz/corpus/simpleicons.txt");
c.bench_function("simpleicons", |b| {
b.iter(|| parse(black_box(simpleicons_data)))
});

let elsevier_data = include_bytes!("../fuzz/corpus/elsevier.txt");
c.bench_function("elsevier", |b| b.iter(|| parse(black_box(elsevier_data))));
}

criterion_group!(benches, performance);
criterion_main!(benches);
1 change: 1 addition & 0 deletions fuzz/corpus/elsevier.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions fuzz/corpus/simpleicons.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
M12 0C8.688 0 6 2.688 6 6s2.688 6 6 6c4.64-.001 7.526 5.039 5.176 9.04h1.68A7.507 7.507 0 0 0 12 10.5 4.502 4.502 0 0 1 7.5 6c0-2.484 2.016-4.5 4.5-4.5s4.5 2.016 4.5 4.5H18c0-3.312-2.688-6-6-6Zm0 3a3 3 0 0 0 0 6c4 0 4-6 0-6Zm0 1.5A1.5 1.5 0 0 1 13.5 6v.002c-.002 1.336-1.617 2.003-2.561 1.058C9.995 6.115 10.664 4.5 12 4.5ZM7.5 15v1.5H9v6H4.5V24h15v-1.5H15v-6h1.5V15Zm3 1.5h3v6h-3zm-6 1.47c0 1.09.216 2.109.644 3.069h1.684A5.957 5.957 0 0 1 6 17.97Z
Loading

0 comments on commit 0817f28

Please sign in to comment.