String Identifier Argument check wants to change code like
to
claiming the second version is faster.
I wrote a benchmark to check, and it shows that the second version is about half as fast as the first one:
require 'benchmark'
def bar
1
end
p(Benchmark.realtime do
1_000_000.times do
"foo#{bar}"
end
end)
p(Benchmark.realtime do
1_000_000.times do
:"foo#{bar}"
end
end)
Result:
0.082756486008293
0.1312436139996862
I do expect literal symbols to perform faster than literal strings but not the case when the value is an interpolated string.
String Identifier Argument check wants to change code like
to
claiming the second version is faster.
I wrote a benchmark to check, and it shows that the second version is about half as fast as the first one:
Result:
I do expect literal symbols to perform faster than literal strings but not the case when the value is an interpolated string.