From: "Iñaki Baz Castillo" Date: 2011-08-07T21:45:55+09:00 Subject: Methods defined with module_eval are... faster? Hi, just let me show this code: ------------------- require "benchmark" module M self.module_eval(" def self.kk(var) if var == 123 a=var*2 else a=var*4 end end ") def self.aa(var) if var == 123 b=var*2 else b=var*4 end end end printf "M.kk: " puts Benchmark.realtime { 4000000.times { M.kk(123) ; M.kk(4) } } printf "M.aa: " puts Benchmark.realtime { 4000000.times { M.aa(123) ; M.aa(4) } } printf "M.kk: " puts Benchmark.realtime { 4000000.times { M.kk(123) ; M.kk(4) } } printf "M.aa: " puts Benchmark.realtime { 4000000.times { M.aa(123) ; M.aa(4) } } ------------------- Results (ruby 1.9.2): M.kk: 1.4799699783325195 M.aa: 1.6037561893463135 M.kk: 1.4918322563171387 M.aa: 1.612684965133667 This is, M.kk (defined with module_eval) is faster than M.aa (which is a commonly defined method). ¿?¿? -- Iñaki Baz Castillo