Please take a minute to review and accept our Terms of Use.
Welcome to the PLECS User Forum, where you can ask questions and receive answers from other members of the community.

Many technical questions regarding PLECS are answered on the Technical Solutions page of our website. Tutorial videos, specific application examples, and pre-recorded webinars are available on our YouTube page. Please follow us on LinkedIn for the latest Plexim news.

How to measure CPU runtime? Constantly getting 0.

0 votes
217 views

I am looking to measure the CPU time required to execute a PLECS standalone model. I am running the model through a simulation script, the same as wallclock is measured in the PLECS tutorials.

I am encountering a strange issue where the CPU time is not being measured properly, but the wallclock time is; the CPU time always shows zero time elapsed. I have attached a screenshot of the simulation script window and octave console showing the outputs. Any help is appreciated.

The simulation script code is here as well

plecs('clc')
t_begin = cputime
tic
plecs('simulate');
toc
t_end = cputime
t_elapsed = t_end - t_begin
asked Sep 11, 2023 by Jared (15 points)
edited Sep 11, 2023 by Jared

1 Answer

0 votes
 
Best answer

Jared, CPU can be a misleading measurement as it accounts for the CPU time of the Octave code, but not the execution time as Octave can be waiting on IO from other processes (i.e. PLECS).

Wall clock (tic/toc) is a better solution for benchmarking compared to cputime().  Another alternative is to use the Octave profiler.

plecs('clc')

tic
t1 = cputime();
profile on;

plecs('simulate')

profile off;
t_wall = toc
t_cpu = cputime()-t1

profshow (10);
profile clear;
answered Sep 13, 2023 by Bryan Lieblick (1,909 points)
selected Sep 14, 2023 by Jared
Hi Bryan,

Thanks for the answer, it helps me understand what is going on here. CPU time is very important to me, I specifically want to know the CPU time required for the PLECS process; it seems this cannot be measured directly? Your answer gives a list of wallclock times for each process, is it possible to get a list of CPU times for each process? I do not fully understand the framework so I may be misguided here.
Wall clock time is often a proxy for CPU time.  I do not think there is a workable solution built into PLECS/Octave.

If you want to measure CPU time of PLECS then perhaps there's an external profiling tool for the operating system you're using? CPU time is reported to Octave through OS specific utilities (e.g. getrusage).
I see, thank you again for the response; it is a shame there is no good method for the standalone program.
...