Ben Giddings
3/11/2005 5:12:00 PM
MiG wrote:
> 1. I have NOTHING against Ruby, it is my best language
> 2. Is it wrong-doing to ask?
> 3. My dumb benchmark: I used real data. If you have 2GB of free RAM and
> use 80MB file, is it wrong? It's the same if you have 1MB RAM and use
> smaller file. I used the real data I have, that's all. It behaves the
> same way with smaller.
> 4. Thank you for excellent humour.
I'm glad you see the humour. I was a little harsh, but I was having a
bad day, sorry.
Really, the benchmark really isn't meaningful. You need to do something
with the data you're reading. It doesn't matter if it's a 80MB file or
a 10 byte file. If you're simply reading the data and discarding it,
you aren't doing anything. For the measurement to be meaningful, you
actually need to *do something*.
Would you expect these two applications to take the same amount of time:
#!/bin/env ruby
1000.times do
# do nothing
end
------
#!/bin/env ruby
1000.times do
num = Math.sin(rand(1.0))
if num < 0.0
num += 1.0
else
num -= 1.0
end
end
Both programs are essentially equivalent. Neither actually *does*
anything. If the second one ran slower, could you really draw any
conclusions about the speed of Ruby's math operations?
In fact, it may be that Ruby's IO is slower than other languages. If
Ruby were even close to the speed of C I'd be stunned. Ruby has to
construct an object with every line it reads. C just stuffs things
blindly into an array. The problem is that your sample doesn't test
Ruby's IO capabilities. In the end, your sample code does absolutely
nothing.
If you want to benchmark Ruby's IO, try doing something like writing a
program to concatenate a number of files, or even just to copy a file.
Open one file for writing, and then open a file for reading, read
something from the input file, write to the output file.
In any case, until the slowness of Ruby's IO proves to be a problem in
actual use, why do you care how it fares on a benchmark?
Ben