From: Christoph Date: 2002-09-07T12:41:07+09:00 Subject: Re: Ruby aesthetics "Gavin Sinclair" wrote .... > Can anyone comment on the performance difference between procs and > singleton definitions? The (calling) performance of procs is generally worth then their the method counter-part (independent of their ``singleton-ness''). Also the creation time of a singleton method is probably smaller than the creation time of a general proc object. --- user system total real fib_lambda 25.266000 0.071000 25.337000 ( 26.859000) fib 6.850000 0.000000 6.850000 ( 7.570000) fib_class 54.449000 0.340000 54.789000 ( 58.965000) --- --- # needs 1.7 fib_lambda = lambda {|n| if n < 2 n else fib_lambda[n - 1] + fib_lambda[n-2] end } def fib(n) if n < 2 n else fib(n - 1) + fib(n - 2) end end fib_class = Class.new do def self.[](n) new(n).fib end def initialize(n) @n =n end def fib if @n < 2 @n else type[@n-1] + type[@n-2] end end end require 'benchmark' Benchmark::bmbm { |test| test.report("fib_lambda") { fib_lambda[29] } test.report("fib") { fib(29) } test.report("fib_class") { fib_class[29] } } --- /Christoph