2

I've got three different programs written in three different languages, and I'm trying to compare their performance in terms of runtime, and memory consumption. What I'm looking for is some command that looks something like:

$ SOMETHING (python test.py)
$ SOMETHING (ghc -o test test.hs; ./test)
$ SOMETHING (gcc -o test test.c; ./test)

the reason for this is that I want to have a unified Unix(y) way of looking at the performance results of these programs as oppose to using the profiling tools in these different languages. I'd like also to know what are some other general/essential criteria software professionals measure beside runtime and memory consumption to get some useful stat out of these programs. Thank you

7kemZmani
  • 121
  • 2
  • Before you worry about the runtime of a specific implementation, worry about the time or memory complexity of your *algorithms*. Make sure you aren't doing things in O(n^3) that can be done in O(n log n log n), for example. (The exception would be when you *know* that the data set will be tiny. There's little reason to worry about a loop that runs through a handful of iterations total to sort a set of four elements, but there's plenty of reason to worry about the sort that can run on a set of 100,000 entries.) – user Jul 18 '16 at 15:29
  • exactly, the code for these three programs are optimized from the algorithm point of view, and now I just want to compare performance on the hardware. for python I could run also pypy test.py or even convert it to python3 and see how it runs. same thing for Haskell ghc and runhaskell and cabal and others, also for gcc, g++, clang. The whole point is just to find the right compiler/interpreter based on runtime & sys resources consumption – 7kemZmani Jul 18 '16 at 15:37

1 Answers1

1

A simple way would be to use GNU time command.

/usr/bin/time python test.py
/usr/bin/time /bin/sh -c 'ghc -o test test.hs; ./test'
/usr/bin/time /bin/sh -c 'gcc -o test test.c; ./test'

To normalize for starting the shell, I would also add a /bin/sh -c to the python command.

time has many options for formatting the output and including memory, I/O and other details in the output. See man time for details.

There is also a bash built-in time which can be used like:

time python test.py
time { ghc -o test test.hs; ./test; }
time { gcc -o test test.c; ./test; }

It will give you the times but I'm not sure that has options for memory and I/O as well.

Munir
  • 3,222
  • 13
  • 27