On May 4, 2006, at 1:14 PM, Wilson Bilkovich wrote:

>> ruby eval_bench.rb
>                user     system      total        real
> eval:       1.141000   0.000000   1.141000 (  1.156000)
> const_get:  0.156000   0.000000   0.156000 (  0.172000)
>
>> cat eval_bench.rb
> require 'benchmark'
> class Foo;end
> some_class = 'Foo'
> Benchmark.bm(10) do |b|
>  b.report("eval:") { 100000.times {eval("#{some_class}.new")} }
>  b.report("const_get:") { 100000.times{Object.const_get 
> (some_class).new} }
> end

We shouldn't avoid eval just because it takes a second (less on my  
computer) to use it 100,000 times. In most situations that is  
premature optimisation.

-- Elliot Temple
http://www.curi.us/blog/