From: Brian Buckley Date: 2006-02-01T11:18:45+09:00 Subject: Re: memoize (reposting via ML) ------=_Part_19194_14061130.1138760311107 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I added a "sleep 1" line to zeta to exaggerate the time of an uncached method call. It is working. --Brian Buckley def zeta(x) sleep 1 r2d =3D 360.0/(2.0*Math::PI) # Radians to degrees 2.0*(Math.sin(x/r2d))*(Math.cos(x/r2d)) end t1 =3D Time.now 10.times { z =3D zeta(2.0) } t2 =3D Time.now memoize(:zeta) t3 =3D Time.now 10.times { z =3D zeta(2.0) } t4 =3D Time.now memoize(:zeta,"z.cache") t5 =3D Time.now 10.times { z =3D zeta(2.0) } t6 =3D Time.now puts "#{t2 - t1}, #{t4 - t3}, #{t6 - t5}" # =3D> 10.0, 1.0, 0.0 ------=_Part_19194_14061130.1138760311107--