Depends on if you mean faster 1 time, or faster after running for a time. Java has a much higher startup overhead making it unsuitable for programs that must run quickly and then exit. However JIT will speed up things that need to be run for long periods of time, including compiling sections of code that are really frequently used all the way down to the bare metal. Ive seen JIT'd code that blew away c++ at O3 when it comes to operations that need to be constantly running for a long period of time. For instance I have an app that needs to pre-generate 1M ecliptic curve keypairs at a time for offline storage (don't ask why). In C++ with O3 the runtime is a little over an hour on a Quad core CPU. In Java that same application generates 100,000 in it's first 20 minutes and the remaining 900,000 in next 25 minutes on the same machine. The difference is that Java has found an efficient path through the code that could only be found after the JIT watched it running for awhile.
The C++ implementation took me 2 days to write (I'm a bit rusty). The java implementation took me less time to write than it took to run. What costs more CPU time or developer time? BTW 90% of statistics are made up on the spot :) On Wed, May 1, 2013 at 10:10 PM, Barry Roberts <[email protected]> wrote: > in Java: > > StringBuffer.reverse() > > On Wed, May 1, 2013 at 9:08 PM, Sasha Pachev <[email protected]> wrote: > > First, let's say thanks to Matt for providing more employment > > opportunities for us. We are good at the technical aspect, but most of > > us are not so good at business. We need to be thankful for the people > > that are good at business and remember that we need them as much as > > they need us. Perhaps we need them even more, because without us they > > would find another business avenue, but without thriving businesses > > our skills would not be worth much. > > > > Matt - did a guy with 10+ years of C experience seriously could not > > reverse a string, and you've met more than one? Was he bad at > > interviewing, did you try putting him in the corner with a text editor > > and a compiler to see if he could do it? > > > > Let me see if I can do it while thinking in e-mail mode: > > > > int str_rev(char* s) > > { > > char* s_end; > > char tmp; > > > > if (!s) return -1; > > > > s_end = s + strlen(s) - 1; > > > > for (; s < s_end; s++, s_end--) > > { > > tmp = *s; > > *s = *s_end; > > *s_end = tmp; > > } > > > > return 0; > > } > > > > Ok, for a fun challenge, assuming the above actually compiles and runs > > without a bug, can somebody make it go faster and prove that it is > > indeed faster with a benchmark? Let's say that we compile the above > > with -O3 and you get to compile your code with -O3 as well. > > > > Now for a really fun challenge, can you make a Java version that is > > faster than the above and prove that it is? BTW, I do not know how. > > > > -- > > Sasha Pachev > > > > Fast Running Blog. > > http://fastrunningblog.com > > Run. Blog. Improve. Repeat. > > > > /* > > PLUG: http://plug.org, #utah on irc.freenode.net > > Unsubscribe: http://plug.org/mailman/options/plug > > Don't fear the penguin. > > */ > > /* > PLUG: http://plug.org, #utah on irc.freenode.net > Unsubscribe: http://plug.org/mailman/options/plug > Don't fear the penguin. > */ > /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
