For performance, write it in C - Part 2, comparing C, Ruby a

On Sat, Jul 29, 2006 at 12:21:48AM +0900, Charles O Nutter wrote:

The limit is not arbitrary; it’s to allow the JVM to maintain certain
constraints over the memory used by incoming class definitions, since
they’re typically not garbage collected. It would not be advisable to allow
loading an extremely large class definition into permanent memory space,
eating up the entirety of the heap. Put your gigantic data in a separate
file and load it at runtime.

I think you might be misunderstanding the usage of “arbitrary” here. An
arbitrary limit, in uses such as this, is one where someone picks a
“magic number” as a limit.

I have no fear of C. I have fear of making C work everywhere, which I do not
have to worry about with either Ruby or Java. I also have a fear of C
fanboys giving up on improving Ruby and always advising that people drop to
C for their problems.

If you really believe there’s no worry about portability of Java code,
you haven’t been dealing with multiplatform, multi-VM Java deployments
enough.

Kroeger, Simon (ext) wrote:

cheers

Simon

Startup time varies with the classes that are being loaded, this hello
world comparison is a wild assed guess
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=hello&lang=all

Charles O Nutter wrote:

Not bad, really, but not even as good as the bogus Java numbers below.
The Java numbers are what was genuinely produced by the Java system on
my computer. What grounds do you have to call them bogus? State clearly
how to time a Java program in such a way that you will not call it bogus
that can also be applied to the other languages here. Remember the Perl
interpreter must be loaded and the source compiled each time the Perl
version is run, somehow I don’t recall you saying that the Perl numbers
were bogus.

Second, you’re not a very good Java programmer if you didn’t know
about this
limit. Perhaps they didn’t teach you this in Java class in 1992? (a
response
troll, admittedly)

I have never encountered this limit before, but then again I have never
had the urge to do this sort of program in Java, I used it to do ALife
and other simulations. How about you submit your version of the problem
in Java, I can then run it on my system in the manner you will describe
so that you wont call it ‘bogus’ and we use those timings. If you are
going to question someone’s programming prowess then we can only ask
that the master himself teaches us how to to it properly.

Some versions of Java have taken as much as 15 seconds to start up on
certain platforms, and the startup time on Linux is frequently slower
than
on other platforms. Java 5 on Windows takes perhaps a second to start up
now, primarily because they do use a shared-memory cache of much of the
static data loaded at startup. Of course, it’s not a startup cost of
zero,
but people simply don’t use Java for command-line tools.
Where are you coming from? We use plenty of command line tools that are
written in Java here. Tools to parse, validate and transform XML. Schema
and RelaxNG checkers. There are plenty of command line tools written in
Java that are used daily by people all over the world, where you pulled
the ‘people simply don’t use Java for command-line tools’ from?

I look forward to seeing your code.

On 7/28/06, Peter H. [email protected] wrote:

Isak H. wrote:

When people want ‘speed’ they care about how fast the code runs, not
JVM startup time…
Interesting, so just how to you run a Java program without the JVM
start-up time?

And if you can’t run a Java program without the JVM start-up then your
point is
what exactly?

The problem is that you’re not controlling for that startup time. If you
want to do a comparison of raw number-crunching performance, you can’t
include processing time that’s unrelated. A short list of what’s wrong
with
your benchmark:

  • You include Ruby parse, startup, and init time
  • You include Java startup and init time
  • You include C startup and init time, however insignificant
  • You do not post your code, system configuration, Java, Ruby, GCC, and
    related library versions, Java and Ruby startup parameters, C compiler
    settings, …
  • You expect us to trust that your knowledge of writing efficient code
    in
    Java is without question (although if you’ve been doing it since 1992,
    maybe
    you’re right)
  • You do not take into consideration the delay before runtime JIT
    happens in
    the JVM

Every reputable benchmark or scientific study must provide full access
to
not only test results but to the tests themselves, along with complete
documentation of methodology and process. To hide the mechanism and the
means behind these tests allows you to impose your own handicaps on each
of
the platforms in question to further your point. To allow no rebuttal
via
submissions of “better” Java code implies an obvious bias against that
platform, and your lack of knowlege about how that platform works taints
your results severely.

It’s certainly possible that Java is slower for this particular
algorithm,
even with an optimized version. However your means of benchmarking and
method of communicating results calls the entirety of your email into
question.

M. Edward (Ed) Borasky wrote:

So what is the source of “fear of C?”

I’m pretty sure it’s manual memory management. Pointers are fun and
dangerous. C is a great language, it gives you enough power to shoot
yourself in the foot.

In addition, I hear it eats babies.
–mark

Sorry to jump into discussion, but I am wondering once again (I cannot
remember the real number) what is the purpose of this “benchmark”?

Showing that your special algorithm is better implemented/run in a
native executable? I could have told you so from the beginning. Have
you tried also with compiled Pascal? (or I don’t know what else).

Or is it the fact that after working in Java since '92 (???) you have
find out about the JVM startup penalty and that any decent benchmark
would not account for that (only in case you are compairing JVM
startup times)? Should I also tell you that the JVM can be configured?
Or that you must run the code a couple of times before, because the
JVM will optimize the bytecode?

However, I must agree, I may have sound rude. Way too rude, for this
completely unuseful thread. Sorry.

./alex

.w( the_mindstorm )p.

On Sat, Jul 29, 2006 at 12:37:20AM +0900, Mike H. wrote:

benchmarks “irrelevant” and “useless” by that argument).

Uh, you start your interpreter/jvm/whatever, get everything started,
then time an operation. it’s certainly not “impossible”

. . . and of course, in Perl (for instance), things like BEGIN blocks
have no relevancy, runtime compilation doesn’t occur . . .

(sarcasm collision imminent)

Peter H. wrote:

Second, you’re not a very good Java programmer if you didn’t know
going to question someone’s programming prowess then we can only ask
written in Java here. Tools to parse, validate and transform XML. Schema
and RelaxNG checkers. There are plenty of command line tools written in
Java that are used daily by people all over the world, where you pulled
the ‘people simply don’t use Java for command-line tools’ from?

I look forward to seeing your code.

Perhaps you could post the 5x5 Java and C programs on your website then
folk like Charles O Nutter can satisfy themselves that the numbers are
not bogus.

Peter H. wrote:

real 0m35.793s
user 0m32.081s
sys 0m0.843s

In another thread Simon Kroger wrote:

real 0m4.703s
user 0m0.015s
sys 0m0.000s

(this is a 2.13GHz PentiumM, 1GB RAM, forget the user and sys timings, but
‘real’ is for real, this is WinXP)

Why is it so much slower on Peter H.'s machine?

M. Edward (Ed) Borasky wrote:

In my younger days, I did a lot of development in assembler languages,
and for many years my main high-level language was FORTRAN. Towards the
end of my FORTRAN days (about 1990) I was still dropping into assembler
for speed, even though the (FORTRAN) compilers were quite good by that
time. C compilers really sucked, especially for numerical applications.

So you know only clunky, crude, archaic languages, the newest
of which dates back to 1973 or earlier. Someday you ought
to move out of the dark ages and program in Ruby.

Now here’s where I’m going to put on my asbestos suit. I think the
difficulty of C development is vastly exaggerated by the fans of
“dynamic/scripting/interpreted” languages! In addition, I think the
difficulty of assembler development is vastly exaggerated

(Note that Eddie is no fan of Ruby.)

One or more of these is true:

  1. You don’t program in Ruby.
  2. You’re not thinking.
  3. You’re not being honest.
  4. You’re simple-minded.

Compared to Ruby, programming in assembly language is very
tedious, very error-prone, very time-consuming, and laden
with a multitude of miniscule details. To a lesser degree,
the same is true of C. And assembly code, of course, is not
portable to another processor.

On 7/28/06, Isaac G. [email protected] wrote:

Perhaps you could post the 5x5 Java and C programs on your website then
folk like Charles O Nutter can satisfy themselves that the numbers are
not bogus.

And the Ruby version please.

On Sat, Jul 29, 2006 at 04:06:52AM +0900, pat eyler wrote:

On 7/28/06, Isaac G. [email protected] wrote:

Perhaps you could post the 5x5 Java and C programs on your website then
folk like Charles O Nutter can satisfy themselves that the numbers are
not bogus.

And the Ruby version please.

While the Ruby version (assuming it’s the same version) was posted to
the list, it would be nice to have them all in the same place. While
you’re at it, you could post the Perl version and whatever other
versions we’ve discussed. I’d do it myself, but for the lack of
availability of the Java version here.

On Fri, Jul 28, 2006 at 08:33:23PM +0900, Pedro C?rte-Real wrote:

case it doesn’t. If what you really wanted to do was calculate this
latin squares thing then the startup time matters. Are there any JVMs
around that keep a shared daemon running for all processes to share so
as to avoid some of the startup time?

It also makes sense to run the algorithm a few times to ensure the JIT
compiler gets the hint that it’s supposed to convert the bytecode to
native code. Otherwise you’re only getting how quickly the bytecode
interpreter can interpret the code rather than the raw speed of the
code.

On Sat, Jul 29, 2006 at 04:20:05AM +0900, William J. wrote:

  1. You don’t program in Ruby.
  2. You’re not thinking.
  3. You’re not being honest.
  4. You’re simple-minded.

Compared to Ruby, programming in assembly language is very
tedious, very error-prone, very time-consuming, and laden
with a multitude of miniscule details. To a lesser degree,
the same is true of C. And assembly code, of course, is not
portable to another processor.

It might be more accurate to say that he’s just reformulated the same
situation those of us who are Ruby fans have described differently –
but in doing so, he doesn’t realize it’s a reformulation, and thinks
he’s correcting us.

foo = :ruby_fan
bar = :eddie
baz = :chad_perrin

foo.says(‘Ruby’s easy to use. C is harder. Assembly is much worse.’)
bar.says(‘Assembly’s okay. C is easy. You just have to be careful.’)
baz.says(‘I guess it depends on your perspective.’)

The problem is:
bar.says(‘You’re all wusses.’).also

On Sat, Jul 29, 2006 at 12:22:05PM +0900, M. Edward (Ed) Borasky wrote:

Well … I’m certainly moving towards Ruby. I just need to unlearn Perl.

Wait – what? Why? Learning R. is making me a better Perlist, and
knowing Perl is helping in my learning of Ruby. Both languages have
their advantages and disadvantages, and both have their place in my
toolkit.

I’ve never subscribed to the “one language” philosophy of programming,
and I don’t get it when people talk as though they do. Was that a joke?

Note the asbestos suit. :slight_smile: I am a fan of Ruby, relative to Perl,
Python, PHP and Java. Ruby is a younger language, so it’s learned from
the mistakes of Perl, Python, PHP and Java. But I don’t get paid to
write Ruby – I get paid to write R and maintain Perl.

Perl has learned from the mistakes of Perl, Python, PHP, Java, and even
Ruby. Wow. You really seem to have it in for Perl.

I’d actually be less inclined to take it amiss if you just disliked
(modern-day standards) high level languages than this pick-and-choose
thing where you like Ruby and hate Chevy – er, I mean Ford. No, wait,
Perl. Seriously, though, reading that email of yours was a bit like
reading those Chevy vs. Ford bumper stickers.

Chad P. wrote:

bar.says(‘Assembly’s okay. C is easy. You just have to be careful.’)
baz.says(‘I guess it depends on your perspective.’)

The problem is:
bar.says(‘You’re all wusses.’).also

Well, no … I’m simply saying that when I was doing it, I did not find
assembly language programming more difficult than programming in a
higher-level language. The last time I wrote assembly code for money was
in 1990, and for fun in 1995. For those Rubyists who say, “Ruby has made
programming fun again,” well, it’s always been fun when I got paid and
my code got used, or when I was building something for myself. The
language has never mattered.

Ruby is a very well-designed higher-level language – one of the best
I’ve seen. Which is why I’m learning Ruby and not Python or PHP or Lua
or C#. If my boss came to me Monday and said, “We just bought a company
that wrote a killer app in Lua, and we want you to maintain it,” well,
I’d learn Lua. :slight_smile:

William J. wrote:

So you know only clunky, crude, archaic languages, the newest
of which dates back to 1973 or earlier. Someday you ought
to move out of the dark ages and program in Ruby.

Well … I’m certainly moving towards Ruby. I just need to unlearn Perl.
:slight_smile: I know other languages – Java, C, Forth, Lisp, and Perl – but most
of the programming I do these days is in R. R is hardly a clunky, crude
or archaic language.

Now here’s where I’m going to put on my asbestos suit. I think the
difficulty of C development is vastly exaggerated by the fans of
“dynamic/scripting/interpreted” languages! In addition, I think the
difficulty of assembler development is vastly exaggerated

(Note that Eddie is no fan of Ruby.)

Note the asbestos suit. :slight_smile: I am a fan of Ruby, relative to Perl,
Python, PHP and Java. Ruby is a younger language, so it’s learned from
the mistakes of Perl, Python, PHP and Java. But I don’t get paid to
write Ruby – I get paid to write R and maintain Perl.

Now R versus Ruby is a tough call. :slight_smile:

One or more of these is true:

  1. You don’t program in Ruby.

I do as a hobby, but not for a living.

  1. You’re not thinking.

No … I wanted to challenge some assumptions that have been promulgated
for a long time. In the olden days, it was “assembler for speed,
higher level languages for portability and ease of use.” Now it’s “C for
speed, scripting languages for ease of use.” The portability argument is
gone – C runs everywhere – more places than Java. :slight_smile:

  1. You’re not being honest.

About what?

  1. You’re simple-minded.

About what?

Compared to Ruby, programming in assembly language is very
tedious, very error-prone, very time-consuming, and laden
with a multitude of miniscule details.
I never found it tedious or error prone relative to the high order
languages available to me at the time, and that included FORTRAN, C,
Lisp and Forth. Programming in any language is tedious, error prone,
time consuming and laden with a multitude of minuscule details.

In most cases, assembly language typing is as dynamic as Ruby’s. Most
decent macro assemblers let you do things like meta-programming, parsing
of expressions, domain-specific languages, and a fair amount of
syntactic sugar. As far as I’m concerned, the only legitimate argument
against assembly language is that it is tied to a specific machine
architecture. It isn’t portable.

On Sat, Jul 29, 2006 at 01:18:25PM +0900, M. Edward (Ed) Borasky wrote:

I’ve never subscribed to the “one language” philosophy of programming,
and I don’t get it when people talk as though they do. Was that a joke?
Well … let’s just say I think Ruby is a vast improvement on Perl. I
learned Perl when Perl 4 was the reigning standard. I don’t particularly
like the way Perl 5 does objects and references. I wrote a lot of code in
Perl 4 and I still maintain it, but I wouldn’t write new code in Perl now
that I have Ruby.

I pretty well loathe the Perl object model, and the syntax for
references could use some work, but object oriented programming isn’t
the whole world of programming – and Perl handles a lot of things with
more elegance than most other languages (such as lexical closures, which
are, frankly, slightly less clunky than Ruby’s closures). Ruby does a
lot of things better than Perl, but there are some significant
shortfalls, too.

The notable thing that jumped out at me about Ruby when I discovered it
is this: Between Perl and Ruby, I don’t need to learn Python at all.
I’m awfully glad for that, since Python basically makes my eyes bleed.
Call it a personal failure if you like – it is definitely at least
mostly personal bias – but that’s the way it is.

Most of what I have written in Perl is stuff that Perl (4) is good at.
Regular expressions, extracting numerical data from miscellaneous text
files, arrays and hashes. Ruby has all of that, plus a coherent object
model, a coherent “Enumerable” model, lambdas, blocks, continuations …

Perl’s unnamed blocks/lambdas/subroutines/functions/whatever are
actually more consistent, syntactically, than Ruby’s – though for many
purposes, Ruby’s implementation is slicker. It’s a trade-off that
provides a net win or net lose depending on what I’m doing.

Perl has learned from the mistakes of Perl, Python, PHP, Java, and even
Ruby. Wow. You really seem to have it in for Perl.

I’m simply tired of it … it lacks “elegance”. It’s useful … it’s
been around longer than Ruby, so there are more libraries and packages
for it. It’s not going away. It’s evolving. But Ruby’s not going away
either. Ruby is evolving.

It doesn’t lack elegance. It doesn’t encourage it the same way as Ruby,
but it certainly enables it. In fact, I’d say it enables it more fully
than Python, though encourages it less. Again, a trade-off (though Ruby
does seem to avoid having to trade away much in this case, from what
I’ve seen so far).

that will pick on Python and Java anyway.
PHP’s just too easy to pick on. Seriously. It’s an anemic syntax
wrapped 'round an enormous bucket of functions that seem to have been
chosen for native implementation by way of a dart board. No challenge
in picking on that one.

Frankly, I think one of the biggest reasons Java and, to a slightly
lesser extent, Python get picked on more often than any other
non-Microsoft languages in almost all programming communities is that
both languages’ communities tend to have sort of a “God’s Chosen
Language” sense of entitlement – not universally, but just prominently
enough that people tend to generalize. Stereotyping both Java and
Python, each in its own way, as inspiring a community of zealots is just
an obvious thing to do when looking for a language to disparage. It’s
probably quite unfair in both cases, of course. In any case, I see
hints of one-true-language-ism in every language community, sometimes
more obnoxiously than at other times (including here).

Python’s a great language, in principle, and is reportedly a great
language in practice for those whose proclivities it suits. It doesn’t
suit mine, so I’ll stick to Ruby and Perl. Java . . . well, let’s just
say that as far as I can tell it’s not nearly as great a language as
some seem to think. I’d rather use Java than Visual Basic, but beyond
that there isn’t much competition with Java for its low ranking in my
hierarchy of preferred languages.

I’m sure there are some here who’ll use that statement as an excuse to
dismiss anything I say about Java or Python from here on out, of course,
and I’m not entirely sure I won’t catch some flak up front but, hey,
full disclosure an’ all.

Despite my thorough dislike and the negative language “features” that
inspired it, I acknowledge that Java has its uses too. Rather than
disparage it as the wrong language for everything I do, I just choose to
avoid doing the things for which it’s the right language as much as I
can manage.

I think that’s quite enough off-topic rambling for one email. The point
of this last bit of nattering on, if it can be said to have a real
point, is that every (reasonable) language has its advantages and
disadvantages. I happen to mesh well with those of both Perl and Ruby,
but not those of Python or Java. Nearly categorical dismissals of Perl
such as yours (implying, it seems, that with Ruby around Perl is
useless except insofar as it gets you employment) are pretty much
valueless, just as similar treatments of the language I don’t like would
be.

Chad P. wrote:

and I don’t get it when people talk as though they do. Was that a joke?
Well … let’s just say I think Ruby is a vast improvement on Perl. I
learned Perl when Perl 4 was the reigning standard. I don’t particularly
like the way Perl 5 does objects and references. I wrote a lot of code
in Perl 4 and I still maintain it, but I wouldn’t write new code in
Perl now that I have Ruby.

Most of what I have written in Perl is stuff that Perl (4) is good at.
Regular expressions, extracting numerical data from miscellaneous text
files, arrays and hashes. Ruby has all of that, plus a coherent object
model, a coherent “Enumerable” model, lambdas, blocks, continuations …

I’ve never subscribed to the “one language” philosophy either, although
I’ve worked places that do. :slight_smile: Right now I have two main languages, Perl
and R. But I don’t want to write new code in Perl.

Perl has learned from the mistakes of Perl, Python, PHP, Java, and even
Ruby. Wow. You really seem to have it in for Perl.

I’m simply tired of it … it lacks “elegance”. It’s useful … it’s
been around longer than Ruby, so there are more libraries and packages
for it. It’s not going away. It’s evolving. But Ruby’s not going away
either. Ruby is evolving.

I’d actually be less inclined to take it amiss if you just disliked
(modern-day standards) high level languages than this pick-and-choose
thing where you like Ruby and hate Chevy – er, I mean Ford. No, wait,
Perl. Seriously, though, reading that email of yours was a bit like
reading those Chevy vs. Ford bumper stickers.

I haven’t seen them … I have a Ford if it matters. :slight_smile: I pick on Perl
because I know more Perl than the others. I don’t know enough about
Python or PHP to pick on them. There appear to be lots of folks here
that will pick on Python and Java anyway.

Chad P. wrote:

I pretty well loathe the Perl object model, and the syntax for
references could use some work, but object oriented programming isn’t
the whole world of programming – and Perl handles a lot of things with
more elegance than most other languages (such as lexical closures, which
are, frankly, slightly less clunky than Ruby’s closures). Ruby does a
lot of things better than Perl, but there are some significant
shortfalls, too.

I don’t think I’ve ever needed lexical closures. The structure of most
of the code I write comes from the application domain rather than the
language. My main application domain is extracting performance data from
various text files and making coherent analytical models from it. A
combination of Perl 4, R, and relational databases is what I’ve evolved
over the years to do that, and that’s the code I write and maintain on a
daily basis.

Given the available libraries for Perl, Ruby and R, I could do the
entire job with any one of the three languages, at least on Linux. I
might have trouble making Ruby do it all under Windows, but I haven’t
tried it.

The notable thing that jumped out at me about Ruby when I discovered it
is this: Between Perl and Ruby, I don’t need to learn Python at all.
I’m awfully glad for that, since Python basically makes my eyes bleed.
Call it a personal failure if you like – it is definitely at least
mostly personal bias – but that’s the way it is.

But I already know Perl … my original comment was that I needed to
unlearn it to learn Ruby. It’s mostly syntactic – curly braces,
semicolons, scalars beginning with dollar signs, etc. I never liked
the Perl dollar sign/at sign/percent sign syntax convention.

And I need to learn at least to read Python, because some of the
software I use is written in it. I don’t think I’d need to write Python
code though.

more obnoxiously than at other times (including here).

Actually, there is one true language. It’s called the “formal
semantics of programming languages”. :slight_smile: But more to the point, I think
there are far too many “general purpose” programming languages.

A working programmer needs to know C, plus whatever languages are used
in his or her shop. Regardless of what the designers and communities for
those other languages intend(ed) them to be, they are in fact occupying
an economic niche. They are special-purpose languages by that
definition.

In this sense, Ruby is on the edge of becoming a special-purpose
language as the engine underneath Rails. I don’t have strong opinions
about whether that’s good or bad, but I do have a strong opinion that it
is the economic niche that Ruby will occupy for the foreseeable future.

Python’s a great language, in principle, and is reportedly a great
language in practice for those whose proclivities it suits. It doesn’t
suit mine, so I’ll stick to Ruby and Perl. Java . . . well, let’s just
say that as far as I can tell it’s not nearly as great a language as
some seem to think. I’d rather use Java than Visual Basic, but beyond
that there isn’t much competition with Java for its low ranking in my
hierarchy of preferred languages.

I once wrote a program in Java. This was in 1996 or thereabouts, and my
reasons for using Java were:

  1. It would run on Windows and all the flavors of UNIX that I was
    dealing with at the time. Visual Basic only runs on Windows.
  2. It had hashes, garbage collection, a reasonable object model, and
    useful compile-time error checking.
  3. It was faster than Perl for number crunching.

Java was a new language at the time – I think it was Java 1.1. It was
certainly before Swing, Java 2, etc. I’ve never had an opportunity to do
any more Java programming, so I don’t know how it is to the folks who
use it for a living. What I do know, however, it that there are a
lot of high-quality applications written in Java.

I think that’s quite enough off-topic rambling for one email. The point
of this last bit of nattering on, if it can be said to have a real
point, is that every (reasonable) language has its advantages and
disadvantages.
Even macro assembler? :slight_smile: This is about performance, right?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs