diff --git a/Cargo.toml b/Cargo.toml index d95514e..d96a0c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,11 @@ winnow = "0.6.8" [dev-dependencies] serde_json = { version = "1.0.87" } +criterion = "0.3" + +[[bench]] +name = "parser_benchmark" +harness = false # docs.rs-specific configuration [package.metadata.docs.rs] diff --git a/README.md b/README.md index 2a37d03..48149f5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,12 @@ # parse string to std::time::Duration +======================================== +
+ +
[![Chrono GitHub Actions](https://github.com/baoyachi/duration-str-rs/actions/workflows/check.yml/badge.svg)](https://github.com/baoyachi/duration-str-rs/actions?query=workflow%3Abuild) [![Crates.io](https://img.shields.io/crates/v/duration-str.svg)](https://crates.io/crates/duration-str) diff --git a/benches/parser_benchmark.rs b/benches/parser_benchmark.rs new file mode 100644 index 0000000..77cfe03 --- /dev/null +++ b/benches/parser_benchmark.rs @@ -0,0 +1,36 @@ +use criterion::{criterion_group, criterion_main, Criterion}; +use std::time::Duration; +use winnow::ascii::{digit1, multispace0}; +use winnow::error::ContextError; +use winnow::token::literal; +use winnow::Parser; + +fn parse_duration() { + let duration = duration_str::parse("2h 37m").unwrap(); + assert_eq!(duration, Duration::new(9420, 0)) +} + +fn impeccable_duration() { + let input = "2h 37m"; + ( + digit1::<_, ContextError>.try_map(str::parse::