# Memoize

**URL:** <https://www.ruby-forum.com/t/memoize/100067>\
**Category:** Ruby\
**Created:** [February 1, 2006, 11:58pm UTC](https://www.ruby-forum.com/t/memoize/100067 "2006-02-01T23:58:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 1, 2006, 11:58pm UTC](https://www.ruby-forum.com/t/memoize/100067/1 "2006-02-01T23:58:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 2, 2006, 7:18am UTC](https://www.ruby-forum.com/t/memoize/100067/2 "2006-02-02T07:18:03Z")

</div>

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
