Java Forum / General / December 2007
performance question
Olivier Scalbert - 08 Dec 2007 19:49 GMT Hello,
I would like to show to somebody how different languages look like by doing a very simple case. I was very surprised by the poor performance of the java version !
Here are the programs in different languages:
in C:
#include <stdio.h>
int main() { int i;
for(i = 0; i < 1000000; i++) { printf("abcdefghijk %d\n", i); }
return 0; }
time ./test1 > out.txt
real 0m0.710s user 0m0.576s sys 0m0.124s
in java: public class Test { public static void main(String[] args) { for (int i = 0; i < 1000000; i++) { System.out.println("abcdefghijk " + i); } } }
time java Test > out.txt
real 0m12.364s user 0m4.180s sys 0m7.676s
time java -server Test > out.txt
real 0m10.537s user 0m3.120s sys 0m6.544s
That is not good at all ! ols@tatooine:~/projects/ruby$ java -version java version "1.6.0_02" Java(TM) SE Runtime Environment (build 1.6.0_02-b05) Java HotSpot(TM) Client VM (build 1.6.0_02-b05, mixed mode, sharing)
ols@tatooine:~/projects/ruby$ uname -a Linux tatooine 2.6.22-14-generic #1 SMP Sun Oct 14 23:05:12 GMT 2007 i686 GNU/Linux
In python: i=0 while i < 1000000: print "abcdefghijk", i i=i+1
time python test.py > out.txt
real 0m2.292s user 0m2.064s sys 0m0.112s
In perl: for ($count = 0; $count < 1000000; $count++) { print "abcdefghijk $count\n"; } time perl test.pl > out.txt
real 0m1.243s user 0m1.060s sys 0m0.160s
In ruby: counter = 0 while counter < 1000000 puts("abcdefghijk #{counter}") counter+=1 end
time ruby test.rb > out.txt
real 0m4.731s user 0m4.452s sys 0m0.100s
As you can see the java program performance is far from the other one. I was very surprised! Before the tests, I was sure that the winner will be C followed by java, but it is not the case ...
Of course, I can improve the performance of the java version, by using a StringBuffer, and print this buffer when it is bigger than a given size, but it is not fair !
If you have any ideas, there are welcomed !
Thanks,
Olivier
Real Gagnon - 08 Dec 2007 20:19 GMT > time java -server Test > out.txt > > real 0m10.537s > user 0m3.120s > sys 0m6.544s I bet that the JVM loading and startup time is very important with your test.
So it's not this particular code which is slow, the timing technique is not adequate.
Bye.
 Signature Real Gagnon from Quebec, Canada * Java, Javascript, VBScript and PowerBuilder code snippets * http://www.rgagnon.com/howto.html * http://www.rgagnon.com/bigindex.html
Olivier Scalbert - 08 Dec 2007 20:37 GMT >> time java -server Test > out.txt >> [quoted text clipped - 4 lines] > I bet that the JVM loading and startup time is very important with your > test. Not sure !
With: public class Test { public static void main(String[] args) { for (int i = 0; i < 1; i++) { System.out.println("abcdefghijk " + i); } } }
time java Test > out.txt
real 0m0.125s user 0m0.040s sys 0m0.032s
> So it's not this particular code which is slow, the timing technique is not > adequate. Do you have another technique ?
> Bye. See you
Lew - 08 Dec 2007 20:58 GMT >>> time java -server Test > out.txt >>> [quoted text clipped - 14 lines] > { > System.out.println("abcdefghijk " + i); Note: This has the overhead of character encoding. Your C example does not. So you are comparing very different activities.
> } > } [quoted text clipped - 9 lines] >> adequate. > Do you have another technique ? Yes - time the loop, not the load time. With Java, you should run the loop for a while, then run it again with timing instrumentation. This lets the JVM optimize the loop.
Your benchmark as presented is pretty useless. Apples and oranges.
 Signature Lew
Olivier Scalbert - 08 Dec 2007 21:09 GMT ;
> Note: This has the overhead of character encoding. Your C example does > not. So you are comparing very different activities. Good point, but I find that the char encoding overhead is quite expensive ! Thanks.
Jon Harrop - 08 Dec 2007 21:42 GMT > ; >> [quoted text clipped - 3 lines] > Good point, but I find that the char encoding overhead is quite expensive > ! Thanks. No, char encoding is not an adequate explanation of a 15x slowdown. This is Java being very poor at buffering.
 Signature Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?u
Lew - 08 Dec 2007 21:55 GMT >> ; >>> Note: This has the overhead of character encoding. Your C example does [quoted text clipped - 5 lines] > No, char encoding is not an adequate explanation of a 15x slowdown. This is > Java being very poor at buffering. A point also made by Mark Thornton, and more evidence that my point is true: that the benchmark is not comparing the same algorithms and is therefore not valid.
 Signature Lew
Olivier Scalbert - 08 Dec 2007 21:59 GMT >>> ; >>>> Note: This has the overhead of character encoding. Your C example does [quoted text clipped - 11 lines] > true: that the benchmark is not comparing the same algorithms and is > therefore not valid. Ok, but how can I do the same thing in Java ? By the way, I do not want to attack java (that I use daily). I just want to understand ...
Lew - 08 Dec 2007 22:09 GMT >>>> ; >>>>> Note: This has the overhead of character encoding. Your C example does [quoted text clipped - 13 lines] > By the way, I do not want to attack java (that I use daily). I just want > to understand ... First, add character encoding to the other languages' examples.
Second, change the buffer in the output streams (or Writer, in Java's case) to be the same size in every example.
Third, don't time the startup time of the Java program. Just time the loops in each language.
Fourth, since, unlike C, Java is dynamically optimized, not statically, run the loop enough times for optimization to kick in (which you likely are already doing). Ideally, you'd run the loop a while without timing it, then again with timing, letting the Hotspot compiler do its thing.
 Signature Lew
Jon Harrop - 08 Dec 2007 22:26 GMT > First, add character encoding to the other languages' examples. Why? We don't want char encoding so there is no logical reason to cripple all other implementations just because Java can't handle it.
> Second, change the buffer in the output streams (or Writer, in Java's > case) to be the same size in every example. You can't even cripple most other implementations in that way.
> Third, don't time the startup time of the Java program. Just time the > loops in each language. The startup time is only ~4% of the total time anyway on this benchmark, because Java is so slow.
> Fourth, since, unlike C, Java is dynamically optimized, not statically, > run the loop enough times for optimization to kick in (which you likely > are > already doing). Ideally, you'd run the loop a while without timing it, > then again with timing, letting the Hotspot compiler do its thing. If you're not doing that with your normal programs, why do it here? Is Hotspot too stupid to reuse previous results? How much scope do you think there is for dynamic optimization here anyway?
 Signature Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?u
Joshua Cranmer - 08 Dec 2007 23:02 GMT >> First, add character encoding to the other languages' examples. > > Why? We don't want char encoding so there is no logical reason to cripple > all other implementations just because Java can't handle it. Why cripple Java, or any other programming language for that matter, by having it merely print out one million lines of code? Use sed, awk, or bash for that matter.
>> Fourth, since, unlike C, Java is dynamically optimized, not statically, >> run the loop enough times for optimization to kick in (which you likely [quoted text clipped - 5 lines] > Hotspot too stupid to reuse previous results? How much scope do you think > there is for dynamic optimization here anyway? Java's performance gets better in the long run thanks to Hotspot optimization; you're metering a program with an abnormally short lifespan that's not "realistic" at all.
The problem with most benchmarks is that almost all of them are poorly designed. The best benchmark is one that takes full power of the language and "standard" libraries to mimic real-world applications. Most benchmarks are far from real-world examples. How many programs actually print out 1,000,000 lines of output in their entire lifespan?
I believe that there is a published benchmark measuring the FPS of a Quake implementation in both Java and C; IIRC, the Java actually does better than the C much of the time.
Don't complain about performance until you have benchmarks of that sort.
 Signature Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth
Olivier Scalbert - 08 Dec 2007 23:34 GMT > The problem with most benchmarks is that almost all of them are poorly > designed. The best benchmark is one that takes full power of the > language and "standard" libraries to mimic real-world applications. Most > benchmarks are far from real-world examples. How many programs actually > print out 1,000,000 lines of output in their entire lifespan? More of 1,000,000 lines of output ? Trust me, a lot of programs ! Depending of your work !
Mark Thornton - 08 Dec 2007 23:52 GMT >> The problem with most benchmarks is that almost all of them are poorly >> designed. The best benchmark is one that takes full power of the [quoted text clipped - 3 lines] > More of 1,000,000 lines of output ? Trust me, a lot of programs ! > Depending of your work ! I've used Java to compute digests of every file on a (large) disk. The execution time was disk bound.
Mark Thornton
Jon Harrop - 09 Dec 2007 11:52 GMT >>> First, add character encoding to the other languages' examples. >> [quoted text clipped - 4 lines] > having it merely print out one million lines of code? Use sed, awk, or > bash for that matter. If the Java were crippled, you would be able to optimize it. Can you?
>>> Fourth, since, unlike C, Java is dynamically optimized, not statically, >>> run the loop enough times for optimization to kick in (which you likely [quoted text clipped - 8 lines] > Java's performance gets better in the long run thanks to Hotspot > optimization; There is absolutely no evidence of that whatsoever.
> you're metering a program with an abnormally short lifespan that's > not "realistic" at all. On the contrary, that is very realistic for a wide range of important applications, e.g. any interactive coding.
> The problem with most benchmarks is that almost all of them are poorly > designed. The best benchmark is one that takes full power of the > language and "standard" libraries to mimic real-world applications. Most > benchmarks are far from real-world examples. How many programs actually > print out 1,000,000 lines of output in their entire lifespan? A huge number of programs do millions of lines of IO.
I was analyzing our sales vs web stats yesterday and that entails millions of lines of IO. Not only is interpreted OCaml both interactive and concise compared to Java, it is also several times faster at this. I don't use Java precisely because it is woefully inadequate in this respect.
> I believe that there is a published benchmark measuring the FPS of a > Quake implementation in both Java and C; IIRC, the Java actually does > better than the C much of the time. Quake 2 is a decade out of date and no longer even vaguely CPU intensive. That is the _only_ reason Java will do as well as C on that benchmark.
> Don't complain about performance until you have benchmarks of that sort. I have plenty of benchmarks of that sort. Look how you must butcher the Java code to make this ray tracer 60% slower than the fastest languages:
http://www.ffconsultancy.com/languages/ray_tracer/
In the cases where Java can attain competitive performance (e.g. with 2x the performance of OCaml), you must apply so many optimizations by hand that the result would be totally unmaintainable for any real program.
 Signature Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?u
Mark Thornton - 09 Dec 2007 12:45 GMT > I have plenty of benchmarks of that sort. Look how you must butcher the Java > code to make this ray tracer 60% slower than the fastest languages: > > http://www.ffconsultancy.com/languages/ray_tracer/ I suspect that using a JVM that does escape analysis to allocate objects on the stack where possible would change the performance of the ray_tracer quite significantly. There is at least one JVM available which does this.
Mark Thornton
Mark Thornton - 08 Dec 2007 23:25 GMT >> First, add character encoding to the other languages' examples. > > Why? We don't want char encoding so there is no logical reason to cripple > all other implementations just because Java can't handle it. If you set the output encoding to ISO-8859-1, then the overhead is usually insignificant. However people who mishandle text containing characters outside US ASCII, in my opinion, deserve a special place in hell. It is really unpleasant trying to recover usable data that has been mangled in this way.
>> Second, change the buffer in the output streams (or Writer, in Java's >> case) to be the same size in every example. > > You can't even cripple most other implementations in that way. Of course you can. You set buffers of any size you want in both Java and C and select flushing policies too in both. If you want a fair comparison, just make sure that you use the same conditions in both cases.
> The startup time is only ~4% of the total time anyway on this benchmark, > because Java is so slow. Until you equalise the buffering policies, you aren't comparing like with like.
> If you're not doing that with your normal programs, why do it here? Is > Hotspot too stupid to reuse previous results? How much scope do you think > there is for dynamic optimization here anyway? If your benchmark is too simple to allow scope for dynamic optimisation it is likely to be a poor representation of real use. If your application is computationally intensive, the results of previous runs can be a poor guide to optimising the current run. Therefore on real work the benefit of retaining previous HotSpot data is not as great as a simplistic test might suggest.
One downside of techniques like those used in HotSpot is that it makes writing useful micro benchmarks much harder. Some suggest that a useful micro benchmark is now all but impossible. HotSpot isn't the only culprit here; modern CPUs also have very complex performance characteristics that similarly confound attempts at simple benchmarks.
Mark Thornton
Patricia Shanahan - 09 Dec 2007 01:26 GMT ...
> One downside of techniques like those used in HotSpot is that it makes > writing useful micro benchmarks much harder. Some suggest that a useful > micro benchmark is now all but impossible. HotSpot isn't the only > culprit here; modern CPUs also have very complex performance > characteristics that similarly confound attempts at simple benchmarks. ...
The uselessness of micro-benchmarks is a lot older than Hotspot.
I became convinced while comparing two computers, both with vector processors, on the double precision Fortran version of Livermore Loops, http://www.netlib.org/benchmark/livermore.
Any one of the loops could have been extracted and treated as a micro benchmark. By selecting a loop, I could have proved a three to one performance ratio between the two computers. *In either direction*.
The compilers for the two computers vectorized different subsets of the loops.
Patricia
Jon Harrop - 09 Dec 2007 11:40 GMT >> Why? We don't want char encoding so there is no logical reason to cripple >> all other implementations just because Java can't handle it. [quoted text clipped - 4 lines] > hell. It is really unpleasant trying to recover usable data that has > been mangled in this way. That depends entirely upon what you're doing. If you're happy with ASCII and you want your program to run 10x faster then you should be able to make this change at will. Lot's of people will want "10x faster". I know I would.
>>> Second, change the buffer in the output streams (or Writer, in Java's >>> case) to be the same size in every example. >> >> You can't even cripple most other implementations in that way. > > Of course you can. No, you can't.
> You set buffers of any size you want in both Java and > C and select flushing policies too in both. If you want a fair > comparison, just make sure that you use the same conditions in both cases. How do you do it in OCaml or F#, for example?
>> The startup time is only ~4% of the total time anyway on this benchmark, >> because Java is so slow. > > Until you equalise the buffering policies, you aren't comparing like > with like. Nobody wants to compare "like with like" in that sense (replicating internals). We are interested in comparing two things of great practical value:
1. Obvious implementation vs obvious implementation, e.g. most concise C vs most concise Java.
2. Optimized vs optimized.
From what we've seen here, Java is 15x slower in the first case and still several times slower in the second.
>> If you're not doing that with your normal programs, why do it here? Is >> Hotspot too stupid to reuse previous results? How much scope do you think >> there is for dynamic optimization here anyway? > > If your benchmark is too simple to allow scope for dynamic optimisation > it is likely to be a poor representation of real use. That is just putting spin on the fact that Java is unsuitable for short-lived programs. A huge number of very important applications fall into that category, e.g. interactive technical computing environments using JIT compilation.
> If your > application is computationally intensive, the results of previous runs > can be a poor guide to optimising the current run. Therefore on real > work the benefit of retaining previous HotSpot data is not as great as a > simplistic test might suggest. I see no evidence that Hotspot improves the performance of longer-running programs. I see a lot of people stating that, but no hard numbers.
> One downside of techniques like those used in HotSpot is that it makes > writing useful micro benchmarks much harder. Some suggest that a useful > micro benchmark is now all but impossible. HotSpot isn't the only > culprit here; modern CPUs also have very complex performance > characteristics that similarly confound attempts at simple benchmarks. That is a retreat into "this benchmark fails to reach the asymptotic limit of infinite complexity and, therefore, shows Java in an unfairly-poor light".
 Signature Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?u
Mark Thornton - 09 Dec 2007 12:48 GMT > I see no evidence that Hotspot improves the performance of longer-running > programs. I see a lot of people stating that, but no hard numbers. You haven't looked very hard, and you have declared that you aren't interested in the answer anyway.
Lew - 09 Dec 2007 16:44 GMT >> I see no evidence that Hotspot improves the performance of longer-running >> programs. I see a lot of people stating that, but no hard numbers. > > You haven't looked very hard, and you have declared that you aren't > interested in the answer anyway. GIYF, Jon. The numbers are out there.
 Signature Lew
Jon Harrop - 10 Dec 2007 00:13 GMT >>> I see no evidence that Hotspot improves the performance of >>> longer-running programs. I see a lot of people stating that, but no hard [quoted text clipped - 4 lines] > > GIYF, Jon. The numbers are out there. Yeah, like the rubbish Steve Wampler just posted. There are lots of numbers out there but nothing objective that I can reproduce.
 Signature Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?u
Lew - 10 Dec 2007 00:34 GMT >>>> I see no evidence that Hotspot improves the performance of >>>> longer-running programs. I see a lot of people stating that, but no hard [quoted text clipped - 5 lines] > Yeah, like the rubbish Steve Wampler just posted. There are lots of numbers > out there but nothing objective that I can reproduce. One minute of search produced <http://www.idiom.com/~zilla/Computer/javaCbenchmark.html>
These are results from ca. 2001-2004, and Java was already reasonably close on a number of the benchmarks, 9x slower on some, faster on others.
A few more minutes turned up <http://www.ddj.com/cpp/184401976> from 2005, which includes source code and operating conditions for the benchmarks. Pretty freaking reproducible, eh?
There's more.
 Signature Lew
Jon Harrop - 10 Dec 2007 09:29 GMT >> Yeah, like the rubbish Steve Wampler just posted. There are lots of >> numbers out there but nothing objective that I can reproduce. [quoted text clipped - 4 lines] > These are results from ca. 2001-2004, and Java was already reasonably > close on a number of the benchmarks, 9x slower on some, faster on others. I would love to try to verify their results but the test codes are not available AFAICT.
> A few more minutes turned up > <http://www.ddj.com/cpp/184401976> > from 2005, which includes source code and operating conditions for the > benchmarks. Pretty freaking reproducible, eh? C++ code runs twice as fast as the Java on my machine. However, the experiment has design flaws which make the results useless.
The essence of a good benchmark is that the task it performs must not be trivially reducible. This is exactly why my ray tracer is a much better benchmark than most of the tasks on the shootout. In contrast, this benchmark simply prints a few constants that could be hardcoded.
Here is an interested quote from one of their citations:
"I found some tests that claim Java is faster than C++... [I] found the test & results to be pretty bogus." http://www.w3sys.com/pages.meta/benchmarks.html
He concludes that Java was much slower but the benchmark was rigged to show Java to be fast by deliberately measuring the wrong thing.
Every time I find a benchmark that shows Java favorably, further investigation shows it to be a fraud.
 Signature Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?u
Lew - 10 Dec 2007 15:48 GMT > C++ code runs twice as fast as the Java on my machine. However, the > experiment has design flaws which make the results useless. [quoted text clipped - 15 lines] > Every time I find a benchmark that shows Java favorably, further > investigation shows it to be a fraud. Blah, blah, blah. A benchmark shows that Java is twice as slow as C++, when before you said it was a hundred times as slow, and all of a sudden you deny the validity of the benchmark. Then you bring up one which you know will beat Java, and yet ignore all the use cases that favor Java.
I am not saying "Java is faster than C++" as a blanket statement. I'm saying Java is a lot closer to C++ in performance than naysayers such as yourself would have us believe. I say there's a lot of evidence out there, you say it isn't reproducible. I find reproducible results that show Java is comparable to C++, you say, "Oh, but those benchmarks aren't valid." Well, the fact that they are reproducible means that people can decide for themselves.
The fact remains that Java is not the slowpoke you claim. The fact is that it is, for many tasks Java is comparable, and for most, in the same ballpark as C++. The fact is that you have not countered with any reasonable evidence for *your* claims, while the evidence just mounts and mounts and mounts for the "Java is near enough to C++" side. I run the benchmarks, too, you know. I read the articles with the same eye to reproducibility and comparability you claim to use. I'm convinced by the hard evidence, enough to discount your flamebait rants.
At this point I am aware that Jon is only going to continue his polemical approach not grounded in tests and facts, for what agenda I can only speculate. My intent is to counteract the misrepresentations and provide evidence for the objective-minded to decide for themselves.
FWIW, my conclusion is that Java is generally somewhat slower than C++ for the types of scenarios micro-benchmarks validate. I have yet to find out if it is for the claimed "Java wins" scenarios: long-running server processes. Nevertheless, in every test I've read or performed, Java is only somewhat slower, not dramatically, and on several benchmarks * it actually outperforms C++ * even in this micro-benchmark scenario.
Those are facts. Now let Jon rant.
 Signature Lew
Steve Wampler - 10 Dec 2007 16:18 GMT > I am not saying "Java is faster than C++" as a blanket statement. I'm > saying Java is a lot closer to C++ in performance than naysayers such as [quoted text clipped - 3 lines] > aren't valid." Well, the fact that they are reproducible means that > people can decide for themselves. This friend speaks my mind.
 Signature Steve Wampler -- swampler@noao.edu The gods that smiled on your birth are now laughing out loud.
Jon Harrop - 10 Dec 2007 23:03 GMT >> C++ code runs twice as fast as the Java on my machine. > > I find reproducible results that show Java is comparable > to C++, you say, "Oh, but those benchmarks aren't valid." Well, the fact > that they are reproducible means that people can decide for themselves. Reread what I wrote above: I tested the benchmark that you cited claiming that it showed Java to be fast and found the exact opposite to be true. Indeed, I did this for every single testable benchmark and they all showed the same results.
> The fact remains that Java is not the slowpoke you claim. That is a triumph of hope over reality. Most of the benchmarks we've looked at in this thread prove that to be completely wrong.
> The fact is that it is, for many tasks Java is comparable, and for most, > in the same ballpark as C++. For some tasks, yes.
> The fact is that you have not countered with any reasonable evidence > for *your* claims, Nonsense. I only just posted my results for the benchmark that _you_ cited and they showed, again, that Java is much slower.
> while the evidence just mounts and mounts and mounts for the "Java is near > enough to C++" side. What drivel. Look at the benchmark the OP posted. A dozen Java implementations later and 20x as much code and it is still 2x slower than the OPs C code.
> I read the articles with the same eye to reproducibility and comparability > you claim to use. I doubt that: I have a PhD in computational physics from the University of Cambridge.
> I'm convinced by the hard evidence, enough to discount your flamebait > rants. No, you and Steve subscribe to the religious faith that Java is performant in the face of overwhelming evidence to the contrary.
> At this point I am aware that Jon is only going to continue his polemical > approach not grounded in tests and facts, for what agenda I can only > speculate. My intent is to counteract the misrepresentations and provide > evidence for the objective-minded to decide for themselves. If that were true you would have optimized the Java code in any of these benchmarks (e.g. the OPs) to run as fast as the other languages.
Instead you have simply restated your position of blind faith several times.
Go ahead, optimize them. I dare you. You can start with the symbolic simplifier I just posted.
 Signature Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?u
Steve Wampler - 10 Dec 2007 23:42 GMT > Reread what I wrote above: I tested the benchmark that you cited claiming > that it showed Java to be fast and found the exact opposite to be true. > Indeed, I did this for every single testable benchmark and they all showed > the same results. For your environment. Not for mine, using the code provided in this thread. What is your environment, incidently? Mine is (for the recent set of tests):
CentOS4.5, gcc 4.1.1, Sun JDK 1.6u3 on a dual-Opteron (2GHz) with 2GB ram
With runs of 10,000,000 lines (since the OP has stated the real case may involve billions of lines), the 'optimized' java is 1/3 again *faster* than the C version - on the above hardware.
 Signature Steve Wampler -- swampler@noao.edu The gods that smiled on your birth are now laughing out loud.
Jon Harrop - 11 Dec 2007 00:48 GMT > What is your environment, incidently? Athlon64 X2 4400+ Debian Lenny GCC 4.2.3 Sun JDK 1.6
 Signature Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?u
Steve Wampler - 11 Dec 2007 01:45 GMT >> What is your environment, incidently? > > Athlon64 X2 4400+ > Debian Lenny > GCC 4.2.3 > Sun JDK 1.6 Now that is interesting. I was hoping it was a single cpu system as I could see that making a significant difference on the Java side.
Is Lenny a 64-bit kernel? CentOS4.5 has a 32-bit kernel on the Opteron.
I'd be surprised in going from 4.1.1 to 4.2.3 made that much of an improvement on the C++ side, but I can't see the difference between the Opteron and Athlon64 resulting in as much a swing as we're seeing between your machine and mine.
I'd be interested in seeing what others are getting with the two programs, also.
 Signature Steve Wampler -- swampler@noao.edu The gods that smiled on your birth are now laughing out loud.
Jon Harrop - 11 Dec 2007 10:06 GMT >>> What is your environment, incidently? >> [quoted text clipped - 9 lines] > Is Lenny a 64-bit kernel? CentOS4.5 has a 32-bit kernel on the > Opteron. Everything is 64-bit here.
> I'd be surprised in going from 4.1.1 to 4.2.3 made that > much of an improvement on the C++ side, but I can't see > the difference between the Opteron and Athlon64 resulting > in as much a swing as we're seeing between your machine > and mine. Agreed.
 Signature Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?u
Lew - 11 Dec 2007 02:22 GMT >> I read the articles with the same eye to reproducibility and comparability >> you claim to use. > > I doubt that: I have a PhD in computational physics from the University of > Cambridge. Oh, I bow to you, Great One!
You accuse me of being "religious" when I clearly state that I find Java to be slower than C++ on many of the benchmarks. This to me is evidence that you are a (highly educated) troll.
 Signature Lew
Jon Harrop - 11 Dec 2007 10:09 GMT > You accuse me of being "religious" when I clearly state that I find Java > to be slower than C++ on many of the benchmarks. If those are your findings, you should not have stated "The fact remains that Java is not the slowpoke you claim.".
 Signature Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?u
Lew - 11 Dec 2007 14:35 GMT >> You accuse me of being "religious" when I clearly state that I find Java >> to be slower than C++ on many of the benchmarks. > > If those are your findings, you should not have stated "The fact remains > that Java is not the slowpoke you claim.". Yes, I should have, because you were claiming 10-100x slower, and I found only 2x slower. Try being honest for a change.
 Signature Lew
Steve Wampler - 09 Dec 2007 17:19 GMT > Ok, but how can I do the same thing in Java ? > By the way, I do not want to attack java (that I use daily). I just want > to understand ... Try the following version (lifted almost verbatim from an earlier thread). Note that it includes instrumentation code that could be stripped out in 'Real Life'. Also note that the methods it uses could be generalized and provided as part of a 'performance' package. (I didn't write the methods, incidently.)
--------------------------------------------------------------------- class T1 {
static public void main(String[] argv) { int lim = new Integer(argv[0]); int nbench = new Integer(argv[1]); int b;
for (b=0; b < nbench; b++) { System.err.println("Bench " + b);
Date start = new Date(); try { write3fastItoS2(lim); } catch ( Exception e) { System.err.println("Exception occurred"); System.err.println(e.toString()); } Date now = new Date();
System.err.println("Took " + ((now.getTime() - start.getTime())/1000.0) + " seconds"); } }
static public void write3fastItoS2( int lim ) throws IOException { BufferedOutputStream os = new BufferedOutputStream( System.out ); String message2 = "abcdefghijk "; byte[] mbuff = message2.getBytes(); int mlength = mbuff.length;
AsciiByteBuff ibuff = new AsciiByteBuff(); ibuff.ascii = new byte [Integer.toString(Integer.MAX_VALUE).length() + 2 ];
for( int i = 0; i < lim; i++ ) { os.write( mbuff, 0, mlength ); fastItoS2( ibuff, i ); os.write(ibuff.ascii, ibuff.start, ibuff.slength ); os.write('\n'); } os.close(); }
/** Converts a POSITIVE integer to a byte [], with an emphasis on speed. * * @param buff The start, length and ASCII values are stored in this buffer. * The buffer must be therefore at least the size of Integer.MAX_VALUE + 2. * buff.start stores the offset of the first ASCII character. * buff.length stores the length of the ASCII character string. * Strings are written to the end of the buffer.ascii array. * @param i MUST BE POSITIVE. This is not tested by the method. Stuff * will explode in spectacular ways if you pass this routine a negative * integer. */ static void fastItoS2( AsciiByteBuff buff, int i ) { int index = buff.ascii.length - 1; int q = i; int r;
for(;;) { r = q % 10; q = q / 10; buff.ascii[index--] = digits[r]; if( q == 0 ) break; }
buff.start = (index + 1); buff.slength = (buff.ascii.length - 1 - index); }
private static class AsciiByteBuff { public int start; public int slength; public byte [] ascii; }
private static byte [] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
} ----------------------------------------------------------------
Yes, it's quite a bit longer than the C version, but by rewriting most of it into a 'performance package' (presumably with additional methods for other, similar operations), the remaining code could be written in not much more lines than the C one. (The fact that no one [as far as I know] has written such a performance package probably means that there hasn't been a perceived need for it!)
Performance with a single run (to match the C version) through the key code (SUN's JDK 1.6):
--------------------------------------------------------------- ->time java -server T1 1000000 1 | cat >/dev/null Bench 0 Took 0.251 seconds java -server T1 1000000 1 0.31s user 0.03s system 88% cpu 0.384 total cat > /dev/null 0.00s user 0.02s system 5% cpu 0.333 total ---------------------------------------------------------------
while on the same machine, using gcc 4.1.1 (-O4) the original C version gives:
--------------------------------------------------------------- ->time ./t1 | cat >/dev/null ./t1 0.29s user 0.02s system 97% cpu 0.319 total cat > /dev/null 0.00s user 0.02s system 6% cpu 0.318 total -> ---------------------------------------------------------------
And to show what Hot Spot can do, let's give it a chance to really kick in (it doesn't take long):
--------------------------------------------------------------- ->time java -server T1 1000000 20 | cat >/dev/null Bench 0 Took 0.239 seconds Bench 1 Took 0.195 seconds Bench 2 Took 0.194 seconds Bench 3 Took 0.199 seconds Bench 4 Took 0.198 seconds Bench 5 Took 0.207 seconds Bench 6 Took 0.194 seconds Bench 7 Took 0.192 seconds Bench 8 Took 0.194 seconds Bench 9 Took 0.194 seconds Bench 10 Took 0.196 seconds Bench 11 Took 0.192 seconds Bench 12 Took 0.193 seconds Bench 13 Took 0.194 seconds Bench 14 Took 0.194 seconds Bench 15 Took 0.198 seconds Bench 16 Took 0.201 seconds Bench 17 Took 0.193 seconds Bench 18 Took 0.194 seconds Bench 19 Took 0.195 seconds java -server T1 1000000 20 4.01s user 0.04s system 99% cpu 4.083 total cat > /dev/null 0.00s user 0.01s system 3% cpu 0.319 total -> ---------------------------------------------------------------
Whereas 20 runs of the C version would produce no significant difference from the original. (Feel free to instrument the C version in the same way.)
Does this prove Java is faster than C? Of course not. I imagine one could do similar hand optimizations on the C side to get a quicker version there as well (or find a better C compiler!). In fact, I'm *sure* one could also write a similar 'performance package' for C...
But it does help show that Java isn't inherently as slow as some would claim.
(If someone who's not as cheap as I am has access to JET, I'd *love* to see what JET does with this code [and the original Java version].)
 Signature Steve Wampler -- swampler@noao.edu The gods that smiled on your birth are now laughing out loud.
Steve Wampler - 09 Dec 2007 17:36 GMT > And to show what Hot Spot can do, let's give it a chance to really kick > in (it doesn't take long): [quoted text clipped - 8 lines] > Took 0.194 seconds > Bench 3 Just for fun, I decided to see what happens if the program has to produce more lines of output (10,000,000 instead of 1,000,000). This allows the effect of Hot Spot to show up more in a single run:
-------------------------------------------------------------- ->time java -server T1 10000000 1 | cat >/dev/null Bench 0 Took 2.07 seconds java -server T1 10000000 1 1.92s user 0.12s system 92% cpu 2.205 total cat > /dev/null 0.01s user 0.13s system 6% cpu 2.154 total --------------------------------------------------------------
And, after modifying the C version to produce 10,000,000 lines (still with Gcc4.1.1 -O4):
-------------------------------------------------------------- ->gcc4 -O4 t1.c -o t1 ->time ./t1 | cat >/dev/null ./t1 3.06s user 0.15s system 98% cpu 3.272 total cat > /dev/null 0.01s user 0.09s system 3% cpu 3.271 total --------------------------------------------------------------
 Signature Steve Wampler -- swampler@noao.edu The gods that smiled on your birth are now laughing out loud.
Jon Harrop - 10 Dec 2007 00:23 GMT > Whereas 20 runs of the C version would produce no significant difference > from the original. (Feel free to instrument the C version in the same > way.) There is absolutely no evidence whatsoever that Hotspot has improved anything in these results. You first run warms the cache (just as it does in C) and you second run in Java jumped virtually to the fastest of all of your results (that was even identical to your last run).
> But it does help show that Java isn't inherently as slow as some would > claim. The claim can equally well be taken as "Java is prohibitively difficult to optimize". Real programs often won't afford 10x code bloat to get decent performance.
 Signature Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?u
Steve Wampler - 10 Dec 2007 02:25 GMT >> Whereas 20 runs of the C version would produce no significant difference >> from the original. (Feel free to instrument the C version in the same [quoted text clipped - 4 lines] > in C) and you second run in Java jumped virtually to the fastest of all of > your results (that was even identical to your last run). Good guess, but wrong. Here's a test with Hotspot turned off (I went back to 1,000,000 output lines because I'm impatient):
-------------------------------------------------------------- ->java -Xint -server T1 1000000 5 | cat >/dev/null Bench 0 Took 2.497 seconds Bench 1 Took 2.453 seconds Bench 2 Took 2.432 seconds Bench 3 Took 2.432 seconds Bench 4 Took 2.427 seconds -> --------------------------------------------------------------
Notice that: (a) the times are a *lot* slower, and (b) there is no significant performance change.
The HotSpot optimizer comes into play quite quickly, which is why even the *first* benchmark run is faster with it turned on - it has *already* sped things up (the first run is slower because the first few 'un-optimized' loop iterations are dragging its average down.
Somehow, though, I suspect I'm wasting my time... Maybe people other than Jon will find this illuminating.
 Signature Steve Wampler -- swampler@noao.edu The gods that smiled on your birth are now laughing out loud.
Lew - 10 Dec 2007 03:25 GMT > Somehow, though, I suspect I'm wasting my time... Maybe people > other than Jon will find this illuminating. Maybe people other than Jon will find this illuminating also: <http://java.sys-con.com/read/45250.htm>
 Signature Lew
Jon Harrop - 10 Dec 2007 09:05 GMT > Good guess, but wrong. I was stating a fact.
> (b) there is no significant performance change. There was so significant performance change beyond cache warming last time either, which was my point.
 Signature Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?u
Steve Wampler - 10 Dec 2007 14:56 GMT >> Good guess, but wrong. > [quoted text clipped - 4 lines] > There was so significant performance change beyond cache warming last time > either, which was my point. So, you're claiming that if someone instrumented the C version to match the Java one (i.e. allow multiple runs of the 'benchmark' from within the same process, with times for each internal run) you'd see the same performance profile for the 1000000xN line case as with the Java?
Out of curiosity, what is your explanation for the fact that the performance is almost an order of magnitude slower when HotSpot is turned off?
 Signature Steve Wampler -- swampler@noao.edu The gods that smiled on your birth are now laughing out loud.
Jon Harrop - 10 Dec 2007 22:43 GMT >>> Good guess, but wrong. >> [quoted text clipped - 9 lines] > same process, with times for each internal run) you'd see the same > performance profile for the 1000000xN line case as with the Java? Exactly.
> Out of curiosity, what is your explanation for the fact that the > performance is almost an order of magnitude slower when HotSpot is turned > off? Missing optimizations.
 Signature Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?u
Steve Wampler - 11 Dec 2007 03:25 GMT >> Out of curiosity, what is your explanation for the fact that the >> performance is almost an order of magnitude slower when HotSpot is turned >> off? > > Missing optimizations. I'm confused by this. Earlier you said there was no evidence of Hotspot helping long running programs. Are you saying that Hotspot helps even short running programs - so as I shorten the loop it will continue to help? (I'm uncertain of how to test this outside of a profiler, as it may have to get quite short to see a change - and measurement noise may dominate when down to a few loop instances. I can run many repeats of the shorter loops, I suppose.)
 Signature Steve Wampler -- swampler@noao.edu The gods that smiled on your birth are now laughing out loud.
Jon Harrop - 11 Dec 2007 10:05 GMT >>> Out of curiosity, what is your explanation for the fact that the >>> performance is almost an order of magnitude slower when HotSpot is [quoted text clipped - 9 lines] > may dominate when down to a few loop instances. I can run many repeats > of the shorter loops, I suppose.) Exactly. I see no evidence that HotSpot is doing anything different to a normal static optimizer, i.e. it does not appear to incrementally improve the performance of the Java code as it runs.
 Signature Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?u
Steve Wampler - 11 Dec 2007 12:45 GMT > Exactly. I see no evidence that HotSpot is doing anything different to a > normal static optimizer, i.e. it does not appear to incrementally improve > the performance of the Java code as it runs. I'm not sure how to tell, either. For example, in the following run, *something* is causing a performance bump somewhere between 10 and 20 millions lines of output - which is well after the effect you were attributing to cache warming earlier, which would have been taking place between 0 and 1 millions lines output. Is this the result of HotSpot kicking in again after 2-4 seconds of running? I have no simple way of telling but something is happening and it happens consistently (I've seen it every repeat of this run).
->time java -server T1 10000000 20 >/dev/null Took 2.067 seconds Took 2.131 seconds Took 1.634 seconds Took 1.631 seconds Took 1.625 seconds Took 1.622 seconds Took 1.632 seconds Took 1.628 seconds Took 1.621 seconds Took 1.625 seconds Took 1.626 seconds Took 1.615 seconds Took 1.616 seconds Took 1.621 seconds Took 1.63 seconds Took 1.627 seconds Took 1.625 seconds Took 1.621 seconds Took 1.63 seconds Took 1.613 seconds java -server T1 10000000 20 > /dev/null 33.45s user 0.09s system 99% cpu 33.581 total
 Signature Steve Wampler -- swampler@noao.edu The gods that smiled on your birth are now laughing out loud.
Lew - 11 Dec 2007 14:37 GMT >> Exactly. I see no evidence that HotSpot is doing anything different to a >> normal static optimizer, i.e. it does not appear to incrementally improve [quoted text clipped - 32 lines] > java -server T1 10000000 20 > /dev/null 33.45s user 0.09s system 99% > cpu 33.581 total It doesn't do much good to present facts before the intellectually dishonest, as our trollish Cambridge God, er, Don, Mr. Harrop is.
 Signature Lew
Roger Lindsjö - 11 Dec 2007 15:23 GMT Making the loops smaller it is easier to show that "something" happens. I ran it with 10000000 iterations instead, and then the output showed: Bench 15 Took 0.229 seconds Bench 16 Took 0.228 seconds Bench 17 Took 0.228 seconds Bench 18 Took 0.105 seconds Bench 19 Took 0.107 seconds Bench 20 Took 0.106 seconds Bench 21 Took 0.107 seconds
So, after 18 iterations the time for each loop is halved. I'm pretty sure this is not a cache warmup (it it is the coldest cache I have ever seen ;-) )
Didn't manage to get compiler debugging to output anything, will se if I can get some more info.
//Roger Lindsjö
Jon Harrop - 11 Dec 2007 15:41 GMT > Making the loops smaller it is easier to show that "something" happens. > I ran it with 10000000 iterations instead, and then the output showed: [quoted text clipped - 16 lines] > sure this is not a cache warmup (it it is the coldest cache I have ever > seen ;-) ) Yes, this is much more compelling evidence of something happening during running (assuming it is repeatable). However, is the >2x performance improvement that you're seeing consistent with Steve's findings that improved by <20%?
 Signature Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?u
Roger Lindsjö - 11 Dec 2007 19:47 GMT >> Making the loops smaller it is easier to show that "something" happens. >> I ran it with 10000000 iterations instead, and then the output showed: [quoted text clipped - 21 lines] > improvement that you're seeing consistent with Steve's findings that > improved by <20%? If I'm understanding you correct, you are asking if I get similar results as above but using the same number as Steven did? Yes, this is what I got: java T1 10000000 10 > out Bench 0 Took 2.928 seconds Bench 1 Took 2.358 seconds Bench 2 Took 1.124 seconds Bench 3 Took 1.125 seconds Bench 4 Took 1.155 seconds Bench 5 Took 1.166 seconds Bench 6 Took 1.13 seconds
After that it seems to stay below 1.2 seconds. So the jump happens between 10 and 20 million, which is consistent with my previous run. It still annoys me that -XX:-PrintCompilation does not actually print anything. The Java I'm using is: java version "1.6.0_02" Java(TM) SE Runtime Environment (build 1.6.0_02-b05) Java HotSpot(TM) Server VM (build 1.6.0_02-b05, mixed mode) Maybe I'll try the latest. I'm quite sure I have gotten output from previous JVMs of when compilation/recompilation occurred and how long time it took. Too bad I can't remember how.
//Roger Lindsjö
Mark Thornton - 11 Dec 2007 19:37 GMT > Exactly. I see no evidence that HotSpot is doing anything different to a > normal static optimizer, i.e. it does not appear to incrementally improve > the performance of the Java code as it runs. It does inlining of virtual methods which static optimisers usually don't do. However none of the micro benchmarks seen here will exhibit that effect. So quite a bit of it optimisation effort is directed at OO programs. In these cases it can show significant benefits relative to C++, which do not appear in essentially functional examples.
Mark Thornton
Gordon Beaton - 10 Dec 2007 15:28 GMT > ->java -Xint -server T1 1000000 5 | cat >/dev/null Warning: cat used with no arguments. Costs a process, gains you nothing.
Do this instead:
java -Xint -server T1 1000000 5 >/dev/null
See also: http://partmaps.org/era/unix/award.html#cat
Caveat: I haven't been following the discussion.
/gordon
--
Steve Wampler - 10 Dec 2007 15:51 GMT >> ->java -Xint -server T1 1000000 5 | cat >/dev/null > [quoted text clipped - 4 lines] > > java -Xint -server T1 1000000 5 >/dev/null I understand. However, I was trying to mimic what might be one use of the java app - as the front end to a pipe. So I used the pipe to avoid people complaining that sending the output directly to /dev/null was different than sending it to a file [which is true, but not relevant].
 Signature Steve Wampler -- swampler@noao.edu The gods that smiled on your birth are now laughing out loud.
Steve Wampler - 10 Dec 2007 02:34 GMT > The claim can equally well be taken as "Java is prohibitively difficult to > optimize". Real programs often won't afford 10x code bloat to get decent > performance. In both the C and Java examples, the performance bottleneck is in the code that does the output. Printf is a library function that does all sorts of fascinating things to get good performance. If you moved that code into the main routine you'd see a remarkable amount of code bloat. In the Java case, you could just as well take the code bloat you complain about and put into a separate package, just as printf is found in a library. Apparently there hasn't been much demand that this be done. I suspect one could get it so the Java main could make a single method call on this package, just as the printf is a single function call - should one find it worthwhile to do so.
 Signature Steve Wampler -- swampler@noao.edu The gods that smiled on your birth are now laughing out loud.
Mark Thornton - 08 Dec 2007 23:08 GMT >> ; >>> Note: This has the overhead of character encoding. Your C example does [quoted text clipped - 5 lines] > No, char encoding is not an adequate explanation of a 15x slowdown. This is > Java being very poor at buffering. Java is not poor at buffering it just doesn't do it by default. In the specific case of System.out it is buffered, but that buffer is flushed at the end of every line. There are good reasons why this behaviour is often useful, just not in this context.
Mark Thornton
Jon Harrop - 08 Dec 2007 21:49 GMT >> I bet that the JVM loading and startup time is very important with your >> test. [quoted text clipped - 17 lines] > user 0m0.040s > sys 0m0.032s Indeed, startup time is the number one mis-attribution posted by Java advocates as a way around explaining very poor performance. As you can see, it was quite wrong to blame startup time on this benchmark.
 Signature Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?u
Stefan Ram - 08 Dec 2007 20:37 GMT >So it's not this particular code which is slow, the timing >technique is not adequate. May be it is. For example, when one wants to write an echo command for the command line, to be used like:
echo "Hello world!"
one does often not use Java for a reason.
On the other hand, people start to consider to write a JVM in Java, because C is too slow:
http://www.adam-bien.com/roller/abien/entry/when_c_becomes_too_slow
And then:
»if you run across benchmarks of any kind that show JRuby running slower than Ruby 1.8.x, we'd appreciate you filing them as bugs«
http://groups.google.com/group/jruby-developers/msg/9fd1ab9664a1a36b?dmode=sourc e&_done=%2Fgroup%2Fjruby-developers%2Fmsg%2F9fd1ab9664a1a36b%3Fdmode%3Dsource&ou tput=gplain
Eric Sosman - 08 Dec 2007 20:24 GMT > Hello, > > I would like to show to somebody how different languages look like by > doing a very simple case. > I was very surprised by the poor performance of the java version ! > [...] Congratulations! You have discovered that Java is a poor choice of language if you plan to do something silly, pointless, and stupid. Please report your findings to Sun, and file a Request For Enhancement to optimize Java for better performance on silly, pointless, and stupid programs. (Don't be too surprised, though, if the Javafolk attach a relatively low priority to the RFE; they're more interested in getting Java to work well for useful programs. That's a clear case of bias against the average programmer, don't you think?)
"And the wheel," said the Captain, "what about this wheel thingy? It sounds a terribly interesting project."
"Ah," said the marketing girl, "well, we're having a little difficulty there."
"Difficulty?" exclaimed Ford. "Difficulty? What do you mean, difficulty? It's the single simplest machine in the entire Universe!"
The marketing girl soured him with a look. "All right Mr. Wiseguy," she said, "you're so clever, you tell us what color it should be."
 Signature Eric Sosman esosman@ieee-dot-org.invalid
Olivier Scalbert - 08 Dec 2007 20:44 GMT Hi,
Thanks for your congratulations !
But do you have a real explanation ?
And by the way, can you explain me, why it was a silly, pointless and stupid program ?
For me, it is only a small program, nothing else.
>> Hello, >> [quoted text clipped - 27 lines] > Mr. Wiseguy," she said, "you're so clever, you tell us > what color it should be." Eric Sosman - 08 Dec 2007 21:26 GMT > [...] > And by the way, can you explain me, why it was a silly, pointless and > stupid program ? Let's apply this test: How valuable is the output of this program? How many backup copies did you make? How many other programs used this output as their input?
If you made no backups and fed the output to no other programs, as I suspect, then by your own actions you have declared the value of the program's output to be zero. A program that produces nothing of value meets my definition of silly, pointless, and stupid.
 Signature Eric Sosman esosman@ieee-dot-org.invalid
Jon Harrop - 08 Dec 2007 21:50 GMT > Let's apply this test: How valuable is the output of > this program? How common is IO?
 Signature Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?u
Olivier Scalbert - 08 Dec 2007 21:54 GMT >> [...] >> And by the way, can you explain me, why it was a silly, pointless and [quoted text clipped - 9 lines] > program that produces nothing of value meets my definition > of silly, pointless, and stupid. Ok, still no technical info, just blabla on what is silly, pointless. I do not appreciate people, that are "donneurs de leçons" (moralist people that give lesson).
Using java daily since many many years from embedded platform to application server, I have never noticed that java can detect silly programs from very intelligent one !
For your info, by adding few lines of code, this program will generate huge csv files (several billions of lines). Theses files will be used to test the import functionality of different databases.
Lew - 08 Dec 2007 21:57 GMT >>> [...] >>> And by the way, can you explain me, why it was a silly, pointless and [quoted text clipped - 20 lines] > huge csv files (several billions of lines). Theses files will be used to > test the import functionality of different databases. Aside from the emotionally-loaded pejoratives and all the /ad hominem/ flaming, the fact remains that your benchmark did not compare the same behaviors and is not indicative of the relative speeds of Java vs. the other platforms.
 Signature Lew
Jon Harrop - 08 Dec 2007 21:54 GMT > Aside from the emotionally-loaded pejoratives and all the /ad hominem/ > flaming, the fact remains that your benchmark did not compare the same > behaviors and is not indicative of the relative speeds of Java vs. the > other platforms. On the contrary, Olivier's test is simple and flawless. Can you make the Java nearly as fast as the C? Feel free to not use unicode, or does Java have poor support for everything else?
 Signature Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?u
Steve Wampler - 09 Dec 2007 00:42 GMT > On the contrary, Olivier's test is simple and flawless. Can you make the > Java nearly as fast as the C? Feel free to not use unicode, or does Java > have poor support for everything else? Well, if you like such simple and flawless tests, here's another one. Of course, this one is (on my machine) over 700 times *faster* in Java than in C. So, why does C have such poor performance - surely it's been around enough that optimizers should be able to as well as Java on such a simple test.
(By the way, the 700 is pretty arbitrary - I could just as easily make it 700,000 times faster in Java!)
*This is why such 'simple, flawless' tests are so flawed*...
------------ C version and time --- #include <stdio.h>
int main(int ac, char **av) { char *s = malloc(1024*1024); int i = 0; for (i = 0; i < 1024*1023; ++i) { s[i] = 'a'; } s[++i] = '\0';
int k = 0; int j = 0; int n = 0; for (n = 0; n < 100; ++n) { for (j = 0; j < 1024*1024*1024; ++j) { k = strlen(s); } } printf("s has %ul (%u) characters\n", strlen(s), k); } ->gcc -O4 t1.c -o t1 ->time t1 s has 1047552l (1047552) characters t1 113.74s user 0.25s system 99% cpu 1:54.18 total -> ------------------------------------------------------------
--------------------------------- Java version and time --- class T1 {
public static void main(String[] args) { StringBuilder s = new StringBuilder(1024*1024); for (int i = 0; i < 1024*1023; ++i) { s.append('a'); } int k = 0; for (int n = 0; n < 100; ++n) { for (int i = 0; i < (1024*1024*1024); ++i) { k = s.length(); } } System.out.println("s has "+s.length()+" ("+k+") characters."); } } ----------------------------------------------------------------
 Signature Steve Wampler -- swampler@noao.edu The gods that smiled on your birth are now laughing out loud.
Steve Wampler - 09 Dec 2007 00:44 GMT > --------------------------------- Java version and time --- > class T1 { [quoted text clipped - 14 lines] > } > ---------------------------------------------------------------- Sigh. The test may be simple and flawless, but my cutting and pasting wasn't. Here's the missing part: --------------------------------------------------------- ->javac T1.java ->time java -server T1 s has 1047552 (1047552) characters. java -server T1 0.12s user 0.04s system 101% cpu 0.158 total -> ----------------------------------------------------------------
 Signature Steve Wampler -- swampler@noao.edu The gods that smiled on your birth are now laughing out loud.
Jon Harrop - 09 Dec 2007 11:29 GMT > Sigh. The test may be simple and flawless, but my cutting and pasting > wasn't. Here's the missing part: [quoted text clipped - 5 lines] > -> > ---------------------------------------------------------------- Here, your C can run this benchmark 20 times before your Java has even started.
 Signature Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?u
George Neuner - 09 Dec 2007 06:35 GMT >> On the contrary, Olivier's test is simple and flawless. Can you make the >> Java nearly as fast as the C? Feel free to not use unicode, or does Java [quoted text clipped - 58 lines] > } >---------------------------------------------------------------- Again not comparing like programs. Java knows the length of the string at each point whereas C has to recompute it every time you ask for it.
Each approach has drawbacks: Java imposes an arbitrary limit on string length and C has a performance issue when it needs to determine the length.
George -- for email reply remove "/" from address
Lew - 09 Dec 2007 06:55 GMT > Again not comparing like programs. Java knows the length of the > string at each point whereas C has to recompute it every time you ask [quoted text clipped - 3 lines] > length and C has a performance issue when it needs to determine the > length. Language Wars are like Editor Wars. George, your comment is nicely balanced, as a few others' have been, pointing out that different languages have different strengths.
This hardly refutes Steve Wampler's point, indeed, it validates it. He was pointing out that one can easily construct a benchmark that exploits the difference(s) between languages to prove whatever point, either side, one wishes to make. A good knowledge of the different tradeoffs between languages lets one construct a benchmark that exploits a strength in one language (Java in his case) that is a weakness in another (C), with respect to what the benchmark measures.
He was also subtly making the point that the OP was "again[,] not comparing like programs".
I like Java not for its speed, which is plenty fast enough in the real world, but for its features as a language and the richness of the API, and not incidentally, for the abundance of job opportunities. In particular, its fundamental architecture for portability, network awareness (anyone remember "The network is the computer"?), inherent multi-threaded power, dynamic nature (sure, reflection is dangerous, but shoo! it's powerful!) and yet, perhaps paradoxically, its straightforwardness make for an extremely useful development platform.
 Signature Lew
George Neuner - 10 Dec 2007 19:46 GMT >> Again not comparing like programs. Java knows the length of the >> string at each point whereas C has to recompute it every time you ask [quoted text clipped - 7 lines] >in his case) that is a weakness in another (C), with respect to what the >benchmark measures. Absolutely. I understood that Steve's program was intentionally constructed to favor Java over C - I was redundantly pointing out that it was mirroring the mistake made by the OP.
>I like Java not for its speed, which is plenty fast enough in the real world, > but for its features as a language and the richness of the API, and not >incidentally, for the abundance of job opportunities. Java is OK. I have a number of issues with it including syntax, organization, and the fact that it religiously enforces OO which IMO is not an optimal programming model for many problems. While I am perfectly comfortable working in OO (pure or not), I prefer languages that let me mix different programming styles more freely.
>network awareness (anyone remember "The network is the computer"?) Actually I do. AFAIC Java is only mediocre in this regard. Its marshalling support is good, but support for easy computation migration is lacking - replicating an entire application is not always desirable and dynamically loading a shitload of classes to relocate a computation is often impractical.
George -- for email reply remove "/" from address
RedGrittyBrick - 11 Dec 2007 10:03 GMT > Java is OK. I have a number of issues with it including syntax, > organization, and the fact that it religiously enforces OO which IMO > is not an optimal programming model for many problems. While I am > perfectly comfortable working in OO (pure or not), I prefer languages > that let me mix different programming styles more freely. Interesting. When I started learning Java, my biggest problem was that I felt I was writing purely procedural code in Java. I tended to have classes with only static methods.
Lew - 11 Dec 2007 14:41 GMT >> Java is OK. I have a number of issues with it including syntax, >> organization, and the fact that it religiously enforces OO which IMO [quoted text clipped - 5 lines] > felt I was writing purely procedural code in Java. I tended to have > classes with only static methods. Interesting to me, too, as I have found that one of the singular strengths of Java is its insistence on OO programming.
I've noticed that people often prefer to take shortcuts when writing code - breaking the OO style being one such. The problem is the concomitant reduction in maintainability and stability of the code. As a good part of my career has been to pick up after absent programmers, I am quite sensitive to the true lifetime cost of such shortcuts.
What seems reasonable to an author, especially a highly-skilled one as, presumably, Mr. Neuner is, will often cause trouble for those who follow, as teams hire a range of skills and experience.
 Signature Lew
Jon Harrop - 11 Dec 2007 15:26 GMT > Interesting to me, too, as I have found that one of the singular strengths > of Java is its insistence on OO programming. |
|