Ben <be*********@spam.me> wrote:
Hi,
I am wondering if there is an easy way to benchmark a c program as a way of measuring the efficiency of the program,
specifically the number of different instructions performed and total running time.
I have used other languages where the interpreter has a built-in flag to give you this information but not sure what the
equivalent is in c.
cheers,
Ben
Some compilers -- e.g. gcc -- have a "profiling" feature that allow you to
automatically count the number of times each line/statement is executed.
If you want to count "instructions" then some x86 processors (and others)
allow you to setup counters for certain "events" such as instruction fetches
or memory read/writes. But that is a function of the operating system.
If you want to measure program runtime and guestimate the number of instructions
executed (not forgetting with multiple pipeline machines these days, this is
not to squeezy anymore) then you're also outside the (strictly) C domain
and into operating system functionality & tools.