Skip to content

Instantly share code, notes, and snippets.

@jhawthorn
Created March 2, 2023 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhawthorn/e9db7a1443eaa957cef772dccdc14d9a to your computer and use it in GitHub Desktop.
Save jhawthorn/e9db7a1443eaa957cef772dccdc14d9a to your computer and use it in GitHub Desktop.
class A
def foo
@foo
end
def initialize
@foo = 123
40.times do
instance_variable_set(:"@var_#{_1}", _1)
end
end
end
A.new # warm A's size pool
obj1 = A.new
obj2 = A.new.freeze
N = ENV.fetch("N", 10_000_000).to_i
N.times do
obj1.foo
obj2.foo
end
class A
def foo
@foo
end
def initialize(bar = false)
@bar = 123 if bar
@foo = 123
40.times do
instance_variable_set(:"@var_#{_1}", _1)
end
end
end
A.new # warm A's size pool
obj1 = A.new
obj2 = A.new(true)
N = ENV.fetch("N", 10_000_000).to_i
N.times do
obj1.foo
obj2.foo
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment