string/concatenation.rb tests are misleading
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 45/100
- Issue 类型
- 重构
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- ruby
- 领域
- performance, testing
调研方向
从 string/concatenation.rb 开始,检查当前基准测试如何定义快速方法以及比较各种连接方法。以 issue 中的 benchmark-ips 示例为参考,使用运行时变量进行比较;完成标准是基准测试不再将解析时连接视为运行时操作,并公平地比较所述的替代方案。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Ruby
- 星标
- 5.7k
- 派生
- 370
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
fastruby/fast-ruby 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 52/100
-
难度 4/5 3-5 天 新手友好度 32/100
-
难度 3/5 1-2 天 新手友好度 35/100
-
难度 2/5 1-3 小时 新手友好度 45/100
-
难度 4/5 3-5 天 新手友好度 42/100
查看 fastruby/fast-ruby 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
TheOdinProject/curriculum#31417 · 2 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 65/100
glossarist/glossarist-ruby#238 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
palladius/rails8-app-on-gcp#145 ·