Subject:
Re: C++ vs. Python vs. Perl vs. PHP performance benchmark
From:
Ivan Zahariev
Date:
20.6.2012 г. 08:48 ч.
To:
Isaac Gouy

Isaac,

You are too focused on "The Sieve of Eratosthenes" -- I don't really care if this is the "The Sieve of Eratosthenes" or Noname's algorithm. I'm testing "loops, arrays with numbers, basic math operations". Point. I don't care if there is a more optimized way of finding those 664579 prime numbers -- because I'm testing the languages, not trying to show how smart I'm in algorithms. Bottom line -- I won't change Java or C++ to use static arrays, nor discuss the algorithm any more.

Regarding the special function -- you are right. The difference for Python is about 20% according to my tests, for PHP it's 5% (already stated on the website). I may correct this, but right now I'm quite busy with my real life. How does this make Java slower?

I won't set an initial heap size for Java -- this is an optimization that's pretty much case-per-case dependent.

Answering your other e-mail about the compilation time. The link you provided (http://www.oracle.com/technetwork/java/hotspotfaq-138619.html#benchmarking_simple) says:
"... you can work around the problem by moving the body of main to a new method and calling it once from main to give the compiler a chance to compile the code".

That's exactly what I've done, so I don't think I'm violating any Java recommendations here.

Look, I'm not biased towards Java or any other language -- I don't even program in Java *or* Python. And current benchmarks put Java on #2 place. I don't know what your idea here is -- to prove that Java is faster than C++, or to to change the difference between Java and Python from 162% to 182%?

I don't know that you meant in the other e-mail by "Here are times for the SimplePrimes.java program that uses int[]". Is there a way that I use dynamic growing arrays and use "int" instead of "Integer"?

P.S. You are not answering all my questions -- System.nanoTime() is returning the wall-clock time? If yes, how are you sure that the compiler isn't executing something on more than one core (for example running the loop on one core, and doing garbage collection on the other).

On 20.6.2012 г. 01:43 ч., Isaac Gouy wrote:
Hi Ivan


Why would you think that I want to make Java look slow?
Because that's what you've done :-)


This is a fair competition with fair rules -- every language uses the
very same algorithm.
I'll answer in 2 ways --

1) The program I provided uses the same algorithm - The Sieve of Eratosthenes. What it doesn't do is force Java to be written as though it was Python.

2) Not a fair competition! Your Java program adds one element at a time to ArrayList s -- but your Python program uses a special function to create the dynamic array s.

To be what you call fair, your Python program should add one element at a time to array s. Measure the runtime of the attached program slowerprimes.py


The idea is, if we used another algorithm which *did* require that we use dynamic
arrays everywhere, to compare how each language does the job in regards
to performance.
If you care about dynamic array performance then don't you think you should use an algorithm that adds and removes elements from a dynamic array?


Note that your optimizations also apply to C++
Yes, the *ordinary* way to write the Sieve of Eratosthenes that every C++ programmer would take is to use a fixed size array. The Sieve of Eratosthenes algorithm does not grow or shrink the array!




If you insist on using Java ArrayList when it isn't needed, then at least set an initial heap size that will allow the ArrayList to grow in the way you wish. Run your Java program like this --

$ time java -Xms500m PrimeNumbersBenchmarkApp


best wishes, Isaac