Skip to content

Commit

Permalink
Derive Copy,Clone for BasicDecimal (#2495)
Browse files Browse the repository at this point in the history
* Derive Copy,Clone for BasicDecimal

* Clippy
  • Loading branch information
tustvold committed Aug 18, 2022
1 parent 4459a0e commit 97b4f65
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
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()))
});
}

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

0 comments on commit 97b4f65

Please sign in to comment.