Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
ielashi committed Jan 26, 2024
1 parent 4d82325 commit 4a13a74
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
30 changes: 26 additions & 4 deletions canbench-bin/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Benchmark: no_changes_test
---------------------------------------------------
Executed 1 of 4 benchmarks.
Executed 1 of 5 benchmarks.
"
);
});
Expand All @@ -61,7 +61,7 @@ Benchmark: noisy_change_test
---------------------------------------------------
Executed 1 of 4 benchmarks.
Executed 1 of 5 benchmarks.
"
);
});
Expand All @@ -84,7 +84,7 @@ Benchmark: regression_test
---------------------------------------------------
Executed 1 of 4 benchmarks.
Executed 1 of 5 benchmarks.
"
);
});
Expand All @@ -106,7 +106,29 @@ Benchmark: improvement_test
---------------------------------------------------
Executed 1 of 4 benchmarks.
Executed 1 of 5 benchmarks.
"
);
});
}

#[test]
fn benchmark_reports_regression_from_zero() {
BenchTest::canister("measurements_output")
.with_bench("stable_memory_increase")
.run(|output| {
assert_success!(
output,
"
---------------------------------------------------
Benchmark: stable_memory_increase
instructions: 404 (regressed from 0)
stable_memory_size: 123 (regressed from 0)
---------------------------------------------------
Executed 1 of 5 benchmarks.
"
);
});
Expand Down
5 changes: 5 additions & 0 deletions tests/measurements_output/canbench_results.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ improvement_test:
measurements:
instructions: 3040
stable_memory_size: 0

stable_memory_increase:
measurements:
instructions: 0
stable_memory_size: 0
14 changes: 14 additions & 0 deletions tests/measurements_output/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
use canbench::{benchmark, macros::bench, BenchResult};

#[link(wasm_import_module = "ic0")]
extern "C" {
pub fn stable64_grow(additional_pages: u64) -> i64;
}

// A benchmark that does nothing.
// The values of the benchmark are persisted such that no change is reported.
#[bench]
Expand Down Expand Up @@ -28,4 +33,13 @@ fn improvement_test() -> BenchResult {
benchmark(|| {})
}

// The values of the benchmark are persisted such that a regression from zero
// is reported.
#[bench]
fn stable_memory_increase() -> BenchResult {
benchmark(|| {
unsafe { stable64_grow(123) }
})
}

fn main() {}

0 comments on commit 4a13a74

Please sign in to comment.