📚
Open Polkadot Bootcamp
  • 📚 About the Bootcamp
    • 📖 Additional Resources
    • 👐 Ask For Support
  • 📖 Curriculum
  • 📕Rust Programming Language
    • Basic Rust
      • Introduction to Rust
        • 🧑‍💻 Excercises
      • Common Programming Concepts
        • 🧑‍💻 Excercises
      • Program Life Cycle
        • 🧑‍💻 Excercises
      • Ownership & Borrow Checker
      • Common Data Structures
    • Advanced Rust
      • Generic types, Trait extension and Advanced types
      • Lifetime Notation
      • Smart pointers & Macros
      • Common design patterns in Rust
      • Package management & How to structure your Rust project
      • Overview of the Rust ecosystem
  • 📘Building a blockchain with Polkadot SDK
    • Polkadot
      • Additional Reads
        • Why do you want to build a blockchain on Polkadot?
        • Understanding the sharded network design of Polkadot
      • Development on Polkadot
    • Polkadot SDK
      • Substrate
        • Create a new blockchain
          • 🧑‍💻 Exercise: Clone the minimal template
          • Understanding the architecture
          • Break down the node architecture
          • Introducing to Pop CLI tool
        • Adding a custom logic to runtime
          • 🧑‍💻 Exercise: Rust State Machine
          • Components of a Pallet
          • Hooks
          • Weights & Benchmarking
          • Extensions
            • Signed Extensions
            • Transaction Extensions
        • Common runtime modules
          • 📕Example: System Pallet
          • 📕Example: Contracts Pallet
          • 📕Example: Assets Pallet
          • 📕Example: Utility Pallet
        • Runtime API and RPC
        • Runtime upgrade
        • Bump Polkadot SDK versions
      • Cumulus
        • Introduction to Cumulus
          • Parachain from scratch
          • 🧑‍💻 Exercise: Build a parachain from scratch
        • Running a local relaychain network
          • Register & reserve a parachain
          • Launch the network & run a collator node
          • Launch the network with Pop CLI
        • Agile Coretime
    • Polkadot Hub
  • 📒Smart Contract Development
    • Introduction
      • Introduction to PolkaVM
      • Getting started with Solidity development
      • Solidity File Structure
      • Contract Structure
    • Basic Solidity
      • Value types
      • Reference Types
      • Mapping Types
      • Simple Storage
    • Advanced Solidity
      • Units
      • Global Variables
      • Expression and Control Structures
      • Advanced Storage
      • Contract Tests
      • Contracts
Powered by GitBook
On this page
  • Write & run a benchmarking
  • Resources
  1. Building a blockchain with Polkadot SDK
  2. Polkadot SDK
  3. Substrate
  4. Adding a custom logic to runtime

Weights & Benchmarking

PreviousHooksNextExtensions

Last updated 6 months ago

  • Weight: Unit of computation in Substrate

  • Bechmarking: Calculating the weights required for one pallet dispatchable function to be executed. Substrate benchmarking framework will re-run the logic calls to the dispatchable function defined in benchmarking.rs multiple times.

    • Dispatchable function weights will be specified in pallet::weights

The Substrate runtime is composed of distinct pallets, each of which expose various dispatchable functions. The weight of each of these functions are completely independent of one another, and can vary based on the logical path executed based on the inputs and existing state.

To benchmark these runtime functions, we execute them within the actual Wasm runtime, in worst case scenarios. With runtime extrinsics where the input or existing state may effect the complexity of the execution, we test the extrinsic by varying those components and using regression analysis to extract results.

The runtime benchmarks are broken into two pieces:

  • Timing Dispatch Function Logic

  • Tallying Database Reads and Writes

Write & run a benchmarking

./target/release/substrate benchmark --chain dev --pallet "*" --extrinsic "*" --steps 0

Resources

Benchmarking your Substrate pallets:

How to retrieve the computational time for resources in Substrate:

📘
https://www.youtube.com/watch?v=Qa6sTyUqgek
https://github.com/paritytech/substrate/discussions/13098
https://www.shawntabrizi.com/substrate-graph-benchmarks/docs/#/runtime?id=how-the-benchmark-works
Block Import Weight Breakdown