1
0
Fork 0
mirror of https://codeberg.org/icewind/bitbuffer.git synced 2026-06-03 08:34:07 +02:00

add read_*_into methods

This commit is contained in:
Robin Appelman 2025-07-13 22:07:12 +02:00
commit 774d820aaf
4 changed files with 393 additions and 47 deletions

View file

@ -121,6 +121,26 @@ fn perf_string<E: Endianness>((offset, buffer): (usize, BitReadBuffer<E>)) {
}
}
#[library_benchmark(setup = build_string_buffer)]
#[bench::le_alligned(0, LittleEndian)]
#[bench::be_alligned(0, BigEndian)]
#[bench::le_unalligned(3, LittleEndian)]
#[bench::be_unalligned(3, BigEndian)]
fn perf_string_into<E: Endianness>((offset, buffer): (usize, BitReadBuffer<E>)) {
let mut pos = offset;
let len = buffer.bit_len();
let mut buff = String::new();
loop {
if pos + (128 * 8) > len {
break;
}
let result = buffer.read_string_into(pos, None, &mut buff).unwrap();
let result = result.as_ref(&buff);
pos += (result.len() + 1) * 8;
black_box(result);
}
}
#[library_benchmark(setup = build_string_buffer)]
#[bench::le_alligned(0, LittleEndian)]
#[bench::be_alligned(0, BigEndian)]
@ -139,6 +159,26 @@ fn perf_bytes<E: Endianness>((offset, buffer): (usize, BitReadBuffer<E>)) {
}
}
#[library_benchmark(setup = build_string_buffer)]
#[bench::le_alligned(0, LittleEndian)]
#[bench::be_alligned(0, BigEndian)]
#[bench::le_unalligned(3, LittleEndian)]
#[bench::be_unalligned(3, BigEndian)]
fn perf_bytes_into<E: Endianness>((offset, buffer): (usize, BitReadBuffer<E>)) {
let mut pos = offset;
let len = buffer.bit_len();
let mut buff = Vec::new();
loop {
if pos + (128 * 8) > len {
break;
}
let result = buffer.read_bytes_into(pos, 128, &mut buff).unwrap();
let result = result.as_ref(&buff);
pos += (result.len() + 1) * 8;
black_box(result);
}
}
#[allow(dead_code)]
#[derive(BitRead)]
struct BasicStruct {
@ -191,13 +231,13 @@ library_benchmark_group!(
library_benchmark_group!(
name = bench_read_string;
compare_by_id = true;
benchmarks = perf_string
benchmarks = perf_string, perf_string_into
);
library_benchmark_group!(
name = bench_read_bytes;
compare_by_id = true;
benchmarks = perf_bytes
benchmarks = perf_bytes, perf_bytes_into
);
library_benchmark_group!(