diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml index f68928b7e2..bc4e5d7bfc 100644 --- a/.github/workflows/bench.yml +++ b/.github/workflows/bench.yml @@ -32,3 +32,25 @@ jobs: alert-threshold: "130%" comment-on-alert: true alert-comment-cc-users: "@kariy,@glihm,@tarrencev" + + bench-sozo: + runs-on: ubuntu-latest + container: + image: ghcr.io/dojoengine/dojo-dev:v1.0.0-alpha.11 + steps: + - uses: actions/checkout@v3 + - run: git config --global --add safe.directory "$GITHUB_WORKSPACE" + - name: Running Katana benchmarks + run: cargo bench --bench spawn-and-move-build -- --output-format bencher | sed 1d | tail -n 1 | tee output_sozo.txt + - uses: benchmark-action/github-action-benchmark@v1 + with: + tool: "cargo" + output-file-path: output_sozo.txt + benchmark-data-dir-path: "." + # Access token to deploy GitHub Pages branch + github-token: ${{ secrets.GITHUB_TOKEN }} + # Push and deploy GitHub pages branch automatically + auto-push: true + alert-threshold: "130%" + comment-on-alert: true + alert-comment-cc-users: "@kariy,@glihm,@tarrencev" diff --git a/bin/sozo/Cargo.toml b/bin/sozo/Cargo.toml index 53fe96d40e..197fad4417 100644 --- a/bin/sozo/Cargo.toml +++ b/bin/sozo/Cargo.toml @@ -75,3 +75,7 @@ default = [ "controller", "walnut" ] controller = [ "dep:account_sdk", "dep:reqwest", "dep:slot" ] walnut = [ "dep:sozo-walnut", "sozo-ops/walnut" ] + +[[bench]] +harness = false +name = "spawn-and-move-build" diff --git a/bin/sozo/benches/spawn-and-move-build.rs b/bin/sozo/benches/spawn-and-move-build.rs new file mode 100644 index 0000000000..59f0b2b298 --- /dev/null +++ b/bin/sozo/benches/spawn-and-move-build.rs @@ -0,0 +1,46 @@ +use std::time::Instant; + +use dojo_lang::scarb_internal::compile_workspace; +use dojo_test_utils::compiler::CompilerTestSetup; +use scarb::compiler::Profile; +use scarb::core::TargetKind; +use scarb::ops::{CompileOpts, FeaturesOpts, FeaturesSelector}; + +// Criterion enforces at least 10 iterations, in the case of Sozo, we only need to compile the code +// once to have a baseline and compiling 10 times would have been too long for the CI. +// We also output the result in the `bencher` format which is the same as the one used in the +// `bench.yml` action. + +fn build_spawn_and_move() { + let setup = CompilerTestSetup::from_examples("../../crates/dojo-core", "../../examples/"); + + let config = setup.build_test_config("spawn-and-move", Profile::DEV); + + let ws = scarb::ops::read_workspace(config.manifest_path(), &config) + .expect("Failed to read workspace"); + + let packages: Vec<_> = ws.members().collect(); + + let _compile_info = compile_workspace( + &config, + CompileOpts { + include_target_names: vec![], + include_target_kinds: vec![], + exclude_target_kinds: vec![TargetKind::TEST], + features: FeaturesOpts { + features: FeaturesSelector::AllFeatures, + no_default_features: false, + }, + }, + packages.iter().map(|p| p.id).collect(), + ) + .expect("Failed to build spawn and move"); +} + +fn main() { + let start = Instant::now(); + build_spawn_and_move(); + let duration = start.elapsed(); + + println!("test build/Sozo.Cold ... bench: {} ns/iter (+/- 0)", duration.as_nanos()); +} diff --git a/bin/sozo/sozo_build_benchmark.txt b/bin/sozo/sozo_build_benchmark.txt new file mode 100644 index 0000000000..276be04dad --- /dev/null +++ b/bin/sozo/sozo_build_benchmark.txt @@ -0,0 +1 @@ +26102