Forum: Ruby memoize

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
unknown (Guest)
on 2006-02-02 00:58
(Received via mailing list)
I was trying to use memoize the other day (v 1.2 from Dan B. --
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
Hal F. (Guest)
on 2006-02-02 08:18
(Received via mailing list)
removed_email_address@domain.invalid wrote:
> I was trying to use memoize the other day (v 1.2 from Dan B. --
> is there a different/better one?). Ran into some problems...

Ignore this post -- I made it 48 hours or so ago. A gateway glitch
delayed it, I guess.


Hal
This topic is locked and can not be replied to.