I'm currently learning C
to optimize the implementation of various algorithms (that I currently have implemented in Python).
To help me compare C
and Python
implementations, I'm looking to measure the function's execution time.
Using Python
, the iPython REPL
offers the fantastic %timeit
functionality, which effectively repeats the function many times and displays the average execution time and an indication of variation over the many times it was performed? This works for execution times varying from nanoseconds to many seconds.
In C
, I've read about a time
command that can be added to code to report the single-run execution time. However, this has 2 limitations:
1) only millisecond resolution
2) it's only a 'single-run' measurement.
Therefore, my question is: are there any better / alternative approaches or packages for C that will enable quick yet accurate (i.e. even working for fast ns-execution time functions) display of execution times?