Crates.io | canbench |
lib.rs | canbench |
version | 0.1.7 |
source | src |
created_at | 2024-02-09 14:03:32.092743 |
updated_at | 2024-10-02 08:37:49.766966 |
description | A benchmarking framework for canisters on the Internet Computer. |
homepage | |
repository | https://github.com/dfinity/canbench |
max_upload_size | |
id | 1133980 |
size | 108,257 |
canbench
canbench
is a tool for benchmarking canisters on the Internet Computer.
Canister smart contracts on the Internet Computer consume compute and memory resources. Given that resources are finite, there are bounds in place when canisters execute a message (transaction):
A single message execution must stay within the allowed bounds, otherwise it's terminated.
canbench
provides developers the tools and insights to understand how their code is using instructions and memory.
Support for reporting dirty pages will be available once there's a way to retrieve dirty page information from the IC.
Metrics that are relevant
Typically benchmarking tools run a benchmark multiple times and return the average time.
On the Internet Computer, where instrumentation is deterministic, this approach is neither ideal nor insightful.
Instead, canbench
reports the number of instructions consumed, as well as changes to both heap and stable memories.
Easy detection of regressions
canbench
allows you to persist the benchmarking results in your canister's repository.
Storing the benchmarking results allows canbench
to determine how the performance has changed relative to the past to detect regressions.
Generous instruction limit
While messages on the Internet Computer are bound to a few billion instructions, canbench
can run benchmarks that are up to 10 trillion instructions, giving you the freedom to write resource-intensive benchmarks as needed.
Language Agnostic
canbench
can, in theory, benchmark canisters written in any language. Initially support for only Rust exists, but support for additional languages can easily be introduced.
cargo install canbench
See the crate's documentation.
canbench
can be included in Github CI to automatically detect performance changes.
Have a look at the workflows in this repository for working examples.
You'll need the following:
scripts
directory.canbench
to post a comment with the benchmarking results. See canbench-post-comment.yml
.upload-pr-number
in ci.yml
.benchmark-fibonacci-example
in ci.yml
.Once you have the CI workflow set up, the job will pass if there are no significant performance changes detected and fail otherwise. A comment is added to the PR to show the results. See this PR for an example.