This document provides instructions on how to set up and run benchmarks for the cairo-coverage project.
Before running benchmarks, ensure you have the following installed:
- Rust and Cargo: Follow the official Rust installation guide.
asdfversion manager: Follow the officialasdfinstallation guide.scarbplugin forasdf:asdf plugin add scarb
starknet-foundryplugin forasdf:asdf plugin add starknet-foundry
The benchmarks rely on trace data generated from specific Cairo projects. The download_bench_projects.sh script is
used to set up these projects and generate the necessary trace data.
-
Navigate to the
benchesdirectory:cd crates/cairo-coverage-core/benches -
Run the
download_bench_projects.shscript:./download_bench_projects.sh
This script contains the
create_tracesfunction, which is responsible for preparing a project for benchmarking. Thecreate_tracesfunction takes four arguments:<origin-link>: The Git URL of the repository containing the Cairo project.<commit-hash>: The specific commit hash of the repository to check out.<starknet-foundry-version>: Thestarknet-foundryversion to use for the project.<scarb-version>: Thescarbversion to use for the project.
For each call to
create_traces, the script will:- Initialize and fetch the specified Git repository.
- Check out the given commit.
- Create a
.tool-versionsfile within the cloned project directory to ensure consistentstarknet-foundryandscarbversions usingasdf. - Run
snforge test --save-trace-datato execute the project's tests and generate execution trace data. - Copy the generated trace data into a
project-tracesdirectory, which the benchmarks will then use.
Adding New Projects for Benchmarking: To add a new project to be benchmarked, you need to:
- Add a new call to the
create_tracesfunction indownload_bench_projects.sh. - Provide the
origin-link,commit-hash,starknet-foundry-version, andscarb-versionrelevant to your new project. - After running
download_bench_projects.sh, you will also need to add a corresponding benchmark function incrates/cairo-coverage-core/benches/benchmarks/(e.g.,my_new_project.rs) and register it incrates/cairo-coverage-core/benches/bench_main.rs.
Example of adding a new project: If you wanted to add a project from
https://github.com/example/my-cairo-project.gitat commitabcdef123456, usingstarknet-foundryversion0.55.0andscarbversion2.13.0, you would add the following line todownload_bench_projects.sh:create_traces "https://github.com/example/my-cairo-project.git" "abcdef123456" 0.55.0 2.13.0
Once the benchmark projects are set up and trace data is generated, you can run the benchmarks using Cargo.
Run the benchmarks using cargo bench:
cargo bench --workspace --bench bench_mainThis command will execute the benchmarks defined in crates/cairo-coverage-core/benches/bench_main.rs and its modules (
e.g., starknet_staking.rs).
Criterion will output the benchmark results to your console and also generate an HTML report which can be found in
target/criterion/report/index.html.