I am working on one project, the purpose of which is to compare sorting algorithms in different languages. My comparisons will be of two types:
- Comparison based on calendar time
- Comparison based on processor time
I want to know, if i can compare this methods / functions / procedures:
Comparison based on calendar time
Java -
System.nanoTime()
then time difference /1000000 on millisecPython -
time.time()
then time difference *1000C -
gettimeofday()
thentotalTime = (end.tv_sec - start.tv_sec) * 1e6; totalTime = (totalTime + (end.tv_usec - start.tv_usec)) * 1e-3;
Pascal -
now
and then time difference usingMilliSecondsBetween()
Comparison based on processor time
Java -
getThreadCpuTime()
then time differencePython -
thread_time()
then time differenceC -
clock()
then time differencePascal -
getTickCount64
then time difference //I am not sure of this, can you give advice?
I would go with external tool for such measure. Have to remember performance measurement is a tricky field and you have to ensure equal environment conditions and inputs for each of your implementations.
More than that:
It is really hard to compare performance of algorithm implementation across different languages because there are so many factors.
As a tool for measurement you can start with linux
time
command:More about time command
For windows there is a powershell cmd-let
Measure-Command
, more about it