Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created February 12, 2013 03:37
Show Gist options
  • Save tenderlove/4760066 to your computer and use it in GitHub Desktop.
Save tenderlove/4760066 to your computer and use it in GitHub Desktop.
class_eval vs define_method memory usage
N = ARGV[0].to_i
T = ARGV[1] || 'eval'

class Foo
  if T == 'eval'
    N.times do |i|
      class_eval "def hello_#{i}; end"
    end
  else
    N.times do |i|
      define_method("hello_#{i}") { }
    end
  end
end

GC.start

sleep

run

memory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment