mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Update iai benchmarks to use iai-callgrind (#7534)
This commit is contained in:
@ -1,38 +1,42 @@
|
||||
#![allow(missing_docs, non_snake_case, unreachable_pub)]
|
||||
|
||||
use iai_callgrind::{
|
||||
library_benchmark, library_benchmark_group, LibraryBenchmarkConfig, RegressionConfig,
|
||||
};
|
||||
use paste::paste;
|
||||
use reth_db::table::{Compress, Decode, Decompress, Encode, Table};
|
||||
|
||||
mod utils;
|
||||
use utils::*;
|
||||
|
||||
macro_rules! impl_iai_inner {
|
||||
macro_rules! impl_iai_callgrind_inner {
|
||||
(
|
||||
$(($name:ident, $mod:ident, $compress:ident, $decompress:ident, $encode:ident, $decode:ident, $seqread:ident, $randread:ident, $seqwrite:ident, $randwrite:ident))+
|
||||
$(($name:ident, $group_name:ident, $mod:ident, $compress:ident, $decompress:ident, $encode:ident, $decode:ident, $seqread:ident, $randread:ident, $seqwrite:ident, $randwrite:ident))+
|
||||
) => {
|
||||
use std::hint::black_box;
|
||||
$(
|
||||
mod $mod {
|
||||
use super::*;
|
||||
use std::hint::black_box;
|
||||
|
||||
#[library_benchmark]
|
||||
pub fn $compress() {
|
||||
for (_, _, v, _) in black_box(load_vectors::<reth_db::tables::$name>()) {
|
||||
black_box(v.compress());
|
||||
}
|
||||
}
|
||||
|
||||
#[library_benchmark]
|
||||
pub fn $decompress() {
|
||||
for (_, _, _, comp) in black_box(load_vectors::<reth_db::tables::$name>()) {
|
||||
let _ = black_box(<reth_db::tables::$name as Table>::Value::decompress(comp));
|
||||
}
|
||||
}
|
||||
|
||||
#[library_benchmark]
|
||||
pub fn $encode() {
|
||||
for (k, _, _, _) in black_box(load_vectors::<reth_db::tables::$name>()) {
|
||||
black_box(k.encode());
|
||||
}
|
||||
}
|
||||
|
||||
#[library_benchmark]
|
||||
pub fn $decode() {
|
||||
for (_, enc, _, _) in black_box(load_vectors::<reth_db::tables::$name>()) {
|
||||
let _ = black_box(<reth_db::tables::$name as Table>::Key::decode(enc));
|
||||
@ -50,34 +54,41 @@ macro_rules! impl_iai_inner {
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn $randwrite() {}
|
||||
}
|
||||
use $mod::*;
|
||||
|
||||
|
||||
library_benchmark_group!(
|
||||
name = $group_name;
|
||||
config = LibraryBenchmarkConfig::default()
|
||||
.regression(
|
||||
RegressionConfig::default().fail_fast(false)
|
||||
);
|
||||
benchmarks =
|
||||
$compress,
|
||||
$decompress,
|
||||
$encode,
|
||||
$decode,
|
||||
);
|
||||
)+
|
||||
|
||||
iai::main!(
|
||||
$(
|
||||
$compress,
|
||||
$decompress,
|
||||
$encode,
|
||||
$decode,
|
||||
)+
|
||||
);
|
||||
iai_callgrind::main!(
|
||||
config = LibraryBenchmarkConfig::default();
|
||||
library_benchmark_groups = $($group_name),+);
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! impl_iai {
|
||||
macro_rules! impl_iai_callgrind {
|
||||
($($name:ident),+) => {
|
||||
paste! {
|
||||
impl_iai_inner!(
|
||||
impl_iai_callgrind_inner!(
|
||||
$(
|
||||
( $name, [<$name _mod>], [<$name _ValueCompress>], [<$name _ValueDecompress>], [<$name _ValueEncode>], [<$name _ValueDecode>], [<$name _SeqRead>], [<$name _RandomRead>], [<$name _SeqWrite>], [<$name _RandomWrite>])
|
||||
( $name, [<$name _group>],[<$name _mod>], [<$name _ValueCompress>], [<$name _ValueDecompress>], [<$name _ValueEncode>], [<$name _ValueDecode>], [<$name _SeqRead>], [<$name _RandomRead>], [<$name _SeqWrite>], [<$name _RandomWrite>])
|
||||
)+
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl_iai!(
|
||||
impl_iai_callgrind!(
|
||||
CanonicalHeaders,
|
||||
HeaderTerminalDifficulties,
|
||||
HeaderNumbers,
|
||||
|
||||
Reference in New Issue
Block a user