What is the "simple" program you are running? "100 times slower" probably
means you're not measuring Ruby's performance, but rather its load time. A
hello world program in C is far faster than one in Ruby because the Ruby
interpreter, which is FAR more complex than "hello world", needs to start
up. But if you printed hello world a million times, there would probably
be little difference between C and Ruby.
In my experience, the "speed" of most real-world programs is controlled
not by the language, but rather by the algorithms used and/or dependencies
on outside services, such as databases or network connections. If it takes
4 hours to run a SQL statement on the database, then the extra two seconds
a scripting language might take over C or C++ really isn't a big deal.
Because of this, i'm much more interested in optimizing the development
time of large projects, and the maintenance effort involved in keeping
them healthy, than i am in "peformance" in the classic sense. First, make
it work, THEN make it fast, changing languages if needed. As i said
earlier, algorithms matter more than language. Heapsort implemented in
Ruby (or Visual Basic for that matter) is going to be orders of magnitude
faster than bubble sort implemented in optimized C, for any substantial
data set.
To get back to your original question... even if you can dump a "compiled"
Ruby program to an executable, it won't be that much faster, because it
has to load up all the weight of the interpreter behind it. This is the
nature of interpreted languages. And if the program is sufficiently
complex, it won't be much slower than a program written in C for most
cases.
Tapio Kelloniemi <spam07@thack.org>
09/23/02 01:38 PM
Please respond to ruby-talk
···
To: ruby-talk@ruby-lang.org (ruby-talk ML)
cc:
Subject: Using Ruby with other languages
Hi all
I'm new to Ruby, but before seriously studying the language I would like
to get some information.
I would like to know, whether it is possible to compile Ruby code to
executables so I could run Ruby code without the interpreter. I also
would like to do this, when I noticed that a simple Ruby program runs
more than 100 times slower than identically implemented C program. I
also would like to know, wheter it is possible to compile RUby code to
object format and then link with code written in different languages,
EG. C++ and C.
Thanks for all answers!
--
Tapio