Skip to content

Commit 1ef22e5

Browse files
authored
like benchmark for StringView (#5936)
1 parent e5604aa commit 1ef22e5

File tree

1 file changed

+41
-14
lines changed

1 file changed

+41
-14
lines changed

arrow/benches/comparison_kernels.rs

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ use rand::Rng;
3333

3434
const SIZE: usize = 65536;
3535

36+
fn bench_like_utf8view_scalar(arr_a: &StringViewArray, value_b: &str) {
37+
like(arr_a, &StringViewArray::new_scalar(value_b)).unwrap();
38+
}
39+
3640
fn bench_like_utf8_scalar(arr_a: &StringArray, value_b: &str) {
3741
like(arr_a, &StringArray::new_scalar(value_b)).unwrap();
3842
}
@@ -77,6 +81,8 @@ fn add_benchmark(c: &mut Criterion) {
7781

7882
let scalar = Float32Array::from(vec![1.0]);
7983

84+
// eq benchmarks
85+
8086
c.bench_function("eq Float32", |b| b.iter(|| eq(&arr_a, &arr_b)));
8187
c.bench_function("eq scalar Float32", |b| {
8288
b.iter(|| eq(&arr_a, &Scalar::new(&scalar)).unwrap())
@@ -161,14 +167,9 @@ fn add_benchmark(c: &mut Criterion) {
161167
let string_right = StringArray::from_iter(array_gen);
162168
let string_view_right = StringViewArray::from_iter(string_right.iter());
163169

170+
let scalar = StringArray::new_scalar("xxxx");
164171
c.bench_function("eq scalar StringArray", |b| {
165-
b.iter(|| {
166-
eq(
167-
&Scalar::new(StringArray::from_iter_values(["xxxx"])),
168-
&string_left,
169-
)
170-
.unwrap()
171-
})
172+
b.iter(|| eq(&scalar, &string_left).unwrap())
172173
});
173174

174175
c.bench_function("lt scalar StringViewArray", |b| {
@@ -192,13 +193,7 @@ fn add_benchmark(c: &mut Criterion) {
192193
});
193194

194195
c.bench_function("eq scalar StringViewArray", |b| {
195-
b.iter(|| {
196-
eq(
197-
&Scalar::new(StringViewArray::from_iter_values(["xxxx"])),
198-
&string_view_left,
199-
)
200-
.unwrap()
201-
})
196+
b.iter(|| eq(&scalar, &string_view_left).unwrap())
202197
});
203198

204199
c.bench_function("eq StringArray StringArray", |b| {
@@ -209,6 +204,8 @@ fn add_benchmark(c: &mut Criterion) {
209204
b.iter(|| eq(&string_view_left, &string_view_right).unwrap())
210205
});
211206

207+
// StringArray: LIKE benchmarks
208+
212209
c.bench_function("like_utf8 scalar equals", |b| {
213210
b.iter(|| bench_like_utf8_scalar(&arr_string, "xxxx"))
214211
});
@@ -229,6 +226,30 @@ fn add_benchmark(c: &mut Criterion) {
229226
b.iter(|| bench_like_utf8_scalar(&arr_string, "%xx_xx%xxx"))
230227
});
231228

229+
// StringViewArray: LIKE benchmarks
230+
// Note: since like/nlike share the same implementation, we only benchmark one
231+
c.bench_function("like_utf8view scalar equals", |b| {
232+
b.iter(|| bench_like_utf8view_scalar(&string_view_left, "xxxx"))
233+
});
234+
235+
c.bench_function("like_utf8view scalar contains", |b| {
236+
b.iter(|| bench_like_utf8view_scalar(&string_view_left, "%xxxx%"))
237+
});
238+
239+
c.bench_function("like_utf8view scalar ends with", |b| {
240+
b.iter(|| bench_like_utf8view_scalar(&string_view_left, "xxxx%"))
241+
});
242+
243+
c.bench_function("like_utf8view scalar starts with", |b| {
244+
b.iter(|| bench_like_utf8view_scalar(&string_view_left, "%xxxx"))
245+
});
246+
247+
c.bench_function("like_utf8view scalar complex", |b| {
248+
b.iter(|| bench_like_utf8view_scalar(&string_view_left, "%xx_xx%xxx"))
249+
});
250+
251+
// StringArray: NOT LIKE benchmarks
252+
232253
c.bench_function("nlike_utf8 scalar equals", |b| {
233254
b.iter(|| bench_nlike_utf8_scalar(&arr_string, "xxxx"))
234255
});
@@ -249,6 +270,8 @@ fn add_benchmark(c: &mut Criterion) {
249270
b.iter(|| bench_nlike_utf8_scalar(&arr_string, "%xx_xx%xxx"))
250271
});
251272

273+
// StringArray: ILIKE benchmarks
274+
252275
c.bench_function("ilike_utf8 scalar equals", |b| {
253276
b.iter(|| bench_ilike_utf8_scalar(&arr_string, "xxXX"))
254277
});
@@ -269,6 +292,8 @@ fn add_benchmark(c: &mut Criterion) {
269292
b.iter(|| bench_ilike_utf8_scalar(&arr_string, "%xx_xX%xXX"))
270293
});
271294

295+
// StringArray: NOT ILIKE benchmarks
296+
272297
c.bench_function("nilike_utf8 scalar equals", |b| {
273298
b.iter(|| bench_nilike_utf8_scalar(&arr_string, "xxXX"))
274299
});
@@ -297,6 +322,8 @@ fn add_benchmark(c: &mut Criterion) {
297322
b.iter(|| bench_regexp_is_match_utf8_scalar(&arr_string, "xx$"))
298323
});
299324

325+
// DictionaryArray benchmarks
326+
300327
let strings = create_string_array::<i32>(20, 0.);
301328
let dict_arr_a = create_dict_from_values::<Int32Type>(SIZE, 0., &strings);
302329
let scalar = StringArray::from(vec!["test"]);

0 commit comments

Comments
 (0)