# Programmatically measure cycles consumption

**URL:** <https://forum.dfinity.org/t/programmatically-measure-cycles-consumption/12450>\
**Category:** Developers\
**Created:** [April 26, 2022, 3:13pm UTC](https://forum.dfinity.org/t/programmatically-measure-cycles-consumption/12450 "2022-04-26T15:13:49Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![gabe](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/gabe/32/4612_2.png) [@gabe](https://forum.dfinity.org/u/gabe)\
**Post date:** [April 28, 2022, 8:42am UTC](https://forum.dfinity.org/t/programmatically-measure-cycles-consumption/12450/6 "2022-04-28T08:42:33Z")

</div>

I did not know that Motoko Playground had started to support profiling. This is huge for me, great work!

I have a few questions regarding the interpretation of the profiling data after reading the design document and experimenting with it a bit in the playground:

1. Immediately when I deploy a canister I get an output as shown below. Does this represent instructions for installing the canister code? If so, is that a cycles cost on top of the _Canister Created_ cost [here](https://smartcontracts.org/docs/developers-guide/computation-and-storage-costs.html#_details_cost_of_compute_and_storage_transactions_on_the_internet_computer)?

> Wasm instructions executed 4246 instrs.

1. When looking at the flame graph below of the `insert()` function from the Phone Book example, does the number of instructions (3891) represent the number of “pure” Wasm instructions _or_ the weighted number of instructions where some system API calls are counted as multiple instructions (as discussed [here](https://forum.dfinity.org/t/heads-up-fixing-prod-issue-by-adjusting-the-complexity-of-some-system-api-calls/9516))?  
The reason I’m asking is because I want to know if it is correct to divide the number of instructions by 10 and multiply by 4 to get the cycles cost of the execution, or if there is more to it.

![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/3/3c3afbd94b4f9c76f4dde5bf845f42c6b222cfa3.png)

1. Again using the Phone Book example in the playground, I measure three operations where I insert three records one after the other in the same canister. See results below. What causes the same function to vary in instructions count based on different inputs?

> insert(“aaa”, record {desc=“aaa”; phone=“111”})  
> **insert: 5970 instrs**

> insert(“bbb”, record {desc=“bbb”; phone=“222”})  
> **insert: 7345 instrs**

> insert(“ccc”, record {desc=“ccc”; phone=“333”})  
> **insert: 5807 instrs**

1. When I run the `lookup()` function, which is a query call, a number of instructions is shown from the profiling. Can these be ignored when calculating cycles costs of a canister, since (if I’m not mistaken) query calls are currently free?

![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/3/3a14d48bf6413452e9072eb678a156636e5cc447.png)

1. Does the profiling support inter-canister calls, as in that you may see the combined number of instructions?

---

_[View the full topic](https://forum.dfinity.org/t/programmatically-measure-cycles-consumption/12450)._
