Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Migrate existing benchmarks! macro to attribute macros #10848

@bkchr

Description

@bkchr

Currently benchmarks are written in the following form:

benchmarks! {
	bench_name {
		// Define the components, assumed to be linear.
		let x in 0 .. MAX_X;
		let y in 0 .. MAX_Y;
		// Setup code
		let z = x + y;
		let caller = whitelisted_caller();
	}: extrinsic_name(z, other_arguments...) // The extrinsic call.
	verify {
		// Post condition verification
		assert_eq!(MyPallet::<T>::my_var() == z);
	}
	// More benchmarks here
}

A better way of writing them would be closer to how tests are written in rust:

#[pallet::benchmark]
fn bench_name(x: LinearComponent<0, MAX_X>, y: LinearComponent<0, MAX_Y>) {
	// Setup code
	let z = x + y;
	let caller = whitelisted_caller();
	// The extrinsic call.
	extrinsic_name(z, other_arguments...);
	// Post condition verification
	assert_eq!(MyPallet::<T>::my_var(), == z);
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions