Skip to content

Commit a4bd607

Browse files
xperiandriclaude
andcommitted
Add compiler benchmarks for mixed ranges, explicit yield! and flat literals
Each benchmark checks a list of Count elements, a range at every tenth one in the mixed and the explicit form, with Count 250, 500 and 1000. The flat literal is the baseline. Mixed ranges are checked by the sequence-expression checker like the explicit form, so the two scale alike and the flat literal does not. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 0a45f70 commit a4bd607

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

‎tests/benchmarks/FCSBenchmarks/CompilerServiceBenchmarks/FSharp.Compiler.Benchmarks.fsproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<Compile Include="GraphTypeCheckingBenchmarks.fs" />
1515
<Compile Include="BackgroundCompilerBenchmarks.fs" />
1616
<Compile Include="ComputationExpressionBenchmarks.fs" />
17+
<Compile Include="MixedRangeBenchmarks.fs" />
1718
<Compile Include="ProjectProbes.fs" />
1819
<Compile Include="NamespaceImportBenchmarks.fs" />
1920
<Compile Include="Program.fs" />
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
module FSharp.Benchmarks.MixedRangeBenchmarks
2+
3+
open BenchmarkDotNet.Attributes
4+
open FSharp.Compiler.CodeAnalysis
5+
open FSharp.Test.ProjectGeneration
6+
open FSharp.Benchmarks.Common.Categories
7+
8+
let private literal count element =
9+
let elements = [ for i in 0 .. count - 1 -> element i ] |> String.concat "; "
10+
$"let xs = [ {elements} ]"
11+
12+
let private flat count = literal count string
13+
14+
let private mixed count =
15+
literal count (fun i -> if i % 10 = 0 then $"{i}..{i + 1}" else string i)
16+
17+
let private explicitYield count =
18+
literal count (fun i -> if i % 10 = 0 then $"yield! [ {i}..{i + 1} ]" else $"yield {i}")
19+
20+
[<MemoryDiagnoser>]
21+
[<SimpleJob(warmupCount = 1, iterationCount = 4)>]
22+
[<BenchmarkCategory(LongCategory)>]
23+
type MixedRangeBenchmarks() =
24+
25+
[<Params(250, 500, 1_000)>]
26+
member val Count = 0 with get, set
27+
28+
member val Benchmark = Unchecked.defaultof<_> with get, set
29+
30+
member this.setup(extraSource) =
31+
let project =
32+
{ SyntheticProject.Create() with
33+
SourceFiles = [ { sourceFile "File" [] with ExtraSource = extraSource } ]
34+
OtherOptions = [ "--langversion:preview" ] }
35+
36+
let checker = FSharpChecker.Create()
37+
this.Benchmark <- ProjectWorkflowBuilder(project, checker = checker).CreateBenchmarkBuilder()
38+
saveProject project false checker |> Async.RunSynchronously
39+
40+
[<IterationSetup>]
41+
member this.StartIteration() =
42+
this.Benchmark.Checker.InvalidateAll()
43+
this.Benchmark.Checker.ClearLanguageServiceRootCachesAndCollectAndFinalizeAllTransients()
44+
45+
[<GlobalSetup(Target = "CheckFlat")>]
46+
member this.SetupFlat() = this.setup (flat this.Count)
47+
48+
[<GlobalSetup(Target = "CheckMixedRange")>]
49+
member this.SetupMixedRange() = this.setup (mixed this.Count)
50+
51+
[<GlobalSetup(Target = "CheckExplicitYield")>]
52+
member this.SetupExplicitYield() = this.setup (explicitYield this.Count)
53+
54+
[<Benchmark(Baseline = true)>]
55+
member this.CheckFlat() =
56+
this.Benchmark { checkFile "File" expectOk }
57+
58+
[<Benchmark>]
59+
member this.CheckMixedRange() =
60+
this.Benchmark { checkFile "File" expectOk }
61+
62+
[<Benchmark>]
63+
member this.CheckExplicitYield() =
64+
this.Benchmark { checkFile "File" expectOk }

0 commit comments

Comments
 (0)