Skip to content

String Identifier Argument demands slower-performing code #492

@p-datadog

Description

@p-datadog

String Identifier Argument check wants to change code like

"foo#{bar}"

to

:"foo#{bar}"

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions