# Measure of code time in C-Script

**URL:** <https://forum.plexim.com/t/measure-of-code-time-in-c-script/1174>\
**Category:** PLECS\
**Tags:** time, c-script\
**Created:** [October 29, 2022, 6:26pm UTC](https://forum.plexim.com/t/measure-of-code-time-in-c-script/1174 "2022-10-29T18:26:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seyager](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@Seyager](https://forum.plexim.com/u/Seyager)\
**Post date:** [October 29, 2022, 6:26pm UTC](https://forum.plexim.com/t/measure-of-code-time-in-c-script/1174/1 "2022-10-29T18:26:18Z")

</div>

Hello.

I would like to know how to measure the time period between 2 point in the update code in the block C-Script. The command CurrentTime() just gives the time at the start of the period.

I need this to compare 2 different codes and tell which one is faster. Thanks.

---

<div class="post-metadata">

**Author:** ![Oliver\_Schwartz](https://dub1.discourse-cdn.com/flex006/user_avatar/forum.plexim.com/oliver_schwartz/32/6_2.png) [@Oliver\_Schwartz](https://forum.plexim.com/u/Oliver_Schwartz)\
**Post date:** [November 15, 2022, 11:25am UTC](https://forum.plexim.com/t/measure-of-code-time-in-c-script/1174/2 "2022-11-15T11:25:21Z")

</div>

The answer to this question does not really have anything to do with PLECS. The correct measurement of execution time in a multitasking system is quite complex and highly operating system dependent. The most reliable method is to use performance counters in the CPU, making sure that the measured thread is only executed on a single CPU core. Google “measure code performance in C” to get some hints. Whether these algorithms can be implemented in a C script is another matter.

The attached model measures the wall clock time between the start and end of a simulation. It can serve as an estimate of performance.

[tictoc.plecs](https://forum.plexim.com/uploads/short-url/udiCN45LS3Ran4FvhnbCBkqvNw7.plecs) (6.35 KB)
