[#80776] prerelease of Guis-1.3pre1 (a GTK widget server) for Ruby — Basile STARYNKEVITCH <basile@...>

Dear All,

11 messages 2003/09/01

[#80849] Simple question(s) — Michael Campbell <michael_s_campbell@...>

(I think...)

16 messages 2003/09/02

[#80870] show me the ruby way — nord ehacedod <nordehacedod@...>

This works, but there must be a more natural way to do

18 messages 2003/09/02
[#80916] Re: show me the ruby way — aero6dof@... (Alan Chen) 2003/09/02

ts <decoux@moulon.inra.fr> wrote in message news:<200309021525.h82FPkM17085@moulon.inra.fr>...

[#80918] Re: show me the ruby way — "Warren Brown" <wkb@...> 2003/09/02

alan,

[#80873] RDoc: how to turn off automatic linking for a word? — leikind@... (Yuri Leikind)

Hello all,

12 messages 2003/09/02
[#80962] Re: RDoc: how to turn off automatic linking for a word? — William Webber <wew@...> 2003/09/03

On Wed, Sep 03, 2003 at 12:32:23AM +0900, Yuri Leikind wrote:

[#81014] unknown node type 0 — Hal Fulton <hal9000@...>

Hello, all.

15 messages 2003/09/03

[#81028] webrick and ruby — ahoward <ahoward@...>

12 messages 2003/09/03

[#81057] WEBrick and mod_ruby performance — quixoticsycophant@... (Jeff Mitchell)

I've been scoping out ruby for an upcoming server project.

16 messages 2003/09/03

[#81075] Unit Tests and Encapsulation — Scott Thompson <easco@...>

This may be off-topic in a Ruby list, although I have noticed that a

18 messages 2003/09/04

[#81167] Difference between .. and ... in boolean ranges — Oliver Dain <odain2@...>

I'm a bit confused by some Ruby behavior I'm seeing with ranges. As I

12 messages 2003/09/04

[#81234] Correction: "religious" — Daniel Carrera <dcarrera@...>

It has come to my attention that the word religious can, indeed, be

12 messages 2003/09/05

[#81239] rcalc 2.0 (Ruby Calculator) — "Josef 'Jupp' Schugt" <jupp@...>

Saluton!

14 messages 2003/09/05

[#81345] ANN: MetaTags 1.0 — Ryan Pavlik <rpav@...>

MetaTags 1.0

73 messages 2003/09/08
[#81361] Re: ANN: MetaTags 1.0 — Tobias Peters <tpeters@...> 2003/09/08

Ryan Pavlik wrote:

[#81371] Re: ANN: MetaTags 1.0 — why the lucky stiff <ruby-talk@...> 2003/09/08

On Monday 08 September 2003 06:58 am, Tobias Peters wrote:

[#81384] Re: ANN: MetaTags 1.0 — Chad Fowler <chad@...> 2003/09/08

On Tue, 9 Sep 2003, why the lucky stiff wrote:

[#81386] Re: ANN: MetaTags 1.0 — dblack@... 2003/09/08

Hi --

[#81394] Re: ANN: MetaTags 1.0 — why the lucky stiff <ruby-talk@...> 2003/09/08

On Monday 08 September 2003 12:08 pm, dblack@superlink.net wrote:

[#81396] Re: ANN: MetaTags 1.0 — Hal Fulton <hal9000@...> 2003/09/08

why the lucky stiff wrote:

[#81452] Re: ANN: MetaTags 1.0 — matz@... (Yukihiro Matsumoto) 2003/09/09

Hi,

[#81454] Re: ANN: MetaTags 1.0 — Dave Thomas <Dave@...> 2003/09/09

[#81615] Re: ANN: MetaTags 1.0 — Richard Kilmer <rich@...> 2003/09/10

On Monday, September 8, 2003, at 11:59 PM, Dave Thomas wrote:

[#81374] problem with Module#append_features — Ferenc Engard <ferenc@...>

Hi all,

24 messages 2003/09/08

[#81503] Memory consumption of Ruby/mod_ruby combo on Apache — David Heinemeier Hansson <david@...>

I'm seeing memory consumption in the area of 30-35mb per Apache process

12 messages 2003/09/09
[#81504] Re: Memory consumption of Ruby/mod_ruby combo on Apache — mgarriss <mgarriss@...> 2003/09/09

David Heinemeier Hansson wrote:

[#81535] using a filter inside Ruby — Eric Schwartz <emschwar@...>

I've the contents of a raw log file in memory, and a program that will

12 messages 2003/09/09

[#81587] Fwd: Calling fun taking struct and not pointer to struct? — Robert Feldt <feldt@...>

Related to the recent thread about nested structs

16 messages 2003/09/10
[#81590] Re: Calling fun taking struct and not pointer to struct? — "Nathaniel Talbott" <nathaniel@...> 2003/09/10

Robert Feldt [mailto:feldt@ce.chalmers.se] wrote:

[#81594] Re: Calling fun taking struct and not pointer to struct? — Robert Feldt <feldt@...> 2003/09/10

Nathaniel Talbott <nathaniel@NOSPAMtalbott.ws> skrev den Wed, 10 Sep 2003 22:42:24 +0900:

[#81596] Re: Calling fun taking struct and not pointer to struct? — "Nathaniel Talbott" <nathaniel@...> 2003/09/10

Robert Feldt [mailto:feldt@ce.chalmers.se] wrote:

[#81597] Re: Calling fun taking struct and not pointer to struct? — Robert Feldt <feldt@...> 2003/09/10

Nathaniel Talbott <nathaniel@NOSPAMtalbott.ws> skrev den Thu, 11 Sep 2003 00:06:18 +0900:

[#81612] What *are* variables? Which are nil now? — Hugh Sasse Staff Elec Eng <hgs@...>

Reading about reflection, ObjectSpace will give you the objects in

22 messages 2003/09/10
[#81632] Re: What *are* variables? Which are nil now? — Austin Ziegler <austin@...> 2003/09/10

> raise "@b1 is nil" if @b1.nil

[#81623] Chasing a garbage collection bug — "Thomas Sondergaard" <thomas@...>

I just discovered that I have a GC related bug, or that is to say it doesn't

17 messages 2003/09/10

[#81755] Passing an Object Class from a method to a caller — "RLMuller" <RLMuller@...>

Hi All,

14 messages 2003/09/11

[#81840] Re: Dir.foreach not with patterns? — "Weirich, James" <James.Weirich@...>

I like the Dir[] form (or its "glob" alternative). I used to write

14 messages 2003/09/12
[#82500] Re: Dir.foreach not with patterns? — Jason Creighton <androflux@...> 2003/09/19

On Thu, 18 Sep 2003 15:59:25 +0100

[#81871] Duck Typing — Jim Weirich <jweirich@...>

In the Method Redefinition thread, this explanation of Duck Typing is

38 messages 2003/09/13
[#81884] Re: Duck Typing — dblack@... 2003/09/13

Hi --

[#81929] actual debian ruby packages are unuseable with tk — Ferenc Engard <ferenc@...>

Dear debian ruby package maintainers,

12 messages 2003/09/13

[#81960] Dot versus double-colon — Hal Fulton <hal9000@...>

OK, I've been thinking (always dangerous after 11 pm).

18 messages 2003/09/14

[#82012] performance and style advice requested — Alex Martelli <aleaxit@...>

I'm trying to learn some Ruby, so I want to write some Ruby code, starting

53 messages 2003/09/14
[#82028] Re: performance and style advice requested — Ben Giddings <bg-rubytalk@...> 2003/09/14

Some style advice:

[#82029] Linguistics 0.02 — Michael Granger <ged@...>

Hi fellow Rubyists,

19 messages 2003/09/14

[#82056] Test::Unit -- multiple errors in test method ??? — Johan Holmberg <holmberg@...>

14 messages 2003/09/15

[#82166] scrambler one-liner — Xavier Noria <fxn@...>

I just came across this interesting article at Slashdot that explains that

27 messages 2003/09/16

[#82206] #{} and \" don't like each other — Peter <Peter.Vanbroekhoven@...>

From the Programming Ruby book:

32 messages 2003/09/16

[#82419] wiki reccomendations — ahoward <ahoward@...>

15 messages 2003/09/18

[#82448] closing stderr — Michael Garriss <mgarriss@...>

I would like to prevent some output that is going to stderr during a

15 messages 2003/09/18

[#82547] fork not available? — walter@...

I am running windows 2000 using the PragProgs install.

14 messages 2003/09/19

[#82561] Trouble with binary files? — <agemoagemo@...>

I'm trying to write a program that will read a binary

24 messages 2003/09/19
[#82562] Re: Trouble with binary files? — Heinz Werntges <werntges@...> 2003/09/19

agemoagemo@yahoo.com wrote:

[#82583] Re: Trouble with binary files? — Tim Hammerquist <tim@...> 2003/09/19

<agemoagemo@yahoo.com> graced us by uttering:

[#82575] Article on oreilly.net on how to build Unix tools with Ruby — Xavier <NOSPAM@...>

Thought you'd like to know about this article

24 messages 2003/09/19
[#82829] Re: Article on oreilly.net on how to build Unix tools with Ruby — Paul Brannan <pbrannan@...> 2003/09/23

On Sat, Sep 20, 2003 at 06:00:21AM +0900, Xavier wrote:

[#82589] POP3Filter for SoBig.F Virus: — Austin Ziegler <austin@...>

Here's an updated version of the Ruby pop3filter that was written. This

32 messages 2003/09/20
[#82592] Re: POP3Filter for SoBig.F Virus: — Austin Ziegler <austin@...> 2003/09/20

I've made more updates. Rather than just putting them here, I've created a

[#82609] Re: POP3Filter for SoBig.F Virus: — Austin Ziegler <austin@...> 2003/09/20

On Sat, 20 Sep 2003 10:14:39 +0900, Austin Ziegler wrote:

[#82617] Re: POP3Filter for SoBig.F Virus: — "Shashank Date" <sdate@...> 2003/09/20

[#82618] Re: POP3Filter for SoBig.F Virus: — Gavin Sinclair <gsinclair@...> 2003/09/20

On Saturday, September 20, 2003, 9:03:18 PM, Shashank wrote:

[#82621] Re: POP3Filter for SoBig.F Virus: — Austin Ziegler <austin@...> 2003/09/20

On Sat, 20 Sep 2003 22:15:40 +0900, Gavin Sinclair wrote:

[#82623] Re: POP3Filter for SoBig.F Virus: — Jose Quesada <quesadaj@...> 2003/09/20

On Sat, 20 Sep 2003 23:52:39 +0900, Austin Ziegler <austin@halostatue.ca>

[#82624] Re: POP3Filter for SoBig.F Virus: — Xavier Noria <fxn@...> 2003/09/20

On Saturday 20 September 2003 18:56, Jose Quesada wrote:

[#82632] Real emails on newsgroup version (was Re: POP3Filter) — Ben Giddings <bg-rubytalk@...> 2003/09/20

This whole worm thing brings up a question:

[#82683] Re: Real emails on newsgroup version (was Re: POP3Filter) — Dave Thomas <Dave@...> 2003/09/22

[#82661] Performance: Ruby vs Java — lalit_pant@... (Lalit Pant)

I'm a newcomer to Ruby, and thought I would write a little

18 messages 2003/09/22

[#82715] Ruby package for Linux — Jim Freeze <jim@...>

Ok, I know nothing about linux packages.

22 messages 2003/09/22

[#82832] upper to lower first letter of a word — yvon.thoravallist@... (Yvon Thoraval)

Recently, i get a vintage list (more than 500 items) with poor typo, for

30 messages 2003/09/23

[#82884] When threads block — Hans Fugal <fugalh@...>

It's difficult to do any serious multi-threaded network programming when

13 messages 2003/09/24

[#82964] Re: Prove internet package for Microsoft Internet Explorer — "Anthony Neville" <anthony.neville@...>

13 messages 2003/09/25

[#83002] TCPSocket.gethostbyname difficulties — "Nathaniel Talbott" <nathaniel@...>

I'm trying to use TCPSocket.gethostbyname to verify that a given domain

35 messages 2003/09/25
[#83006] Re: TCPSocket.gethostbyname difficulties — Peter <Peter.Vanbroekhoven@...> 2003/09/25

> I can browse to either of those hosts, so what's different about them? Any

[#83014] Re: TCPSocket.gethostbyname difficulties — "Nathaniel Talbott" <nathaniel@...> 2003/09/26

Peter [mailto:Peter.Vanbroekhoven@cs.kuleuven.ac.be] wrote:

[#83030] Re: TCPSocket.gethostbyname difficulties — ts <decoux@...> 2003/09/26

>>>>> "N" == Nathaniel Talbott <nathaniel@NOSPAMtalbott.ws> writes:

[#83035] Re: TCPSocket.gethostbyname difficulties — "Nathaniel Talbott" <nathaniel@...> 2003/09/26

ts [mailto:decoux@moulon.inra.fr] wrote:

[#83036] Re: TCPSocket.gethostbyname difficulties — ts <decoux@...> 2003/09/26

>>>>> "N" == Nathaniel Talbott <nathaniel@NOSPAMtalbott.ws> writes:

[#83037] Re: TCPSocket.gethostbyname difficulties — "Nathaniel Talbott" <nathaniel@...> 2003/09/26

ts [mailto:decoux@moulon.inra.fr] wrote:

[#83011] Adding, removing and redefining features at runtime — "Thomas Sondergaard" <thomas@...>

I am working on an article on the subject of implementing dynamically typed

23 messages 2003/09/26

[#83105] Fwd: FW: Porting Suggestions: Lucene to Ruby; Perl Text::Balanced — Erik Hatcher <erik@...>

I was alerted about me being mentioned on ruby-talk, as I was not

12 messages 2003/09/27
[#83117] OT: alerts - was Re: Fwd: FW: Porting Suggestions: Lucene to Ruby; Perl Text::Balanced — Hal Fulton <hal9000@...> 2003/09/27

Erik Hatcher wrote:

[#83140] Thoughts on yield — nolan_d@... (Nolan J. Darilek)

I've begun working on a music-related ruby project, and recently I've

17 messages 2003/09/28

[#83223] Article on ARTIMA — Peter Hickman <peter@...>

There is the start of a series of articles on ARTIMA with Matz.

21 messages 2003/09/29

[#83310] Making == symmetric? — elbows@... (Nathan Weston)

It has always bothered me that == is not symmetric in ruby:

22 messages 2003/09/30

performance and style advice requested

From: Alex Martelli <aleaxit@...>
Date: 2003-09-14 16:44:09 UTC
List: ruby-talk #82012
I'm trying to learn some Ruby, so I want to write some Ruby code, starting 
with my usual favourite fun field -- combinatorial arithmetic related to 
the game of contract bridge.  As a warm-up, I begin with the "probability
of pointcount".  Problem definition: a hand is a set of 13 cards out of 52.
16 of those cards (Aces, Kings, Queens, Jacks) are known as "honors" and
are assigned a "pointcount" (4 for each Ace, 3 for each King, 2 for each
Queen, 1 for each Jack).  Consider all possible hands and determine the
exact probability of each possible point-count.

Basically, this boils down to considering each of the 2**16 possible
sets of honors -- each has an easily computed total pointcount -- and
for each of them computing in how many different ways it can occur --
which is C(36, 13-numberofhonors) -- the ways of choosing out of the
36 non-honors in the deck the 13-numberofhonors non-honors in this
hand.  (That's with C(x,y) extended to be 0 for y<0, of course).

So I sit down and code it in the simplest way -- in Python first for
practice, since that's what I'm familiar with, then in Ruby.  Fine
both ways, except that (on my laptop, which is all I have at hand as
I'm on a business trip -- with Python 2.3 and Ruby 1.8 and Win/XP)
the Python version runs in just above 4 seconds while the Ruby one
takes over 9.  Hmmm, probably my lack of Ruby instincts, of course,
but anyway -- just as of course -- this needs to be optimized by
quite a bit (not for its own sake, but because later I'll extend it
to compute much more interesting stuff, such as correlations between
points, controls and shape, etc, etc) so who cares about performance
for the "coded in the simplest way" versions (oh, I should clarify:
simplest _except_ that I have of course memoized C(), computing
combinations aka binomial coefficients, and the factorial it calls).

So I start optimizing and squeezing every cycle I can -- and I get
down to about 0.65 seconds for Python, 2.3 seconds for Ruby (best
case, for each of them).  Eep -- the ratio keeps increasing, so my
lack of sound Ruby instincts must be really hurting.  Oh well, say
I, let's try "ruby -rprofile".  EEK!  After a couple of times where
I was convinced it had just seized up I decided to let it run all
the way -- and it took almost 1000 seconds.  Is a slowdown of over
400 times normal for Ruby profiling, or is something weird in my
installation...?  (It's the one-exe native Ruby 1.8 install for Win
which comes with a lot of goodies such as SciTE, Programming Ruby
in HTML-Help format, etc).

Anyway, the profiler's output isn't illuminating to me at all, so
that's when I decide to turn to the famous Ruby community -- I'm
sure you'll find lots to critique in my Ruby program, particularly
with an eye to performance but not necessarily just that (I _am_
quite aware that I may be guilty of "coding Python in Ruby" -- and
this may produce suboptimal performance _and_ other issues).

So, first, for reference, here's the optimized Python program:


#
# Memoized implementation of factorial
#
def fact(x, _fact_memo = {0:1, 1:1, 2:2, 3:6, 4:24, 5:120, 6:720, 7:5040} ):
    " factorial of x (0 if x<0) "
    try: return _fact_memo[x]
    except KeyError:
        if x < 0: return 0
        return _fact_memo.setdefault(x, x * fact(x-1))

#
# Memoized implementation of C(x, y) [binomial coefficient, aka comb]
#
def comb(x, y, _comb_memo = {}):
    " combinations of x things y at a time (0 if x<0, y<0, or y>x) "
    try: return _comb_memo[x, y]
    except KeyError:
        if x<0 or y<0 or y>x: return 0
        return _comb_memo.setdefault((x, y), fact(x) / (fact(y)*fact(x-y)))

#
# we represent a "honor" by a its points-worth
#
honors = [ p for p in range(1,5) for s in range(4) ]

#
# we represent a "honors set" by a pair (points-worth, total-#-of-cards)
#
def honor_subsets(lis, fromindex=0):
    """ recursive generator of all sets from a list and starting point;
        each set is represented by a honor-set as above, while the list
        must hold points-worths representing "honors" again as above.
    """
    ph = lis[fromindex]
    if fromindex == len(lis)-1:
        yield 0, 0
        yield ph, 1
        return
    for pw, le in honor_subsets(lis, fromindex+1):
        yield pw, le
        yield ph+pw, 1+le

def main():
    " main computation "
    # hist: histogram  points -> number of occurrences
    hist = {}
    # totcom: total number of occurrences
    totcom = 0L
    # range over all possible honorsets
    for hs in honor_subsets(honors):
        # compute number of honors and pointcount for this honorset
        pt, nh = hs
        # compute number of possible occurrences of this honorset
        nc = comb(36, 13-nh)
        # update histogram and total
        hist[pt] = hist.get(pt, 0) + nc
        totcom += nc
    # print total and eyeball-check it
    print totcom, comb(52, 13)

    # sort histogram by decreasing frequency
    aux = [ (nc, pt) for pt, nc in hist.iteritems() ]
    aux.sort()
    aux.reverse()

    # compute frequencies as relative percentages
    divis = 100.0 / totcom

    # give top 10 possibilities
    for nc, pt in aux[:10]:
        print "%2d %d (%.2f)" % (pt, nc, nc * divis)


# run the computation
import time
start = time.time()
main()
stend = time.time()
print stend-start


and here is the corresponding optimized Ruby program:


#
# factorial, memoized via an Array
#
$_fact_memo=[1,1,2,6,24,120,720]
def fact(x)
    # factorial of x (0 if x<0)
    result = $_fact_memo[x]
    if !result
        return 0 if x<0
        result = $_fact_memo[x] = x*fact(x-1)
    end
    return result
end

#
# binomial factor (aka comb), memoized via a Hash
#
$_comb_memo={}
def comb(x, y)
    # combinations of x things y at a time (0 if x<0, y<0, or y>x)
    result = $_comb_memo[[x, y]]
    if !result
        return 0 if x<0 or y<0 or y>x
        result = $_comb_memo[[x, y]] = fact(x)/(fact(y)*fact(x-y))
    end
    return result
end

#
# add to Array a recursive iterator over honor-subsets
#
# a honor is represented by its point-value (1..4); a honor-subset is
# a pair [total-pointcount, number-of-honors]
#
class Array
    def each_subset(from=0)
        if from==size-1:
            #
            # end of array, so, return 2 only possible subsets remaining:
            # empty set, or singleton set with the last element in it
            #
            yield [0, 0]
            yield [self[from], 1]
        else
            #
            # 2+ elements remaining, so, loop iteratively, extracting
            # the current element and getting all possible subsets of
            # all later ones -- for each of those, return 2 possible
            # subsets, i.e., either without or with the current element
            #
            thispoints = self[from]
            each_subset(from+1) do |subpoints, sublength|
                yield subpoints, sublength
                yield thispoints + subpoints, 1 + sublength
            end
        end
    end
end


def main()
    # main computation 
    # hist: histogram (Hash) points -> number of occurrences
    hist = Hash.new(0)
    # totcon: total number of occurrences
    totcom = 0
    # range over all possible honor-sets
    honors = Array(1..4) * 4
    honors.each_subset do |pt, nh|
        # receive number of honors and pointcount for this honorset,
        # then compute number of possible occurrences of this honorset
        nc = comb(36, 13-nh)
        # update histogram and total
        hist[pt] += nc
        totcom += nc
    end
    # print total and eyeball-check it
    print totcom, ' ', comb(52, 13), "\n"

    # sort histogram by decreasing frequency
    aux = hist.sort {|a,b| b[1]<=>a[1]}

    # compute frequencies as relative percentages
    divis = totcom / 100.0

    # give top 10 possibilities
    for pt, nc in aux[0,10]
        printf "%2d %d (%.2f)\n" , pt, nc, nc/divis
    end
end

# run the computation
start = Time.now
main
stend = Time.now
puts stend-start


Finally, FWIW, here's the start of the profiler's output...:


C:\Python23>ruby -rprofile alco2.rb
635013559600 635013559600
10 59723754816 (9.41)
 9 59413313872 (9.36)
11 56799933520 (8.94)
 8 56466608128 (8.89)
 7 50979441968 (8.03)
12 50971682080 (8.03)
13 43906944752 (6.91)
 6 41619399184 (6.55)
14 36153374224 (5.69)
 5 32933031040 (5.19)
948.294
  %   cumulative   self              self     total
 time   seconds   seconds    calls  ms/call  ms/call  name
 34.90   317.57    317.57       16 19848.44 909790.50  Array#each_subset
 13.12   437.00    119.43    65537     1.82     6.56  Object#comb
 10.56   533.11     96.11   131073     0.73     2.54  Hash#[]
  8.20   607.70     74.59    65385     1.14     1.82  Array#eql?
  8.11   681.49     73.79    65552     1.13     1.79  Array#hash
  6.17   737.65     56.16   161735     0.35     0.35  Fixnum#+
  4.87   781.99     44.34   130770     0.34     0.34  Numeric#eql?
  4.80   825.63     43.65   131104     0.33     0.33  Kernel.hash
  4.14   863.31     37.68   100426     0.38     0.38  Bignum#+
  2.59   886.84     23.53    65551     0.36     0.36  Hash#[]=
  2.48   909.38     22.54    65613     0.34     0.34  Fixnum#-
  0.02   909.57      0.19       91     2.09    38.57  Object#fact
  0.02   909.75      0.18        1   180.00   180.00  
Profiler__.start_profile
  0.02   909.92      0.17        1   170.00   190.00  Hash#sort
  0.01   910.02      0.10      350     0.29     0.29  Fixnum#<
  0.01   910.10      0.08      193     0.41     0.41  Hash#default
  0.01   910.16      0.06       59     1.02     1.19  Fixnum#*

I've truncated starting from where the "%time" goes to 0.00.


Thanks for any feedback!


Alex


In This Thread

Prev Next