You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Existing Issue: Search the existing issues for this repository. If there is an issue that fits your needs do not file a new one. Subscribe, react, or comment on that issue instead.
Descriptive Title: Write the title for this issue as a short synopsis. If possible, provide context. For example, "Document new Get-Foo cmdlet" instead of "New cmdlet."
PowerShell Version
5.1, 7.2, 7.3, 7.4
Summary
I would like to suggest updating the String addition section of the Performance docs to show unified tests between StringBuilder, addition assignment op += and -join operator similar to the ones used in #9997, this would help giving a better performance perspective as well as add fairness to the tests.
It's worth noting that these tests are executing in the caller's Scope since Measure-Command dot sources the Script Block, performance tests should always be executed in their own scope & { } to add fairness and perhaps more accurate results.
Thanks for your update, I think it is a nice improvement of this section.
The only thing that keeps singing in the back of my mind that sometimes you better off with not concatenating strings at all and just pipe them through (as usually adviced with objects).
In a pipeline like:
Don't blindly use e.g. the string builder on the whole content because "it is faster".
But this comment comes probably down to a stricter general note (or warning)
Note
Many of the techniques described here aren't idiomatic PowerShell and may reduce the readability of a PowerShell script. Besides, as they often choke the PowerShell pipeline, they might consume considerable more memory. Script authors are advised to use idiomatic PowerShell unless performance dictates otherwise.
@iRon7 I agree with that but the doc section is making a recommendation about string addition not about how to write output to a file. Also the perf tests are describing an extreme scenario, nobody would / should be adding to a string so many times but in case they are, then its good to advise on which technique is better.
Prerequisites
Get-Foo
cmdlet" instead of "New cmdlet."PowerShell Version
5.1, 7.2, 7.3, 7.4
Summary
I would like to suggest updating the String addition section of the Performance docs to show unified tests between StringBuilder, addition assignment op
+=
and-join
operator similar to the ones used in #9997, this would help giving a better performance perspective as well as add fairness to the tests.The doc is currently offering measurements like:
When the fair test would've been:
It's worth noting that these tests are executing in the caller's Scope since
Measure-Command
dot sources the Script Block, performance tests should always be executed in their own scope& { }
to add fairness and perhaps more accurate results.Details
Proposed Performance Tests
Measurements Results
.NET - PowerShell 7.4.0-preview.3
.NET Framework - Windows PowerShell 5.1
Proposed Content Type
About Topic, Concept
Proposed Title
No response
Related Articles
The text was updated successfully, but these errors were encountered: