Benchmarking

Benchmarking in the Polkadot SDK/Substrate measures execution time and resource usage for pallets and extrinsics, ensuring accurate weight calculations and optimal performance.

With Pop CLI, you can benchmark pallets and extrinsics interactively by managing parameters efficiently. Run the following command to start benchmarking:

pop bench pallet

Note that the command requires the frame-omni-bencher binary to be installed on your local machine.

Pop CLI will automatically source the frame-omni-bencher binary if not found on your local machine.

Provide a runtime to benchmark

The command requires a runtime built with the runtime-benchmarks feature. Pop CLI detects available runtimes in your project, allowing you to choose one if multiple exist.

  Choose the build profile of the binary that should be used:
  Release

  Select the runtime:
   pop-runtime-testnet
   pop-runtime-devnet
   pop-runtime-mainnet

If the binary is missing, Pop CLI builds it with the appropriate build profile and features. You can manually specify the runtime binary path using:

pop bench pallet --runtime=target/release/pop-runtime-devnet.wasm

By default, whenever benchmarking starts, the runtime binary will be automatically built to ensure that it is current. You can provide a flag --no-build or -n manually to skip the build process if there is an existing runtime binary.

pop bench pallet --no-build

Configure the genesis builder policy and preset

Genesis builder policy defines the way to construct the initial genesis state.

There are two options for the genesis builder policy:

  • none: Do not provide any genesis state.

  • runtime: Use the runtime's genesis preset.

To configure the genesis builder manually, you can use the --genesis-builder flag. For example:

The genesis preset is configured on the runtime via sp_genesis_builder crates which contains a runtime-api to be implemented by runtimes, in order to express their genesis state.

To configure the genesis builder preset manually, you can use the --genesis-builder-preset flag:

Select pallets and extrinsics

You'll be prompted to benchmark all pallets or select a specific one. Pop CLI lists all available pallets within the runtime, allowing you to search by name and choose from the list.

You can simply search for pallets by typing their name and selecting them from the list.

If a pallet is specified, the CLI will prompt you to select the extrinsics you want to benchmark within that pallet. You can select multiple extrinsics by pressing the spacebar. Same as searching for pallets, you can search for extrinsics by typing their name as well.

If --extrinsic= and --pallet= are provided, the CLI will skip the search and directly benchmark with the specified arguments.

Manage parameters

Pop CLI displays all editable parameters, allowing you to preview and modify them as needed. Simply select a parameter to provide a new value.

To skip parameter configuration, you can use the --skip-parameters flag.

For example, to update the High parameter:

And you will see the value is updated:

Save weight output and parameter values to file

After the providing parameter values, you will be prompted to save the weight output and provided parameter values to a file. If not provided, no weight output will be saved.

To save parameter values, the file path is default to pop-bench.toml.

Below is the example of the parameter file:

With the saved parameter file, you can load parameter values from the file by using the -f or --bench-file flag.

For more advanced parameter configuration, you can run the following command to learn more:

Learning Resources

Need help?

Ask on Polkadot Stack Exchange (tag it pop) or drop by our Telegram. We're here to help!

Last updated

Was this helpful?