-
Notifications
You must be signed in to change notification settings - Fork 793
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Computation Expression Benchmarks (#16541)
* add benchmarks for various usages of CEs * refactor * move CE source files to dedicated ce folder
- Loading branch information
Showing
8 changed files
with
12,491 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
tests/benchmarks/FCSBenchmarks/CompilerServiceBenchmarks/ComputationExpressionBenchmarks.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
tests/benchmarks/FCSBenchmarks/CompilerServiceBenchmarks/ce/CE100xnest1.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } | ||
} |
Oops, something went wrong.