Reputation: 83
I know we can compare the time complexity of two algorithms by analysis. But know I want to evaluate them by real data. But unfortunately, they are written in different language. Since different language themselves have different efficiency, is it possible to compare the efficiency of two algorithms written in different efficiency?
For example, I have two sorting algorithms. One written in C and another in Java. It's unfair to compare their running time because C and Java have different efficiency. Is it possible to compare them fairly? Maybe a way to unify the unit for an operation?
I don't want to rewrite any algorithm because both of them have more than 10 thousand lines.
Upvotes: 3
Views: 2377
Reputation: 5260
if you want to test the time complexity of each algorithm, you can run them on different data set size, let sayon: 10, 100, 1000, 10K, 100K ... 1M (or B) data set, measure the time it take the algorithm to finish. put the result on graph will give you the answer.
so if the complexity is linear you will get a linear graph, if it's O(n^2) the graph will be very different.
now that you have the time complexity of each algorithm it's easy to compare them, alought each is written in a different language.
Upvotes: 3
Reputation: 7494
While it is definitely possible to measure which setup runs faster, it would not be enough to say for certain that the algorithm of the the setup that ran faster is more efficient or quicker. The reason is because of the programming languages themselves. Certain languages are faster because they are simpler. Java is slower because it has a lot of features which make it impractical to run large mathematical calculations. On the other hand, nothing can beat Fortran when it comes to pure number crunching. You will find that for large datasets Fortran runs faster than Java even with a relatively less efficient algorithm (keyword here is relative).
Upvotes: 0