How can I calculate the execution time in the following code:
#include /* Core input/output operations */
#include
n_procs is never initialized, the 16372-value that gets printed just happens to be what was previously on the stack.
The C standard library doesn't provide functionality to query processor count or high-performance timers, so you will have to look at other means of querying this. For instance, both POSIX and Windows API provides functionality like this.
edit: See Programmatically find the number of cores on a machine for how to initialize n_procs. Seeing how you use gettimeofday, you're probably on some unix-variant; "n_procs = sysconf(_SC_NPROCESSORS_ONLN);" is probably what you want.