Skip to content

Commit

Permalink
bench: add sozo build bench for spawn and move
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm committed Sep 12, 2024
1 parent 80d1827 commit cbc4e15
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 4 additions & 0 deletions bin/sozo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
46 changes: 46 additions & 0 deletions bin/sozo/benches/spawn-and-move-build.rs
Original file line number Diff line number Diff line change
@@ -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());
}
1 change: 1 addition & 0 deletions bin/sozo/sozo_build_benchmark.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
26102

0 comments on commit cbc4e15

Please sign in to comment.