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

Adding benchmarks with Criterion #31

Draft
wants to merge 53 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
4f398d0
No Deps Working Example with i32
Laifsyn Mar 26, 2024
0cbbd32
Staging changes on branch for dev-ing
Laifsyn Mar 28, 2024
04bf0ec
Implement Tests for to_cardinal method
Laifsyn Mar 29, 2024
4a61d9d
Implement Tests for to_cardinal method
Laifsyn Mar 29, 2024
53472fa
ammending - eliminate prepended zeros from tests
Laifsyn Mar 29, 2024
3e236dd
Fix weird merging
Laifsyn Mar 29, 2024
02195d7
More unified test for cardinal conversion
Laifsyn Mar 29, 2024
a81b310
Add Veinti Flavor and setters for Spanish fields
Laifsyn Mar 29, 2024
d29babe
Refactoro with BigFloat
Laifsyn Mar 29, 2024
df765fd
Consume Vec of Triplets instead of reading it
Laifsyn Mar 29, 2024
e41e33e
Refactor out the Integer equivalent of to_cardinal()
Laifsyn Mar 29, 2024
fe3638c
Conversion for fractional number
Laifsyn Mar 30, 2024
496f7a2
Tweak comments and error checking
Laifsyn Apr 1, 2024
8de42c2
Staging: to_ordinal implementation
Laifsyn Apr 1, 2024
c547a3a
defaults to using "veinti..." flavor instead of "veinte y..."
Laifsyn Apr 2, 2024
8f51aa6
Stage Changes: to_ordinal progress
Laifsyn Apr 3, 2024
ff4e5a1
Complete ordinal implementation
Laifsyn Apr 3, 2024
57c722c
to_year implementation
Laifsyn Apr 3, 2024
3d9b15e
Expand tests
Laifsyn Apr 4, 2024
04d2e01
update container settings
Laifsyn Apr 4, 2024
5d0a21f
Currency Implementation
Laifsyn Apr 4, 2024
fad8ceb
Add Spanish implementation to lang::Language trait
Laifsyn Apr 6, 2024
66c56aa
try to ensure enum integrity safety
Laifsyn Apr 6, 2024
b11912e
add rustfmt_skip
Laifsyn Apr 7, 2024
a057344
derive basic traits for Lang enum
Laifsyn Apr 7, 2024
0c62c2c
Add more str parsing and invert bool logic
Laifsyn Apr 7, 2024
52024f4
add Integration Test for spanish
Laifsyn Apr 7, 2024
1fd7816
Update Docs format and info
Laifsyn Apr 7, 2024
6d5e505
add Spanish Docs and fix currency logic
Laifsyn Apr 7, 2024
d197359
run Rustfmt on most files and add derives
Laifsyn Apr 7, 2024
611a17a
testing DocTests
Laifsyn Apr 8, 2024
f86b6ae
Try to improve Integration Test
Laifsyn Apr 8, 2024
a3be350
Main became too much of a mess, so un-using it
Laifsyn Apr 8, 2024
63c599a
Remove devcontainers and rustfmt
Laifsyn Apr 11, 2024
25de996
attend clippy warning in test
Laifsyn Apr 11, 2024
26eef47
undo rustfmt on bin.rs
Laifsyn Apr 11, 2024
5af4b80
Undoing rustfmt on lang.rs
Laifsyn Apr 12, 2024
21d77de
undo missed a rustfmt on lang.rs
Laifsyn Apr 12, 2024
428adfd
undo rustfmt on lib.rs
Laifsyn Apr 12, 2024
0d7ee4c
try fix trailing whitespace
Laifsyn Apr 12, 2024
6299fa3
try fix EOF
Laifsyn Apr 12, 2024
88bb1ad
delete unused main.rs
Laifsyn Apr 12, 2024
7371a47
remove cfg attribute from num2words.rs
Laifsyn Apr 12, 2024
f6aeb2d
temporarily remove derives from enum Output in output.rs
Laifsyn Apr 12, 2024
d61def7
Undo added derives to currency.rs
Laifsyn Apr 12, 2024
c72b339
update README with new language
Laifsyn Apr 12, 2024
92f21c8
Update readme to reflect spanish as option
Laifsyn Apr 12, 2024
2a8d28a
temporarily remove derives
Laifsyn Apr 12, 2024
5b7b311
First Benchmarks result - Using vanilla For Loop
Laifsyn Apr 14, 2024
b163025
Sync Bench branch with latest Spanish Impl
Laifsyn Apr 17, 2024
233ccf7
Update code for benchmark
Laifsyn Apr 22, 2024
40429a0
updated criterion.toml
Laifsyn May 27, 2024
6f6b66f
Fix numerical representation
Laifsyn May 27, 2024
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
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,12 @@ path = "src/lib.rs"
name = "num2words"
path = "src/bin/bin.rs"

[[bench]]
name = "num2words"
harness = false

[dependencies]
num-bigfloat = { version = "^1.7.1", default-features = false }

[dev-dependencies]
criterion = "0.5.1"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Here is a list of all of the supported languages:
| 🇫🇷🇨🇦 | `Lang::French` | `fr` | French | quarante-deux |
| 🇧🇪🇨🇩 | `Lang::French_BE` | `fr_BE` | French (BE) | quarante-deux |
| 🇨🇭 | `Lang::French_CH` | `fr_CH` | French (CH) | quarante-deux |
| 🇪🇸 | `Lang::Spanish` | `es` | Spanish | cuarenta y dos|
| 🇺🇦 | `Lang::Ukrainian` | `uk` | Ukrainian | сорок два |

This list can be expanded! Contributions are welcomed.
Expand Down
91 changes: 91 additions & 0 deletions benches/num2words.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
use std::time::Duration;

use criterion::measurement::WallTime;
use criterion::{
black_box, criterion_group, criterion_main, BenchmarkGroup, BenchmarkId, Criterion,
};
use num2words::{Currency, Num2Words};
use num_bigfloat::BigFloat;
// Criterion's quick start guide https://bheisler.github.io/criterion.rs/book/getting_started.html
fn group_with_config(bench_group: &mut BenchmarkGroup<'_, WallTime>) {
bench_group.measurement_time(Duration::from_secs(20));
bench_group.sample_size(1000);
bench_group.confidence_level(0.99);
bench_group.warm_up_time(Duration::from_secs(5));
}
pub fn criterion_benchmark(c: &mut Criterion) {
let nonillion = BigFloat::from(121_121_121_121_121_121_121_121_121_121_121u128);
let quadrillions = BigFloat::from(121_121_121_121_121_121u64);
let trillions = BigFloat::from(121_121_121_121_121u64);
let billions = BigFloat::from(121_121_121_121u64);
let millions = BigFloat::from(121_121_121);
let thousands = BigFloat::from(121_121);
let hundreds = BigFloat::from(121);
// from lowest to biggest
let numbers = [hundreds, thousands, millions, billions, trillions, quadrillions, nonillion];
let numbers_name =
["hundreds", "thousands", "millions", "billions", "trillions", "quadrillions", "nonillion"];
use num2words::Lang::*;
let numbers_and_name = numbers.iter().zip(numbers_name.iter()).collect::<Vec<_>>();
let languages = [
// (Spanish, "ES"),
(English, "EN"),
(French, "FR"),
(French_BE, "FR_BE"),
(French_CH, "FR_CH"),
(Ukrainian, "UK"),
];
let mut group = c.benchmark_group("Num2Words to_cardinal()");
group_with_config(&mut group);

for row_data in languages.iter().copied() {
let (lang, language) = row_data;
for (num, number) in numbers_and_name.iter() {
let id = BenchmarkId::new(language, number);
group.bench_with_input(id, *num, |b, num| {
b.iter(|| {
let driver = Num2Words::new(*num).lang(lang);
black_box(driver.cardinal().to_words().unwrap());
})
});
}
}
group.finish();

// let mut group = c.benchmark_group("Num2Words to_ordinal()");
// group_with_config(&mut group);

// for row_data in languages.iter().copied() {
// let (lang, language) = row_data;
// for (num, number) in numbers_and_name.iter() {
// let id = BenchmarkId::new(language, number);
// group.bench_with_input(id, *num, |b, num| {
// b.iter(|| {
// let driver = Num2Words::new(*num).lang(lang);
// black_box(driver.ordinal().to_words().unwrap());
// })
// });
// }
// }
// group.finish();

// // to currency
// let mut group = c.benchmark_group("Num2Words to_currency(Currency::USD)");
// group_with_config(&mut group);

// for row_data in languages.iter().copied() {
// let (lang, language) = row_data;
// for (num, number) in numbers_and_name.iter() {
// let id = BenchmarkId::new(language, number);
// group.bench_with_input(id, *num, |b, num| {
// b.iter(|| {
// let driver = Num2Words::new(*num).lang(lang);
// black_box(driver.currency(Currency::USD).to_words().unwrap());
// })
// });
// }
// }
// group.finish();
}
criterion_group!(benches, criterion_benchmark,);
criterion_main!(benches);
30 changes: 30 additions & 0 deletions benches/test results.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//8GB RAM 2-cores Codespace
English time: [159.08 µs 161.34 µs 163.93 µs]
Found 14 outliers among 100 measurements (14.00%)
4 (4.00%) high mild
10 (10.00%) high severe

French time: [157.37 µs 159.43 µs 161.73 µs]
Found 18 outliers among 100 measurements (18.00%)
6 (6.00%) high mild
12 (12.00%) high severe

French_BE time: [157.24 µs 159.91 µs 163.33 µs]
Found 16 outliers among 100 measurements (16.00%)
3 (3.00%) high mild
13 (13.00%) high severe

French_CH time: [157.60 µs 159.73 µs 162.13 µs]
Found 18 outliers among 100 measurements (18.00%)
11 (11.00%) high mild
7 (7.00%) high severe

Spanish time: [17.792 µs 18.141 µs 18.551 µs]
Found 15 outliers among 100 measurements (15.00%)
2 (2.00%) high mild
13 (13.00%) high severe

Ukrainian time: [158.49 µs 160.56 µs 162.99 µs]
Found 19 outliers among 100 measurements (19.00%)
6 (6.00%) high mild
13 (13.00%) high severe
59 changes: 59 additions & 0 deletions criterion.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Fast getting started guide:
# https://bheisler.github.io/criterion.rs/book/getting_started.html
#
# Following this guide: https://crates.io/crates/criterion-table/0.2.2
# Installing the following binaries:
# cargo install cargo-criterion
# cargo install criterion-table
# run the following pipings for specific benchmarks
# cargo criterion --bench num2words --message-format=json > num2word_bench.json
# cat num2word_bench.json | criterion-table > BENCHMARKS.md
# Alternatively to do all at once
# cargo criterion --message-format=json | criterion-table > BENCHMARKS.md
#
#
# This is used to override the directory where cargo-criterion saves
# its data and generates reports.
criterion_home = "./target/criterion"

# This is used to configure the format of cargo-criterion's command-line output.
# Options are:
# criterion: Prints confidence intervals for measurement and throughput, and
# indicates whether a change was detected from the previous run. The default.
# quiet: Like criterion, but does not indicate changes. Useful for simply
# presenting output numbers, eg. on a library's README.
# verbose: Like criterion, but prints additional statistics.
# bencher: Emulates the output format of the bencher crate and nightly-only
# libtest benchmarks.
output_format = "criterion"

# This is used to configure the plotting backend used by cargo-criterion.
# Options are "gnuplot" and "plotters", or "auto", which will use gnuplot if it's
# available or plotters if it isn't.
ploting_backend = "auto"

# The colors table allows users to configure the colors used by the charts
# cargo-criterion generates.
[colors]
# These are used in many charts to compare the current measurement against
# the previous one.
current_sample = {r = 31, g = 120, b = 180}
previous_sample = {r = 7, g = 26, b = 28}

# These are used by the full PDF chart to highlight which samples were outliers.
not_an_outlier = {r = 31, g = 120, b = 180}
mild_outlier = {r = 5, g = 127, b = 0}
severe_outlier = {r = 7, g = 26, b = 28}

# These are used for the line chart to compare multiple different functions.
comparison_colors = [
{r = 8, g = 34, b = 34},
{r = 6, g = 139, b = 87},
{r = 0, g = 139, b = 139},
{r = 5, g = 215, b = 0},
{r = 0, g = 0, b = 139},
{r = 0, g = 20, b = 60},
{r = 9, g = 0, b = 139},
{r = 0, g = 255, b = 127},
]

1 change: 1 addition & 0 deletions src/bin/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ AVAILABLE LANGUAGES:
fr: French (France and Canada)
fr_BE: French (Belgium and the Democratic Republic of the Congo)
fr_CH: French (Swiss Confederation and Aosta Valley)
es: Spanish
uk: Ukrainian

AVAILABLE OUTPUTS:
Expand Down
Loading