Skip to content

Commit

Permalink
benches: Add a few more value decode benches
Browse files Browse the repository at this point in the history
  • Loading branch information
dhedey committed Aug 8, 2024
1 parent 9141df7 commit eb251fb
Showing 1 changed file with 76 additions and 17 deletions.
93 changes: 76 additions & 17 deletions radix-engine-tests/benches/costing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ use sbor::rust::iter;
use scrypto_test::prelude::LedgerSimulatorBuilder;
use wabt::wat2wasm;

fn generate_interesting_bytes_of_length(length: usize) -> Vec<u8> {
include_workspace_asset_bytes!("radix-transaction-scenarios", "radiswap.rpd")
.iter()
.cycle()
.take(length)
.cloned()
.collect()
}

fn bench_decode_rpd_to_manifest_value(c: &mut Criterion) {
let payload = include_workspace_asset_bytes!("radix-transaction-scenarios", "radiswap.rpd");
println!("Payload size: {}", payload.len());
Expand All @@ -39,30 +48,76 @@ fn bench_decode_rpd_to_manifest_raw_value(c: &mut Criterion) {
});
}

fn bench_decode_bytes_to_manifest_value(c: &mut Criterion) {
let payload = manifest_encode(include_workspace_asset_bytes!(
"radix-transaction-scenarios",
"radiswap.rpd"
))
.unwrap();
fn bench_decode_encoded_u8_array_to_manifest_value(c: &mut Criterion) {
let example_bytes = generate_interesting_bytes_of_length(1000000);
let payload = manifest_encode(&example_bytes).unwrap();
println!("Payload size: {}", payload.len());
c.bench_function("costing::decode_bytes_to_manifest_value", |b| {
c.bench_function("costing::decode_encoded_u8_array_to_manifest_value", |b| {
b.iter(|| manifest_decode::<ManifestValue>(&payload))
});
}

fn bench_decode_bytes_to_manifest_raw_value(c: &mut Criterion) {
let payload = manifest_encode(include_workspace_asset_bytes!(
"radix-transaction-scenarios",
"radiswap.rpd"
))
.unwrap();
fn bench_decode_encoded_u8_array_to_manifest_raw_value(c: &mut Criterion) {
let example_bytes = generate_interesting_bytes_of_length(1000000);
let payload = manifest_encode(&example_bytes).unwrap();
println!("Payload size: {}", payload.len());
c.bench_function(
"costing::decode_encoded_u8_array_to_manifest_raw_value",
|b| b.iter(|| manifest_decode::<ManifestRawValue>(&payload)),
);
}

fn bench_decode_encoded_i8_array_to_manifest_value(c: &mut Criterion) {
let example_i8_array = generate_interesting_bytes_of_length(1000000)
.into_iter()
.map(|b| i8::from_be_bytes([b]))
.collect::<Vec<_>>();
let payload = manifest_encode(&example_i8_array).unwrap();
println!("Payload size: {}", payload.len());
c.bench_function("costing::decode_bytes_to_manifest_raw_value", |b| {
b.iter(|| manifest_decode::<ManifestRawValue>(&payload))
c.bench_function("costing::decode_encoded_i8_array_to_manifest_value", |b| {
b.iter(|| manifest_decode::<ManifestValue>(&payload))
});
}

fn bench_decode_encoded_i8_array_to_manifest_raw_value(c: &mut Criterion) {
let example_i8_array = generate_interesting_bytes_of_length(1000000)
.into_iter()
.map(|b| i8::from_be_bytes([b]))
.collect::<Vec<_>>();
let payload = manifest_encode(&example_i8_array).unwrap();
println!("Payload size: {}", payload.len());
c.bench_function(
"costing::decode_encoded_i8_array_to_manifest_raw_value",
|b| b.iter(|| manifest_decode::<ManifestRawValue>(&payload)),
);
}

fn bench_decode_encoded_tuple_array_to_manifest_value(c: &mut Criterion) {
let value = generate_interesting_bytes_of_length(1000000)
.into_iter()
.map(|b| (b,))
.collect::<Vec<_>>();
let payload = manifest_encode(&value).unwrap();
println!("Payload size: {}", payload.len());
c.bench_function(
"costing::decode_encoded_tuple_array_to_manifest_value",
|b| b.iter(|| manifest_decode::<ManifestValue>(&payload)),
);
}

fn bench_decode_encoded_tuple_array_to_manifest_raw_value(c: &mut Criterion) {
let value = generate_interesting_bytes_of_length(1000000)
.into_iter()
.map(|b| (b,))
.collect::<Vec<_>>();
let payload = manifest_encode(&value).unwrap();
println!("Payload size: {}", payload.len());
c.bench_function(
"costing::decode_encoded_tuple_array_to_manifest_raw_value",
|b| b.iter(|| manifest_decode::<ManifestRawValue>(&payload)),
);
}

fn bench_validate_sbor_payload(c: &mut Criterion) {
let package_definition = manifest_decode::<PackageDefinition>(include_workspace_asset_bytes!(
"radix-transaction-scenarios",
Expand Down Expand Up @@ -328,8 +383,12 @@ criterion_group!(
costing,
bench_decode_rpd_to_manifest_value,
bench_decode_rpd_to_manifest_raw_value,
bench_decode_bytes_to_manifest_value,
bench_decode_bytes_to_manifest_raw_value,
bench_decode_encoded_u8_array_to_manifest_value,
bench_decode_encoded_u8_array_to_manifest_raw_value,
bench_decode_encoded_i8_array_to_manifest_value,
bench_decode_encoded_i8_array_to_manifest_raw_value,
bench_decode_encoded_tuple_array_to_manifest_value,
bench_decode_encoded_tuple_array_to_manifest_raw_value,
bench_validate_sbor_payload,
bench_validate_sbor_payload_bytes,
bench_validate_secp256k1,
Expand Down

0 comments on commit eb251fb

Please sign in to comment.