MCPcopy Create free account
hub / github.com/apache/arrow-rs / criterion_benchmark

Function criterion_benchmark

arrow-buffer/benches/mutable_buffer_repeat_slice.rs:25–73  ·  view source on GitHub ↗
(c: &mut Criterion)

Source from the content-addressed store, hash-verified

23use std::hint;
24
25fn criterion_benchmark(c: &mut Criterion) {
26 let mut group = c.benchmark_group("MutableBuffer repeat slice");
27 let mut rng = StdRng::seed_from_u64(42);
28
29 for slice_length in [3, 20, 100] {
30 let slice_to_repeat: Vec<u8> = hint::black_box(
31 (&mut rng)
32 .sample_iter(&Alphanumeric)
33 .take(slice_length)
34 .collect(),
35 );
36 let slice_to_repeat: &[u8] = slice_to_repeat.as_ref();
37
38 for repeat_count in [3, 64, 1024, 8192] {
39 let parameter_string = format!("slice_len={slice_length} n={repeat_count}");
40
41 group.bench_with_input(
42 BenchmarkId::new("repeat_slice_n_times", &parameter_string),
43 &(repeat_count),
44 |b, &repeat_count| {
45 b.iter(|| {
46 let mut mutable_buffer = arrow_buffer::MutableBuffer::with_capacity(0);
47
48 mutable_buffer.repeat_slice_n_times(slice_to_repeat, repeat_count);
49
50 Buffer::from(mutable_buffer)
51 })
52 },
53 );
54 group.bench_with_input(
55 BenchmarkId::new("extend_from_slice loop", &parameter_string),
56 &(repeat_count),
57 |b, &repeat_count| {
58 b.iter(|| {
59 let mut mutable_buffer = arrow_buffer::MutableBuffer::with_capacity(
60 size_of_val(slice_to_repeat) * repeat_count,
61 );
62
63 for _ in 0..repeat_count {
64 mutable_buffer.extend_from_slice(slice_to_repeat);
65 }
66
67 Buffer::from(mutable_buffer)
68 })
69 },
70 );
71 }
72 }
73}
74
75criterion_group!(benches, criterion_benchmark);
76criterion_main!(benches);

Callers

nothing calls this directly

Calls 6

collectMethod · 0.80
repeat_slice_n_timesMethod · 0.80
extend_from_sliceMethod · 0.80
takeMethod · 0.45
as_refMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected