tags:

views:

403

answers:

3

Most online judges have some sort of system to measure execution time and memory consumption. An example is shown here. How is it done? Is there a simple UNIX utility I can use to run similar tests on my own programs?

+1  A: 

The UNIX time command will output the amount user time, system time, and some memory statistics. The Linux version can be found here and includes some formatting strings that allow you to specify the exact output.

tvanfosson
+1  A: 

Valgrind with all it's tools will give you some info:

  • cachegrind - a cache simulator
  • callgrind - call graph tracing - allows to get the cost of calls and show what is happening in your program
  • massif - info about heap memory usage
  • memcheck - memory leak checking

In addition you can use more sophisticated software, like Intel VTune.

If you are interested in low level details and the real hardware counters yourself then have a look at the perfmon2 which has some chances of getting into mainstream kernel some time in the future.

And search old questions - there are many posts on this subject.

Anonymous
+1  A: 

Last time I needed to profile a Unix program, I used gcc and gprof. It got me the information I needed.

David Thornley