Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

string/concatenation.rb tests are misleading

未关闭
#64 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
45/100
Issue 类型
重构
描述清晰度
描述清楚
活跃度
停滞
技术栈
ruby

调研方向

从 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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

fastruby/fast-ruby 的其他 Issue

查看 fastruby/fast-ruby 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。