C code runtime measurement (Linux)

I want to measure the runtime of a c-code segment using Linux. I take one timestamp at the beginning of the code segment and one at the end. But I do not know how to protect the code from IRQ interruptions and context switches to high tasks. The program works in user space! The code segment is short, so don't panic bypassing the system.

Does anyone know an easy solution for this kind of protection?

+5
source share
1 answer

You can use getrusage(2)to use processor time, and not just real-time measurement. This should give you the answer you want without resorting to a fun business, for example, blocking the launch of other programs.

+3
source

All Articles