memoize



I was trying to use memoize the other day (v 1.2 from Dan Berger --
is there a different/better one?). Ran into some problems...

In this dumb example, where I'm passing the same parameter every time,
the speed should *blaze*, should it not?

This doesn't work for me. I see no measurable speed difference in these
three cases. What am I doing wrong?


Thanks,
Hal


require 'memoize'

include Memoize

def zeta(x)
r2d = 360.0/(2.0*Math::PI) # Radians to degrees
2.0*(Math.sin(x/r2d))*(Math.cos(x/r2d))
end

puts Time.now
1000000.times { z = zeta(2.0) }
puts Time.now

memoize(:zeta)

puts Time.now
1000000.times { z = zeta(2.0) }
puts Time.now

memoize(:zeta,"z.cache")

puts Time.now
1000000.times { z = zeta(2.0) }
puts Time.now

.



Relevant Pages

  • Re: Got me some projects!!! :-)
    ... (some ad agency that is paid too much for dumb ideas) ... Ok, lets puts ...
    (rec.games.pinball)
  • Re: AMC: Babe the Victim
    ... who puts out. ... To keep all these guys on the hook and willing to break ... everyone refer to Dumb as Dirt Dixie as if she were a saint AND totally irresitable to all men. ...
    (rec.arts.tv.soaps.abc)
  • Re: Some random observations after game 2.
    ... the field including 60 percent 3 pointers, puts up 21/7/5, and he gets ... What, pray tell, were his dumb decisions tonight? ...
    (alt.sports.basketball.nba.la-lakers)
  • memoize (reposting via ML)
    ... In this dumb example, where I'm passing the same parameter every time, ... I see no measurable speed difference in these ... puts Time.now ...
    (comp.lang.ruby)
  • Re: A comparison by example of keyword argument styles
    ... Right, so this is probably a really dumb idea, but I was just having a ... little bit of fun. ... puts "You thought of my third request was #" ... Prev by Date: ...
    (comp.lang.ruby)