Hi all, In some places new array creates as a Array(). If we replace it to a , we increase performance about 1.7 times:
def old_slow
Array(123)
end
def new_fast
[123]
end
Benchmark.ips do |x|
x.report(“new_fast”) { new_fast }
x.report(“old_slow”) { old_slow }
x.compare!
end
Calculating -------------------------------------
new_fast 184.920k i/100ms
old_slow 150.931k i/100ms
new_fast 7.528M (± 4.4%) i/s - 37.724M
old_slow 4.408M (± 4.3%) i/s - 22.036M
Comparison:
new_fast: 7528299.2 i/s
old_slow: 4408283.1 i/s - 1.71x slower
What do you think about it?