Great Computer Language Shootout

William James wrote:

> We've added some new micro-benchmarks and deprecated some of the

old

> ones.
> So now Ruby is missing a dozen programs!
>
> http://shootout.alioth.debian.org/
>
> If you have a few moments please contribute stylish Ruby programs.
>
> best wishes, Isaac

Here's a shorter and, I think, slightly faster program to count
word-frequencies.

freq = Hash.new(0)
loop {
    data = (STDIN.read(4095) or break) + (STDIN.gets || "")
    for word in data.downcase!.tr!('^a-z',' ').split
        freq[word] += 1
    end
}
print freq.to_a.map{|x| sprintf("%7d %s\n",x[1],x[0])}.sort.reverse

Can anyone explain why the Perl version is 4 times as fast as the
Ruby one?

Thanks William, I'm afraid we need the programs to be sent to the
shootout, we can't skim them from other places.

Some folk just post them on the mailing list:
http://shootout.alioth.debian.org/miscfile.php?sort=fullcpu&file=mailinglist&title=mailing%20list

others use the message form or email them to igouy2

best wishes, Isaac

···

igouy@yahoo.com wrote: