From f402e45a8cad002d41caf9802d3e80bc681164b3 Mon Sep 17 00:00:00 2001 From: Rostislav Raykov Date: Tue, 30 Jan 2024 18:54:03 +0100 Subject: [PATCH] test: add simple benchmarks using divan --- Cargo.toml | 5 +++++ benches/parse.rs | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 benches/parse.rs diff --git a/Cargo.toml b/Cargo.toml index b2a3ac3..6a09bef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ serde = { version = "1.0.127", optional = true, features = ["derive"] } strum = {version = "0.25.0", optional = true, features = ["derive"] } [dev-dependencies] +divan = "0.1.11" serde_json = "1.0.66" [build-dependencies] @@ -31,3 +32,7 @@ quote = "1.0.35" [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] + +[[bench]] +name = "parse" +harness = false diff --git a/benches/parse.rs b/benches/parse.rs new file mode 100644 index 0000000..a6f2c3b --- /dev/null +++ b/benches/parse.rs @@ -0,0 +1,21 @@ +use std::str::FromStr; + +fn main() { + // Run registered benchmarks. + divan::main(); +} + +#[divan::bench] +fn parse_code() { + iso_currency::Currency::from_code("EUR").unwrap(); +} + +#[divan::bench] +fn parse_numeric() { + iso_currency::Currency::from_numeric(978).unwrap(); +} + +#[divan::bench] +fn from_str() { + iso_currency::Currency::from_str("SEK").unwrap(); +}