Tuesday, February 23, 2016

Performance of a.length > 0 vs a.empty? on

In Ruby 2.3.0

require 'benchmark'

a = []

t1 = Benchmark.realtime do
 a.length > 0
end

t2 = Benchmark.realtime do
  a.empty?
end

p t2 < t1


This prints true.