From: Sean O'Halpin Date: 2011-08-08T06:08:14+09:00 Subject: Re: Methods defined with module_eval are... faster? Hi, When I run this using Benchmark.bmbm (to account for GC) I don't see any appreciable difference between the two methods. I used this code with ruby 1.9.2: TIMES=4000000 Benchmark.bmbm {|x| x.report("M.kk") { TIMES.times { M.kk(123) ; M.kk(4) } } } Benchmark.bmbm {|x| x.report("M.aa") { TIMES.times { M.aa(123) ; M.aa(4) } } } Benchmark.bmbm {|x| x.report("M.kk") { TIMES.times { M.kk(123) ; M.kk(4) } } } Benchmark.bmbm {|x| x.report("M.aa") { TIMES.times { M.aa(123) ; M.aa(4) } } } and got these results: M.kk 3.850000 0.010000 3.860000 ( 4.149469) M.aa 3.960000 0.010000 3.970000 ( 3.995387) M.kk 3.900000 0.020000 3.920000 ( 4.154616) M.aa 3.900000 0.010000 3.910000 ( 4.201047) I then re-ran the original code but changed the order of the tests. I got these results: Original order: M.kk: 3.75673246383667 M.aa: 3.9386367797851562 M.kk: 3.531486988067627 M.aa: 3.7896509170532227 Swapped: M.aa: 4.207374095916748 M.kk: 4.187262296676636 M.aa: 3.915318727493286 M.kk: 4.421187162399292 Apart from showing that I have a ~much~ slower machine than yours, I don't see anything significant in these results. I think what you're seeing is an artefact of garbage collection. Regards, Sean