Care to explain? The idea was that you don't know beforehand what code
gets called by proc.
I don't like both approaches, but:
$ cat eval_cache.rb
require 'benchmark'
c = '@a + @b'
@a, @b = 1, 2
p1 = lambda { eval c }
p2 = eval "lambda { #{c} }"
Benchmark.bm do |x|
x.report do
100000.times {p1.call}
end
x.report do
100000.times {p2.call}
end
end
$ ruby eval_cache.rb
user system total real
0.480000 0.000000 0.480000 ( 0.480000)
0.160000 0.000000 0.160000 ( 0.161000)
Kent.
On 6/27/05, Adam Sanderson <netghost / gmail.com> wrote:
> That won't gain you any effiecency. Assuming that you're doing the
> same statement for each record perhaps you'd be better off with
> something along the lines of:
>
> irb(main):001:0> p = proc{|a,b| a+b }
> => #<Proc:0x000583ec@(irb):1>
> irb(main):002:0> p.call(1,5)
> => 6
>
> You might just need to rethink your approach a little.
> .adam sanderson
>
>
>