This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Elide bounds checks in (fixedsize)list-iter
Also adds a slice unchecked and dispatches slice method to the unchecked. This also reduces a double assert to a single assert in safe code. As the bounds were checked at the array buffer and at the validity.
- Loading branch information
Showing
18 changed files
with
330 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,3 +230,7 @@ harness = false | |
[[bench]] | ||
name = "iter_utf8" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "iter_list" | ||
harness = false |
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,54 @@ | ||
use arrow2::{ | ||
array::{ListArray, PrimitiveArray}, | ||
buffer::Buffer, | ||
datatypes::DataType, | ||
}; | ||
|
||
use arrow2::bitmap::Bitmap; | ||
use arrow2::buffer::MutableBuffer; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use std::iter::FromIterator; | ||
use std::sync::Arc; | ||
|
||
fn add_benchmark(c: &mut Criterion) { | ||
(10..=20).step_by(2).for_each(|log2_size| { | ||
let size = 2usize.pow(log2_size); | ||
|
||
let values = Buffer::from_iter(0..size as i32); | ||
let values = PrimitiveArray::<i32>::from_data(DataType::Int32, values, None); | ||
|
||
let mut offsets = MutableBuffer::from_iter((0..size as i32).step_by(2)); | ||
offsets.push(size as i32); | ||
|
||
let validity = (0..(offsets.len() - 1)) | ||
.map(|i| i % 4 == 0) | ||
.collect::<Bitmap>(); | ||
|
||
let data_type = ListArray::<i32>::default_datatype(DataType::Int32); | ||
let array = ListArray::<i32>::from_data( | ||
data_type, | ||
offsets.into(), | ||
Arc::new(values), | ||
Some(validity), | ||
); | ||
|
||
c.bench_function(&format!("list: iter_values 2^{}", log2_size), |b| { | ||
b.iter(|| { | ||
for x in array.values_iter() { | ||
assert_eq!(x.len(), 2); | ||
} | ||
}) | ||
}); | ||
|
||
c.bench_function(&format!("list: iter 2^{}", log2_size), |b| { | ||
b.iter(|| { | ||
for x in array.iter() { | ||
assert_eq!(x.unwrap().len(), 2); | ||
} | ||
}) | ||
}); | ||
}) | ||
} | ||
|
||
criterion_group!(benches, add_benchmark); | ||
criterion_main!(benches); |
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
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
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
Oops, something went wrong.