Skip to content

Commit

Permalink
add benches code
Browse files Browse the repository at this point in the history
  • Loading branch information
baoyachi committed Jun 5, 2024
1 parent 4a4d0d6 commit 94e2da3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "duration-str"
version = "0.11.0"
version = "0.11.1"
authors = ["baoyachi <[email protected]>"]
edition = "2021"
description = "duration string parser"
Expand Down
8 changes: 5 additions & 3 deletions benches/parser_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ fn parse_duration() {

fn impeccable_duration() {
let input = "2h 37m";
(
digit1::<_, ContextError>.try_map(str::parse::<usize>),
let duration = (
digit1::<_, ContextError>.try_map(str::parse::<u64>),
literal('h').value(3600),
multispace0,
digit1.try_map(str::parse::<usize>),
digit1.try_map(str::parse::<u64>),
literal('m').value(60),
)
.map(|(hour, h_unit, _, min, min_unit)| hour * h_unit + min * min_unit)
.map(|seconds| Duration::new(seconds, 0))
.parse(input)
.unwrap();
assert_eq!(duration, Duration::new(9420, 0))
}

pub fn duration_str_benchmark(c: &mut Criterion) {
Expand Down

0 comments on commit 94e2da3

Please sign in to comment.