mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-12-22 19:49:33 +00:00
add benches
This commit is contained in:
parent
a5ba54422f
commit
d2b30c1cbd
3 changed files with 72 additions and 31 deletions
|
@ -1,5 +1,10 @@
|
|||
//! This module contains benchmarks for any
|
||||
//! non-trivial/manual `epee` implementation.
|
||||
//!
|
||||
//! - non-trivial
|
||||
//! - manual
|
||||
//! - common
|
||||
//!
|
||||
//! type with a `epee` implementation.
|
||||
//!
|
||||
//! Types with the standard `epee` derive implementation are not included.
|
||||
|
||||
|
@ -11,29 +16,21 @@ use function_name::named;
|
|||
use cuprate_epee_encoding::{from_bytes, to_bytes};
|
||||
use cuprate_rpc_types::bin::{GetBlocksRequest, GetBlocksResponse};
|
||||
|
||||
criterion_group! {
|
||||
name = benches;
|
||||
config = Criterion::default();
|
||||
targets =
|
||||
epee_to_bytes_get_blocks_request,
|
||||
epee_from_bytes_get_blocks_request,
|
||||
epee_to_bytes_get_blocks_response,
|
||||
epee_from_bytes_get_blocks_response,
|
||||
}
|
||||
criterion_main!(benches);
|
||||
|
||||
/// TODO
|
||||
macro_rules! impl_epee_benchmark {
|
||||
/// Create [`to_bytes`] and [`from_bytes`] benchmarks for `epee` types.
|
||||
macro_rules! generate_epee_benchmarks {
|
||||
(
|
||||
$(
|
||||
$t:ty
|
||||
),* $(,)?
|
||||
) => { paste::paste! {
|
||||
// Generate the benchmarking functions.
|
||||
$(
|
||||
#[named]
|
||||
fn [<epee_from_bytes_ $t:snake>](c: &mut Criterion) {
|
||||
let bytes = to_bytes($t::default()).unwrap();
|
||||
|
||||
// `iter_batched()` is used so the `Default::default()`
|
||||
// is not part of the timings.
|
||||
c.bench_function(function_name!(), |b| {
|
||||
b.iter_batched(
|
||||
|| bytes.clone(),
|
||||
|
@ -56,10 +53,22 @@ macro_rules! impl_epee_benchmark {
|
|||
});
|
||||
}
|
||||
)*
|
||||
|
||||
// Enable all the benchmark functions created in this macro.
|
||||
criterion_group! {
|
||||
name = benches;
|
||||
config = Criterion::default();
|
||||
targets =
|
||||
$(
|
||||
[<epee_from_bytes_ $t:snake>],
|
||||
[<epee_to_bytes_ $t:snake>],
|
||||
)*
|
||||
}
|
||||
criterion_main!(benches);
|
||||
}};
|
||||
}
|
||||
|
||||
impl_epee_benchmark! {
|
||||
generate_epee_benchmarks! {
|
||||
GetBlocksRequest,
|
||||
GetBlocksResponse
|
||||
// GetBlocksResponse // TODO: fix epee impl
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
//! Benchmarks for `cuprate-json-rpc`.
|
||||
#![allow(unused_crate_dependencies)]
|
||||
|
||||
mod serde;
|
||||
mod epee;
|
||||
mod serde;
|
||||
|
||||
criterion::criterion_main! {
|
||||
epee::benches,
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
//! This module contains benchmarks for any
|
||||
//! non-trivial/manual `serde` implementation.
|
||||
//!
|
||||
//! - non-trivial
|
||||
//! - manual
|
||||
//! - common
|
||||
//!
|
||||
//! type with a `serde` implementation.
|
||||
//!
|
||||
//! Types with the standard `serde` derive implementation are not included.
|
||||
|
||||
|
@ -9,19 +14,21 @@ use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion
|
|||
use function_name::named;
|
||||
use serde_json::{from_str, to_string};
|
||||
|
||||
use cuprate_rpc_types::misc::TxEntry;
|
||||
use cuprate_rpc_types::{
|
||||
json::{
|
||||
CalcPowRequest, GetBlockHeadersRangeResponse, GetBlockResponse, GetBlockTemplateResponse,
|
||||
GetConnectionsResponse, GetInfoResponse, GetLastBlockHeaderResponse, SyncInfoResponse,
|
||||
},
|
||||
misc::TxEntry,
|
||||
};
|
||||
use cuprate_test_utils::rpc::data::json::{
|
||||
CALC_POW_REQUEST, GET_BLOCK_HEADERS_RANGE_RESPONSE, GET_BLOCK_RESPONSE,
|
||||
GET_BLOCK_TEMPLATE_RESPONSE, GET_CONNECTIONS_RESPONSE, GET_INFO_RESPONSE,
|
||||
GET_LAST_BLOCK_HEADER_RESPONSE, SYNC_INFO_RESPONSE,
|
||||
};
|
||||
|
||||
criterion_group! {
|
||||
name = benches;
|
||||
config = Criterion::default();
|
||||
targets =
|
||||
serde_from_str_tx_entry,
|
||||
serde_to_string_tx_entry,
|
||||
}
|
||||
criterion_main!(benches);
|
||||
|
||||
/// TODO
|
||||
macro_rules! impl_serde_benchmark {
|
||||
/// Generate [`from_str`] and [`to_string`] benchmarks for `serde` types.
|
||||
macro_rules! generate_serde_benchmarks {
|
||||
(
|
||||
$(
|
||||
// The type to test =>
|
||||
|
@ -29,6 +36,7 @@ macro_rules! impl_serde_benchmark {
|
|||
$t:ty => $t_example:expr
|
||||
),* $(,)?
|
||||
) => { paste::paste! {
|
||||
// Generate the benchmarking functions.
|
||||
$(
|
||||
#[named]
|
||||
fn [<serde_from_str_ $t:snake>](c: &mut Criterion) {
|
||||
|
@ -53,11 +61,35 @@ macro_rules! impl_serde_benchmark {
|
|||
);
|
||||
});
|
||||
}
|
||||
|
||||
)*
|
||||
|
||||
// Enable all the benchmark functions created in this macro.
|
||||
criterion_group! {
|
||||
name = benches;
|
||||
config = Criterion::default();
|
||||
targets =
|
||||
$(
|
||||
[<serde_from_str_ $t:snake>],
|
||||
[<serde_to_string_ $t:snake>],
|
||||
)*
|
||||
}
|
||||
criterion_main!(benches);
|
||||
}};
|
||||
}
|
||||
|
||||
impl_serde_benchmark! {
|
||||
generate_serde_benchmarks! {
|
||||
// Custom serde types.
|
||||
TxEntry => r#"{"as_hex":"","as_json":"","double_spend_seen":false,"prunable_as_hex":"","prunable_hash":"","pruned_as_hex":"","received_timestamp":0,"relayed":false,"tx_hash":"","in_pool":false}"#,
|
||||
// Distribution => "TODO: enable after type is finalized"
|
||||
|
||||
// Common types or heavy types (heap types, many fields, etc).
|
||||
GetLastBlockHeaderResponse => GET_LAST_BLOCK_HEADER_RESPONSE,
|
||||
CalcPowRequest => CALC_POW_REQUEST,
|
||||
SyncInfoResponse => SYNC_INFO_RESPONSE,
|
||||
GetInfoResponse => GET_INFO_RESPONSE,
|
||||
GetBlockResponse => GET_BLOCK_RESPONSE,
|
||||
GetConnectionsResponse => GET_CONNECTIONS_RESPONSE,
|
||||
GetBlockTemplateResponse => GET_BLOCK_TEMPLATE_RESPONSE,
|
||||
GetBlockHeadersRangeResponse => GET_BLOCK_HEADERS_RANGE_RESPONSE
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue