Ivan Perez
Ivan Perez

Reputation: 610

Statically calculate execution time and memory consumption of C program

I work on a language that compiles to C99 with no mallocs, no recursion, and no loops. All memory is pre-allocated, and all functions terminate (unless there's an exception like division by zero).

The entry point of my module is always the same: a function void step(void).

Is there a tool that, under such circumstances, will calculate the max memory usage and max execution time of my code?

Upvotes: 0

Views: 151

Answers (1)

Paul Floyd
Paul Floyd

Reputation: 6946

valgrind --tool=massif --stacks=yes --pages-as-heap=yes

The above should profile all of the memory use.

Alternatively, while your executable is running you can use pmap -x PID (or look at /proc/PID/maps).

For the execution time, I would just use /usr/bin/time -p exe_name

Upvotes: -1

Related Questions