-
Notifications
You must be signed in to change notification settings - Fork 830
Use String.concat to concatenate command line arguments
#9297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
d813884 to
ac4a13b
Compare
|
@saul, I think the test failed because it expected an additional newline. |
|
I'm not sure how to read that chart, but isn't this saying that the 4.3s is coming from |
|
Yes all of the Seq.fold slowness is due to String.Concat (the BCL method). I replaced it with String.concat (the F# wrapper that passes to String.Join) as that uses StringBuilder under the hood. Sorry if my description was confusing! |
|
Thanks, looks good. I did a quick benchmark and it likely corroborates your own findings 🙂 // Learn more about F# at http://docs.microsoft.com/dotnet/fsharp
open System
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running
[<MemoryDiagnoser>]
type ConcatBench() =
let strings = [ for x in 0..100 -> sprintf "--commandlinearg:%d" x ]
[<Benchmark(Baseline=true)>]
member _.SeqFold() =
strings
|> Seq.fold (fun acc f -> acc + f + Environment.NewLine) ""
|> ignore
[<Benchmark>]
member _.FSharpCoreStringConcat() =
strings
|> String.concat Environment.NewLine
|> ignore
[<EntryPoint>]
let main argv =
let summary = BenchmarkRunner.Run<ConcatBench>()
printfn "%A" summary
0 // return an integer exit code.NET Framework:
On .NET 5:
|
|
Really appreciate the quick turnaround, thanks both :) |
* Use `String.concat` to concatenate command line arguments * Fix newline at end of cmd Co-authored-by: Kevin Ransom (msft) <[email protected]>
While profiling design time builds I noticed that the Seq.fold here is responsible for most of the Fsc task's run time: