Skip to content

Add Computation Expression Benchmarks #16541

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

Merged
merged 4 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module FSharp.Benchmarks.ComputationExpressionBenchmarks

open System.IO
open BenchmarkDotNet.Attributes
open FSharp.Compiler.CodeAnalysis
open FSharp.Test.ProjectGeneration

[<Literal>]
let FSharpCategory = "fsharp"

[<MemoryDiagnoser>]
[<BenchmarkCategory(FSharpCategory)>]
type ComputationExpressionBenchmarks() =

let mutable sourceFileName = ""

[<Params("CE100xnest1.fs",
"CE100xnest5.fs",
// "CE100xnest10.fs", // enable if you have the spare time
"CE200xnest5.fs",
"CEwCO500xnest1.fs",
"CEwCO100xnest5.fs")>]
member public this.Source
with get () = File.ReadAllText(__SOURCE_DIRECTORY__ ++ "ce" ++ sourceFileName)
and set f = sourceFileName <- f

member val Benchmark = Unchecked.defaultof<_> with get, set

member this.setup(project) =
let checker = FSharpChecker.Create()
this.Benchmark <- ProjectWorkflowBuilder(project, checker = checker).CreateBenchmarkBuilder()
saveProject project false checker |> Async.RunSynchronously

[<GlobalSetup(Targets = [| "CheckCE"; "CompileCE" |])>]
member this.SetupWithSource() =
this.setup
{ SyntheticProject.Create() with
SourceFiles =
[

{ sourceFile "File" [] with
ExtraSource = this.Source
}
]
OtherOptions = []
}

[<Benchmark>]
member this.CheckCE() =
this.Benchmark { checkFile "File" expectOk }

[<Benchmark>]
member this.CompileCE() = this.Benchmark { compileWithFSC }
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<Compile Include="FileCascadeBenchmarks.fs" />
<Compile Include="GraphTypeCheckingBenchmarks.fs" />
<Compile Include="BackgroundCompilerBenchmarks.fs" />
<Compile Include="ComputationExpressionBenchmarks.fs" />
<Compile Include="Program.fs" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
module SomeModule =

type StrChainBuilder() =
member this.Zero() = ""
member this.Delay(f) = f ()
member this.Yield(x: string) = x
member this.Combine(a, b) = a + b

let strchain = StrChainBuilder()

let test =
// 100 x nesting of 1
strchain {
"test0"
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
strchain { "test1" }
}
Loading