XPerf
语言C#证据

cs-string-plus-hot — 循环中的 string +=

状态: 已测量

主张

在循环中使用不可变的 string += 比使用 StringBuilder 对于 N=30000 慢得多。

如何测量

运行时(本证据文件)

FieldValue
时间2026-10-22 亚洲/上海 (JSONL ts 为 UTC)
dotnet8.0.32
string_plus_equals 之前的中位数226.0176 毫秒
(stringbuilder) 后的中位数0.0885 毫秒
压缩前/后比例~2554×

与 lint 的对应

csharpperf-lint cs-string-plus-hot:保持默认严重性。

限制

  • 默认保持关闭。大比例是无I/O的CPU/分配。