Great Computer Language Shootout

Discussion in 'Ruby' started by igouy@yahoo.com, Mar 12, 2005.

  1. Guest

    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
    , Mar 12, 2005
    #1
    1. Advertising

  2. 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?
    William James, Mar 12, 2005
    #2
    1. Advertising

  3. Guest

    William James wrote:
    > 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 list

    others use the message form or email them to igouy2

    best wishes, Isaac
    , Mar 12, 2005
    #3
  4. Guest

    William James wrote:
    > 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


    Excellent!

    Before we can use it I'm afraid you have to contribute it to the
    shootout, we can't just skim programs from other places.

    Please send programs to the mailing list or send them using the message
    form or email them to igouy2

    http://shootout.alioth.debian.org/faq.php?sort=fullcpu

    best wishes, Isaac
    , Mar 12, 2005
    #4
  5. wrote:
    > William James wrote:
    > > 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

    >
    > Excellent!
    >
    > Before we can use it I'm afraid you have to contribute it to the
    > shootout, we can't just skim programs from other places.
    >
    > Please send programs to the mailing list or send them using the

    message
    > form or email them to igouy2
    >
    > http://shootout.alioth.debian.org/faq.php?sort=fullcpu
    >
    > best wishes, Isaac


    Ruby gurus: before this is sent to the shootout, would you check
    it to see if it can be made faster? (It has already been checked
    for correctness.)
    William James, Mar 12, 2005
    #5
  6. Carlos Guest

    [William James <>, 2005-03-15 14.56 CET]
    > > William James wrote:

    [...]
    > > > freq = Hash.new(0)
    > > > loop {
    > > > data = (STDIN.read(4095) or break) + (STDIN.gets || "")
    > > > for word in data.downcase!.tr!('^a-z',' ').split


    But "a".downcase! => nil ... And the same with most !-methods (they return
    nil when nothing was changed).
    Carlos, Mar 16, 2005
    #6
  7. > But "a".downcase! => nil ... And the same with most !-methods (they return
    > nil when nothing was changed).


    That always bothered me, since I lose my method chaining with !
    methods. Like this:

    line.strip!.downcase!

    must be

    line.strip.downcase

    to work properly. But then you lose some efficiency.

    I'd prefer that ! methods returned 'self'. In the *rare* case that I
    need to know if something changed, I'll use == or something. RCR in
    the making?

    Dan
    Daniel Amelang, Mar 17, 2005
    #7
  8. It's been suggested many times. I agree, but my vote hardly counts. =)


    On Thu, 17 Mar 2005 09:16:26 +0900, Daniel Amelang
    <> wrote:
    > > But "a".downcase! => nil ... And the same with most !-methods (they return
    > > nil when nothing was changed).

    >
    > That always bothered me, since I lose my method chaining with !
    > methods. Like this:
    >
    > line.strip!.downcase!
    >
    > must be
    >
    > line.strip.downcase
    >
    > to work properly. But then you lose some efficiency.
    >
    > I'd prefer that ! methods returned 'self'. In the *rare* case that I
    > need to know if something changed, I'll use == or something. RCR in
    > the making?
    >
    > Dan
    >
    >
    Michael Campbell, Mar 17, 2005
    #8
  9. Hal Fulton Guest

    Daniel Amelang wrote:
    >>But "a".downcase! => nil ... And the same with most !-methods (they return
    >>nil when nothing was changed).

    >
    >
    > That always bothered me, since I lose my method chaining with !
    > methods. Like this:
    >
    > line.strip!.downcase!
    >
    > must be
    >
    > line.strip.downcase
    >
    > to work properly. But then you lose some efficiency.
    >
    > I'd prefer that ! methods returned 'self'. In the *rare* case that I
    > need to know if something changed, I'll use == or something. RCR in
    > the making?


    It's been discussed a lot over the years. My impression is that
    Matz likes this behavior, in which case it would be unlikely to
    change.


    Hal
    Hal Fulton, Mar 17, 2005
    #9
  10. Isaac Gouy Guest

    Isaac Gouy, Mar 29, 2005
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jacob Lee

    code for Computer Language Shootout

    Jacob Lee, Mar 16, 2005, in forum: Python
    Replies:
    14
    Views:
    611
  2. Delaney, Timothy C (Timothy)

    RE: code for Computer Language Shootout

    Delaney, Timothy C (Timothy), Mar 16, 2005, in forum: Python
    Replies:
    3
    Views:
    300
    Raymond Hettinger
    Mar 17, 2005
  3. Replies:
    14
    Views:
    491
    Fredrik Lundh
    Nov 30, 2005
  4. Phil Tomson
    Replies:
    25
    Views:
    298
    Gawnsoft
    Jun 20, 2004
  5. Isaac Gouy
    Replies:
    0
    Views:
    102
    Isaac Gouy
    Aug 3, 2004
Loading...

Share This Page