You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calling `self.class` multiple times is not cheap.
```ruby
class A
def self.foo
end
def foo1
self.class.foo
self.class.foo
self.class.foo
self.class.foo
end
def foo2
klass = self.class
klass.foo
klass.foo
klass.foo
klass.foo
end
end
a = A.new
Benchmark.ips do |x|
x.report("foo1") { a.foo1 }
x.report("foo2") { a.foo2 }
end
```
```
Warming up --------------------------------------
foo1 341.701k i/100ms
foo2 414.000k i/100ms
Calculating -------------------------------------
foo1 3.194M (± 5.4%) i/s - 16.060M in 5.044653s
foo2 4.276M (± 3.8%) i/s - 21.528M in 5.041999s
```
Similar with rails#36052.
0 commit comments