-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
193da3a
commit ef44355
Showing
7 changed files
with
85 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use const_decimal::{Decimal, ScaledInteger}; | ||
use criterion::measurement::WallTime; | ||
use criterion::{black_box, BatchSize, BenchmarkGroup}; | ||
use num_traits::PrimInt; | ||
use prop::strategy::ValueTree; | ||
use prop::test_runner::TestRunner; | ||
use proptest::prelude::*; | ||
|
||
pub fn bench_all<const D: u8, I>(group: &mut BenchmarkGroup<'_, WallTime>) | ||
where | ||
I: ScaledInteger<D> + Arbitrary, | ||
{ | ||
bench_primitive_to_f64::<I>(group); | ||
bench_decimal_to_f64::<D, I>(group); | ||
} | ||
|
||
fn bench_primitive_to_f64<I>(group: &mut BenchmarkGroup<'_, WallTime>) | ||
where | ||
I: PrimInt + Arbitrary, | ||
{ | ||
// Use proptest to generate arbitrary input values. | ||
let mut runner = TestRunner::deterministic(); | ||
let input = (I::arbitrary(), I::arbitrary()); | ||
|
||
group.bench_function("primitive/to_f64", |bencher| { | ||
bencher.iter_batched( | ||
|| input.new_tree(&mut runner).unwrap().current(), | ||
|(a, b)| black_box(black_box(a) + black_box(b)), | ||
BatchSize::SmallInput, | ||
) | ||
}); | ||
} | ||
|
||
fn bench_decimal_to_f64<const D: u8, I>(group: &mut BenchmarkGroup<'_, WallTime>) | ||
where | ||
I: ScaledInteger<D> + Arbitrary, | ||
{ | ||
// Use proptest to generate arbitrary input values. | ||
let mut runner = TestRunner::deterministic(); | ||
let input = I::arbitrary().prop_map(|a| Decimal::<_, D>(a)); | ||
|
||
group.bench_function("decimal/to_f64", |bencher| { | ||
bencher.iter_batched( | ||
|| input.new_tree(&mut runner).unwrap().current(), | ||
|a| black_box(a.to_f64()), | ||
BatchSize::SmallInput, | ||
) | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters