memoize

R

rubyhacker

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
 
H

Hal Fulton

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...

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


Hal
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top