Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New setup for criterion #252

Draft
wants to merge 4 commits into
base: era_vm_integration_v2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/tests/vm-benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ zksync_vm_benchmark_harness.workspace = true
rand.workspace = true
vise.workspace = true
tokio.workspace = true
hex.workspace = true

[dev-dependencies]
criterion.workspace = true
Expand Down
108 changes: 82 additions & 26 deletions core/tests/vm-benchmark/benches/criterion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,101 @@ use criterion::{
use zksync_types::Transaction;
use zksync_vm_benchmark_harness::{
cut_to_allowed_bytecode_size, get_deploy_tx, get_heavy_load_test_tx, get_load_test_deploy_tx,
get_load_test_tx, get_realistic_load_test_tx, BenchmarkingVm, BenchmarkingVmFactory, Fast, Lambda,
Legacy, LoadTestParams,
get_load_test_tx, get_realistic_load_test_tx, BenchmarkingVm, BenchmarkingVmFactory, Fast,
Lambda, Legacy, LoadTestParams,
};

const SAMPLE_SIZE: usize = 20;
const ZKSYNC_HOME: &str = std::env!("ZKSYNC_HOME");

// fn benches_in_folder<VM: BenchmarkingVmFactory, const FULL: bool>(c: &mut Criterion) {
// let mut group = c.benchmark_group(VM::LABEL.as_str());
// group
// .sample_size(SAMPLE_SIZE)
// .measurement_time(Duration::from_secs(10));
//
// let benches = format!(
// "{}/core/tests/vm-benchmark/deployment_benchmarks",
// ZKSYNC_HOME
// );
//
// for path in std::fs::read_dir(&benches).unwrap() {
// let path = path.unwrap().path();
//
// let test_contract = std::fs::read(&path).expect("failed to read file");
//
// let code = cut_to_allowed_bytecode_size(&test_contract).unwrap();
// let tx = get_deploy_tx(code);
// let file_name = path.file_name().unwrap().to_str().unwrap();
// let full_suffix = if FULL { "/full" } else { "" };
// let bench_name = format!("{file_name}{full_suffix}");
// group.bench_function(bench_name, |bencher| {
// if FULL {
// // Include VM initialization / drop into the measured time
// bencher.iter(|| BenchmarkingVm::<VM>::default().run_transaction(black_box(&tx)));
// } else {
// bencher.iter_batched(
// BenchmarkingVm::<VM>::default,
// |mut vm| {
// let result = vm.run_transaction(black_box(&tx));
// (vm, result)
// },
// BatchSize::LargeInput, // VM can consume significant amount of RAM, especially the new one
// );
// }
// });
// }
// }
//
pub fn program_from_file(bin_path: &str) -> Vec<u8> {
let program = std::fs::read(bin_path).unwrap();
let encoded = String::from_utf8(program).unwrap();

if &encoded[..2] != "0x" {
panic!("Wrong hex");
}

let bin = hex::decode(&encoded[2..]).unwrap();

bin
}
// Simpler version
fn benches_in_folder<VM: BenchmarkingVmFactory, const FULL: bool>(c: &mut Criterion) {
let mut group = c.benchmark_group(VM::LABEL.as_str());

group
.sample_size(SAMPLE_SIZE)
.measurement_time(Duration::from_secs(10));
let send_bench_tag = "send";
let send_bench = format!(
"{}/core/tests/vm-benchmark/deployment_benchmarks/{}",
ZKSYNC_HOME, send_bench_tag
);

let benches = format!("{}/core/tests/vm-benchmark/deployment_benchmarks", ZKSYNC_HOME);

for path in std::fs::read_dir(&benches).unwrap() {
let path = path.unwrap().path();

let test_contract = std::fs::read(&path).expect("failed to read file");
let fibonacci_bench_tag = "fibonacci_rec";
let fibonacci_bench = format!(
"{}/core/tests/vm-benchmark/deployment_benchmarks/{}",
ZKSYNC_HOME, fibonacci_bench_tag
);

let code = cut_to_allowed_bytecode_size(&test_contract).unwrap();
let tx = get_deploy_tx(code);
let file_name = path.file_name().unwrap().to_str().unwrap();
let full_suffix = if FULL { "/full" } else { "" };
let bench_name = format!("{file_name}{full_suffix}");
let benches: Vec<(&str, String)> = vec![
(send_bench_tag, send_bench),
(fibonacci_bench_tag, fibonacci_bench),
];
for (bench_tag, bench_path) in benches {
let bench_name = format!("{bench_tag}/full");
// Only benchmark the tx execution itself
let code = program_from_file(&bench_path);
let tx = get_deploy_tx(&code[..]);
group.bench_function(bench_name, |bencher| {
if FULL {
// Include VM initialization / drop into the measured time
bencher.iter(|| BenchmarkingVm::<VM>::default().run_transaction(black_box(&tx)));
} else {
bencher.iter_batched(
BenchmarkingVm::<VM>::default,
|mut vm| {
let result = vm.run_transaction(black_box(&tx));
(vm, result)
},
BatchSize::LargeInput, // VM can consume significant amount of RAM, especially the new one
);
}
bencher.iter_batched(
BenchmarkingVm::<VM>::default,
|mut vm| {
let result = vm.run_transaction(black_box(&tx));
(vm, result)
},
BatchSize::LargeInput,
);
});
}
}
Expand Down
Loading