(c: &mut Criterion)
| 23 | use std::hint; |
| 24 | |
| 25 | fn 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", ¶meter_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", ¶meter_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 | |
| 75 | criterion_group!(benches, criterion_benchmark); |
| 76 | criterion_main!(benches); |
nothing calls this directly
no test coverage detected