From 9f37923763a6a550c4295e112ac72c97131c7fda Mon Sep 17 00:00:00 2001 From: Fran Date: Tue, 27 Aug 2024 15:56:37 -0300 Subject: [PATCH 1/3] benchmarks: leverage zksync-home to get proper path --- core/tests/vm-benchmark/benches/criterion.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/tests/vm-benchmark/benches/criterion.rs b/core/tests/vm-benchmark/benches/criterion.rs index a02d6f308b33..c39a273ac235 100644 --- a/core/tests/vm-benchmark/benches/criterion.rs +++ b/core/tests/vm-benchmark/benches/criterion.rs @@ -7,19 +7,23 @@ 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::var("ZKSYNC_HOME"); +const BENCH_PATH: &str = format!( + "{}/core/tests/vm-benchmark/deployment_bechmarks", + ZKSYNC_HOME +); fn benches_in_folder(c: &mut Criterion) { let mut group = c.benchmark_group(VM::LABEL.as_str()); group .sample_size(SAMPLE_SIZE) .measurement_time(Duration::from_secs(10)); - for path in std::fs::read_dir("deployment_benchmarks").unwrap() { + for path in std::fs::read_dir(BENCH_PATH).unwrap() { let path = path.unwrap().path(); let test_contract = std::fs::read(&path).expect("failed to read file"); From 2a3b40504cd974e46e46b7c414188331bf802b62 Mon Sep 17 00:00:00 2001 From: Fran Date: Tue, 27 Aug 2024 16:30:28 -0300 Subject: [PATCH 2/3] fix: readd bench contracts --- .../fibonacci_rec.sol | 19 +++++++++++++++++++ .../deployment_benchmarks_sources/send.sol | 8 ++++++++ 2 files changed, 27 insertions(+) create mode 100644 core/tests/vm-benchmark/deployment_benchmarks_sources/fibonacci_rec.sol create mode 100644 core/tests/vm-benchmark/deployment_benchmarks_sources/send.sol diff --git a/core/tests/vm-benchmark/deployment_benchmarks_sources/fibonacci_rec.sol b/core/tests/vm-benchmark/deployment_benchmarks_sources/fibonacci_rec.sol new file mode 100644 index 000000000000..acdd27356bfc --- /dev/null +++ b/core/tests/vm-benchmark/deployment_benchmarks_sources/fibonacci_rec.sol @@ -0,0 +1,19 @@ +pragma solidity ^0.8.0; + +contract benchmark { + uint256 value; + constructor() { + value = fib(25); + } + + function get_calculation() public view returns (uint256) { + return value; + } + + function fib(uint256 n) internal returns (uint256) { + if (n <= 1) { + return n; + } + return fib(n - 1) + fib(n - 2); + } +} diff --git a/core/tests/vm-benchmark/deployment_benchmarks_sources/send.sol b/core/tests/vm-benchmark/deployment_benchmarks_sources/send.sol new file mode 100644 index 000000000000..f8463ab46e43 --- /dev/null +++ b/core/tests/vm-benchmark/deployment_benchmarks_sources/send.sol @@ -0,0 +1,8 @@ +pragma solidity >=0.8.20; + +contract Send { + constructor() { + address payable self = payable(msg.sender); + self.call{value: 100}; + } +} From b5a6843ec1bfd8e0a7c4914bad93410ae021abfd Mon Sep 17 00:00:00 2001 From: Fran Date: Wed, 28 Aug 2024 10:48:38 -0300 Subject: [PATCH 3/3] flamegraphs: properly build now --- core/tests/vm-benchmark/benches/criterion.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/core/tests/vm-benchmark/benches/criterion.rs b/core/tests/vm-benchmark/benches/criterion.rs index c39a273ac235..e20d26ebd77b 100644 --- a/core/tests/vm-benchmark/benches/criterion.rs +++ b/core/tests/vm-benchmark/benches/criterion.rs @@ -12,18 +12,20 @@ use zksync_vm_benchmark_harness::{ }; const SAMPLE_SIZE: usize = 20; -const ZKSYNC_HOME: &str = std::env::var("ZKSYNC_HOME"); -const BENCH_PATH: &str = format!( - "{}/core/tests/vm-benchmark/deployment_bechmarks", - ZKSYNC_HOME -); +const ZKSYNC_HOME: &str = std::env!("ZKSYNC_HOME"); + fn benches_in_folder(c: &mut Criterion) { let mut group = c.benchmark_group(VM::LABEL.as_str()); group .sample_size(SAMPLE_SIZE) .measurement_time(Duration::from_secs(10)); - for path in std::fs::read_dir(BENCH_PATH).unwrap() { + let bench_path = format!( + "{}/core/tests/vm-benchmark/deployment_benchmarks", + ZKSYNC_HOME + ); + + for path in std::fs::read_dir(bench_path).unwrap() { let path = path.unwrap().path(); let test_contract = std::fs::read(&path).expect("failed to read file");