Search code examples
javapythontimeterminalbenchmarking

Measuring performance difference between Python and Java implementations?


I want to compare the performance of two different implementations (Python and Java) of the same algorithm. I run scripts on the terminal (using Ubuntu 18) like this:

time script_name

I'm not sure how accurate this is. Is it possible to increase the accuracy of this benchmark? Perhaps there is a way to remove any restrictions or set-up in Python or Java?


Solution

  • As explained in this answer, the correct way to benchmark a program using time is the following command: sudo chrt -f 99 /usr/bin/time --verbose <benchmark>. However, note that this will only be accurate if the algorithm takes at least a second to execute, as otherwise the exec call might take up a big part of the benchmark.

    This answer suggests using perf stat instead, as such: perf stat -r 10 -d <your app and arguments>.