#![allow(missing_docs, clippy::exit, reason = "benchmarks")]
use iai_callgrind::{library_benchmark, library_benchmark_group, main};
use std::hint::black_box;
use s2rst::s2::encoded_uint_vector::{
decode_uint_vector_u32, decode_uint_vector_u64, encode_uint_vector_u32, encode_uint_vector_u64,
};
#[library_benchmark]
fn encode_decode_u32_1024() -> Vec<u32> {
let values: Vec<u32> = (0..1024).map(|i| i * 0xa5a5).collect();
let mut buf = Vec::new();
encode_uint_vector_u32(&values, &mut buf).unwrap();
black_box(decode_uint_vector_u32(&mut buf.as_slice()).unwrap())
}
#[library_benchmark]
fn encode_decode_u64_1024() -> Vec<u64> {
let values: Vec<u64> = (0..1024).map(|i| i * 0xa5a5a5a5a5a5).collect();
let mut buf = Vec::new();
encode_uint_vector_u64(&values, &mut buf).unwrap();
black_box(decode_uint_vector_u64(&mut buf.as_slice()).unwrap())
}
#[library_benchmark]
fn encode_u32_1024() -> Vec<u8> {
let values: Vec<u32> = (0..1024).map(|i| i * 0xa5a5).collect();
let mut buf = Vec::with_capacity(4096);
encode_uint_vector_u32(&values, &mut buf).unwrap();
black_box(buf)
}
#[library_benchmark]
fn decode_u32_1024() -> Vec<u32> {
let values: Vec<u32> = (0..1024).map(|i| i * 0xa5a5).collect();
let mut buf = Vec::new();
encode_uint_vector_u32(&values, &mut buf).unwrap();
black_box(decode_uint_vector_u32(&mut buf.as_slice()).unwrap())
}
#[library_benchmark]
fn encode_decode_u32_65536() -> Vec<u32> {
let values: Vec<u32> = (0..65536).collect();
let mut buf = Vec::new();
encode_uint_vector_u32(&values, &mut buf).unwrap();
black_box(decode_uint_vector_u32(&mut buf.as_slice()).unwrap())
}
library_benchmark_group!(
name = encoded_uint_vector_benchmarks;
benchmarks =
encode_decode_u32_1024,
encode_decode_u64_1024,
encode_u32_1024,
decode_u32_1024,
encode_decode_u32_65536
);
main!(library_benchmark_groups = encoded_uint_vector_benchmarks);