On Wed, Jul 26, 2006 at 11:26:45PM +0900, Charles O Nutter wrote: > On 7/26/06, Peter Hickman <peter@semantico.com> wrote: > > > >Charles O Nutter wrote: > >> I'll lob a couple of grenades and then duck for cover. > >> > >> - Write it in C is as valid as write it in Java (as someone else > >> mentioned). > >> Java is at least as fast as C for most algorithms. > > > >As someone who is paid to program in Java I very seriously doubt this. > >However I will write a Java version of the code and time it. It should > >be interesting to say the least. > > Doubt all you like.
Full disclaimer included: As someone who is NOT paid to program in Java, and in fact finds Java rather odious, and would rather write code in almost anything else that isn't the annoyance factor equivalent of VB, I too doubt it. Aside from not being paid to program in Java, though, I have played with Java code, I have researched Java performance characteristics extensively in the performance of job tasks, I've looked at hundreds of benchmarks over the years, and I know a fair bit about programming language interpreters and parsers in the abstract. The end result is that characterizing Java as "at least as fast as C" in most cases and faster in many other cases sounds like a load of (perhaps well-meaning) hooey to me.
> > >We are talking about two different things here. I was talking about > >performance as being the number 1 absolute top priority, you are talking > >about 'reasonable performance'. As far as I am concerned for those > >scripts that I don't convert to C Perl, Ruby and Python are fast enough. > >Other people think that they are not, they seem to expect the sort of > >performance C gives when they write things in a scripting language. I > >think that they are barking. > > They may be hoping for the impossible, but that doesn't mean they shouldn't > hope and that doesn't mean they shouldn't be frustrated when the stock > answer is "write it in C". The fact that Ruby and other dynamic languages > are not as fast as compiled C is not the language's fault or the user's > fault...it's an implementation flaw. It certainly may be a flaw that can't > be fixed, a problem impossible to solve, but there's nothing about a > language's design that should necessitate it being slower than any other > language. Perhaps we haven't found the right way to implement these > languages, or perhaps some of us have and others just aren't there yet. > Either way, it's not the language that's eventually the problem...it's > simply the distance from what the underlying platform wants to run that's an > issue. C is, as they put it, closer to "bare metal", but only because C is > little more than a set of macros on top of assembly code. If the underlying > processor ran YARV bytecodes, I doubt Ruby performance would be a concern.
I'd say "yes and no" to that. There are things about Ruby -- things that I absolutely would not change -- that necessitate slower runtime execution. For instance, for Ruby to work as specced, it needs dynamic typing, which is simply slower in execution, because typing becomes a part of execution. Static typing doesn't require types to be set at execution: they can be set at compile-time, because they don't have to change depending on runtime conditions. Thus, you add an extra step to runtime execution a variable (pardon the pun) number of times. It's an unavoidable execution-speed loss based on how the Ruby language is supposed to work, and it's a characteristic of Ruby that I absolutely would not throw away for better runtime performance. Because of this, of course, it is effectively impossible to use persistent compiled executables for Ruby to solve the runtime execution performance gap that is introduced by dynamic typing as well. C'est la vie.
Other, similar difficulties arise as well. Ultimately, it's not the fact that it's an interpreted language that is the problem. That can be solved via a number of tricks (just-in-time compilation similar to Perl, bytecode compilation, or even simply writing a compiler for it, for example), if that's the only problem. The main problem is that, like Perl, Python, and various Lisps, it's a dynamic language: it can be used to write programs that change while they're running. To squeeze the same performance out of Ruby that you get out of C, you'd have to remove its dynamic characteristics, and once you do that you don't have Ruby any longer.
[Quoted text hidden]
|
|