# Weights & Benchmarking

* **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.&#x20;
  * Dispatchable function weights will be specified in `pallet::weights`&#x20;

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

<figure><img src="/files/qfZi4ecmn6BjfgJ3SSKv" alt=""><figcaption><p>Block Import Weight Breakdown</p></figcaption></figure>

### Write & run a benchmarking

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

### Resources

* Benchmarking your Substrate pallets: <https://www.youtube.com/watch?v=Qa6sTyUqgek>
* How to retrieve the computational time for resources in Substrate:  <https://github.com/paritytech/substrate/discussions/13098>
* <https://www.shawntabrizi.com/substrate-graph-benchmarks/docs/#/runtime?id=how-the-benchmark-works>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bootcamp.openguild.wtf/building-a-blockchain-with-polkadot-sdk/polkadot-sdk/substrate/adding-a-custom-logic-to-runtime/weights-and-benchmarking.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
