Hi, I want to calculate the execution time and the number of cycles for the small set of code (python code). Currently, I am working with Raspberry Pi 3B (ARM Cortex-A53 SoC processor) and writing a python code. Now, I have to calculate execution time as well as a number of cycles for a small set of code. For example:
a = 10
b = 10
print("Sum ", (a+b))
If, it is impossible, then how can you say that print() is very slow. Is there any approach or calculation
.
"unpredictable" doesn't mean "unmeasurable." Any call to a "real" operating system (like Linux) has a lot of overhead just in switch context back and forth between the user and the operating system. (even on a deeply embedded system, the cost of an "SVC" instruction (causing exception-like handling) is perhaps 5x more than a "BL" based function call. Then you have to decode what function is being asked for and ... more. Adding an real OS adds additional context including caches and pager tables, and who knows what else.)
If you take a python program like:
do_io = Falsefor i in range(0, 1000000): a = 10 b = 10 if (do_io): print("Sum ", (a+b)) else: c = a + b
do_io = False
for i in range(0, 1000000):
if (do_io):
else:
c = a + b
and run it with "time python3 foo.py > /dev/null", you get times about 5x higher for the do_io=True version. (and in that case, they're both having to load and initialize the python interpreter as well, which is no small task.)