string/concatenation.rb tests are misleading
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 45/100
- Issue type
- Refactor
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- ruby
- Domain
- performance, testing
Research direction
Start in string/concatenation.rb and inspect how the current benchmarks define the fast method and compare concatenation methods. Use the issue's benchmark-ips example as the reference, with runtime variables for the comparison; done means the benchmark no longer treats parser-time concatenation as a runtime operation and fairly compares the stated alternatives.
Written by the indexing model from the issue text.
Description
Hi, the tests in string/concatenation.rb are quite misleading.
The fast method consists of this
def fast
'foo' 'bar'
end
That's not concatenating during calling of fast but on parsing the code. If you write another method just returning foobar, it is as fast as this method.
So I think this is not fair comparison and what you usually want is to concatenate two variables during runtime.
For this use case concat and << are calling the same code, so they have the same performance and both are fine if you want to change the string on the left and not just get two strings concatenated. If you want a new string you can use +.
Some better test could be to compare + and String interpolation
Benchmark.ips do |x|
foo = 'foo'
bar = 'bar'
x.report('String#+') do
foo + bar
end
x.report('String interpolation') do
"#{foo}#{bar}"
end
x.compare!
end
This still has the difference that interpolation can handle nil values, while + cannot.
- Dominant language
- Ruby
- Stars
- 5.7k
- Forks
- 370
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from fastruby/fast-ruby
-
Difficulty 2/5 1-3 hours Newbie friendliness 52/100
-
Difficulty 4/5 3-5 days Newbie friendliness 32/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
All issues in fastruby/fast-ruby
Similar issues
-
SyncEm always forwards a dummy block, so wrapped methods lose their no-block/Enumerator behavior Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
bug P2
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
dependabot
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
githubnext/gh-aw-cao#13349 ·
-
user-reported
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Kong/developer.konghq.com#7316 ·