This is an automated email from the ASF dual-hosted git repository. kszucs pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push: new e26806e ARROW-3664: [Rust] Add benchmark for PrimitiveArrayBuilder e26806e is described below commit e26806eeb4dcaa07b2f7dd7a7b3da2d0fdb42276 Author: Chao Sun <sunc...@apache.org> AuthorDate: Tue Nov 6 12:16:36 2018 +0100 ARROW-3664: [Rust] Add benchmark for PrimitiveArrayBuilder Author: Chao Sun <sunc...@apache.org> Author: Krisztián Szűcs <szucs.kriszt...@gmail.com> Closes #2903 from sunchao/ARROW-3664 and squashes the following commits: 0cdc0e1f <Krisztián Szűcs> fmt c9d94de7 <Chao Sun> ARROW-3664: Add benchmark for PrimitiveArrayBuilder --- ci/travis_script_rust.sh | 1 + rust/Cargo.toml | 4 +++ rust/benches/builder.rs | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) diff --git a/ci/travis_script_rust.sh b/ci/travis_script_rust.sh index 75a4b9a..1cd179f 100755 --- a/ci/travis_script_rust.sh +++ b/ci/travis_script_rust.sh @@ -35,6 +35,7 @@ cargo rustc -- -D warnings cargo build cargo test +cargo bench cargo run --example dynamic_types popd diff --git a/rust/Cargo.toml b/rust/Cargo.toml index b618ea9..c74e7a9 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -45,3 +45,7 @@ criterion = "0.2" [[bench]] name = "array_from_vec" harness = false + +[[bench]] +name = "builder" +harness = false diff --git a/rust/benches/builder.rs b/rust/benches/builder.rs new file mode 100644 index 0000000..4d09d94 --- /dev/null +++ b/rust/benches/builder.rs @@ -0,0 +1,73 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +extern crate arrow; +extern crate criterion; +extern crate rand; + +use arrow::builder::*; +use criterion::*; +use rand::distributions::Standard; +use rand::{thread_rng, Rng}; +use std::mem::size_of; + +// Build arrays with 512k elements. +const BATCH_SIZE: usize = 8 << 10; +const NUM_BATCHES: usize = 64; + +fn bench_primitive(c: &mut Criterion) { + let data: [i64; BATCH_SIZE] = [100; BATCH_SIZE]; + c.bench( + "bench_primitive", + Benchmark::new("bench_primitive", move |b| { + b.iter(|| { + let mut builder = PrimitiveArrayBuilder::<i64>::new(64); + for _ in 0..NUM_BATCHES { + black_box(builder.push_slice(&data[..])); + } + black_box(builder.finish()); + }) + }).throughput(Throughput::Bytes( + (data.len() * NUM_BATCHES * size_of::<i64>()) as u32, + )), + ); +} + +fn bench_bool(c: &mut Criterion) { + let data: Vec<bool> = thread_rng() + .sample_iter(&Standard) + .take(BATCH_SIZE) + .collect(); + let data_len = data.len(); + c.bench( + "bench_bool", + Benchmark::new("bench_bool", move |b| { + b.iter(|| { + let mut builder = PrimitiveArrayBuilder::<bool>::new(64); + for _ in 0..NUM_BATCHES { + black_box(builder.push_slice(&data[..])); + } + black_box(builder.finish()); + }) + }).throughput(Throughput::Bytes( + (data_len * NUM_BATCHES * size_of::<bool>()) as u32, + )), + ); +} + +criterion_group!(benches, bench_primitive, bench_bool); +criterion_main!(benches);