Skip to content

Commit a3719ca

Browse files
seddonm1jorgecarleitao
authored andcommitted
ARROW-11651: [Rust][DataFusion] Implement Postgres String Functions: Length Functions
Splitting up apache/arrow#9243 This implements the following functions: - String functions - [x] bit_Length - [x] char_length - [x] character_length - [x] length - [x] octet_length Closes #9509 from seddonm1/length-functions Lead-authored-by: Mike Seddon <seddonm1@gmail.com> Co-authored-by: Jorge C. Leitao <jorgecarleitao@gmail.com> Signed-off-by: Andrew Lamb <andrew@nerdnetworks.org>
1 parent 12df8ad commit a3719ca

3 files changed

Lines changed: 274 additions & 44 deletions

File tree

rust/arrow/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ harness = false
114114
name = "length_kernel"
115115
harness = false
116116

117+
[[bench]]
118+
name = "bit_length_kernel"
119+
harness = false
120+
117121
[[bench]]
118122
name = "sort_kernel"
119123
harness = false
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
#[macro_use]
19+
extern crate criterion;
20+
use criterion::Criterion;
21+
22+
extern crate arrow;
23+
24+
use arrow::{array::*, compute::kernels::length::bit_length};
25+
26+
fn bench_bit_length(array: &StringArray) {
27+
criterion::black_box(bit_length(array).unwrap());
28+
}
29+
30+
fn add_benchmark(c: &mut Criterion) {
31+
fn double_vec<T: Clone>(v: Vec<T>) -> Vec<T> {
32+
[&v[..], &v[..]].concat()
33+
}
34+
35+
// double ["hello", " ", "world", "!"] 10 times
36+
let mut values = vec!["one", "on", "o", ""];
37+
for _ in 0..10 {
38+
values = double_vec(values);
39+
}
40+
let array = StringArray::from(values);
41+
42+
c.bench_function("bit_length", |b| b.iter(|| bench_bit_length(&array)));
43+
}
44+
45+
criterion_group!(benches, add_benchmark);
46+
criterion_main!(benches);

0 commit comments

Comments
 (0)