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

Derive Copy,Clone for BasicDecimal #2495

Merged
merged 3 commits into from Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 15 additions & 13 deletions arrow/benches/array_from_vec.rs
Expand Up @@ -87,20 +87,11 @@ fn decimal128_array_from_vec(array: &[Option<i128>]) {
);
}

fn decimal256_array_from_vec() {
// bench decimal256array
// create option<into<decimal256>> array
let size = 1 << 10;
let mut array = vec![];
let mut rng = rand::thread_rng();
for _ in 0..size {
let decimal =
Decimal256::from(BigInt::from(rng.gen_range::<i128, _>(0..9999999999999)));
array.push(Some(decimal));
}
fn decimal256_array_from_vec(array: &[Option<Decimal256>]) {
criterion::black_box(
array
.into_iter()
.iter()
.copied()
.collect::<Decimal256Array>()
.with_precision_and_scale(70, 2)
.unwrap(),
Expand All @@ -120,9 +111,20 @@ fn decimal_benchmark(c: &mut Criterion) {
b.iter(|| decimal128_array_from_vec(array.as_slice()))
});

// bench decimal256array
// create option<into<decimal256>> array
let size = 1 << 10;
let mut array = vec![];
let mut rng = rand::thread_rng();
for _ in 0..size {
let decimal =
Decimal256::from(BigInt::from(rng.gen_range::<i128, _>(0..9999999999999)));
array.push(Some(decimal));
}

// bench decimal256 array
c.bench_function("decimal256_array_from_vec 32768", |b| {
b.iter(|| decimal256_array_from_vec)
b.iter(|| decimal256_array_from_vec(array.as_slice()))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now more realistic as it is no longer benchmarking the decimal assembly code

});
}

Expand Down
4 changes: 2 additions & 2 deletions arrow/src/util/decimal.rs
Expand Up @@ -26,7 +26,7 @@ use num::bigint::BigInt;
use num::Signed;
use std::cmp::{min, Ordering};

#[derive(Debug)]
#[derive(Debug, Clone, Copy)]
pub struct BasicDecimal<const BYTE_WIDTH: usize> {
precision: usize,
scale: usize,
Expand Down Expand Up @@ -247,7 +247,7 @@ impl Decimal256 {
}

/// Constructs a `BigInt` from this `Decimal256` value.
pub(crate) fn to_big_int(&self) -> BigInt {
pub(crate) fn to_big_int(self) -> BigInt {
BigInt::from_signed_bytes_le(&self.value)
}
}
Expand Down