Skip to content

F# micro benchmarks #4051

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 3 commits into from
Mar 18, 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
32 changes: 32 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,21 @@ jobs:
- main
- 8.0

- template: /eng/performance/build_machine_matrix.yml
parameters:
jobTemplate: /eng/performance/benchmark_jobs.yml
buildMachines:
- win-x64
- ubuntu-x64
isPublic: true
jobParameters:
kind: fsharpmicro
csproj: src\benchmarks\micro-fsharp\MicrobenchmarksFSharp.fsproj
runCategories: 'FSharpMicro'
channels:
- main
- 8.0

# bepuphysics benchmarks
- template: /eng/performance/build_machine_matrix.yml
parameters:
Expand Down Expand Up @@ -488,6 +503,23 @@ jobs:
- main
- 8.0

- template: /eng/performance/build_machine_matrix.yml
parameters:
jobTemplate: /eng/performance/benchmark_jobs.yml
buildMachines:
- win-x64
- ubuntu-x64
- win-arm64
- ubuntu-arm64-ampere
isPublic: false
jobParameters:
kind: fsharpmicro
csproj: src\benchmarks\micro-fsharp\MicrobenchmarksFSharp.fsproj
runCategories: 'FSharpMicro'
channels:
- main
- 8.0

# bepuphysics benchmarks
- template: /eng/performance/build_machine_matrix.yml
parameters:
Expand Down
4 changes: 4 additions & 0 deletions src/benchmarks/micro-fsharp/Categories.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module MicroBenchmarks.FSharp.Categories

[<Literal>]
let FSharpMicroCategory = "FSharpMicro"
210 changes: 210 additions & 0 deletions src/benchmarks/micro-fsharp/Collections.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
module MicroBenchmarks.FSharp.Collections

open BenchmarkDotNet.Attributes

[<MemoryDiagnoser>]
[<BenchmarkCategory(Categories.FSharpMicroCategory)>]
type CollectionsBenchmark() =
let mutable length = 0
let mutable list = []
let mutable array = [||]

[<Params(1000, 10000)>]
member x.Length
with get () = length
and set (value) =
length <- value
list <- List.init length (fun _ -> 0)
array <- Array.init length (fun _ -> 0)

/// List
[<Benchmark>]
member x.ListRemoveAtBeginning() =
list
|> List.removeAt 0
|> ignore

[<Benchmark>]
member x.ListRemoveAtEnd() =
list
|> List.removeAt (x.Length - 1)
|> ignore

[<Benchmark>]
member x.ListRemoveManyAtBeginning() =
list
|> List.removeManyAt 0 10
|> ignore

[<Benchmark>]
member x.ListRemoveManyAtEnd() =
list
|> List.removeManyAt (x.Length - 11) 10
|> ignore

[<Benchmark>]
member x.ListInsertAtBeginning() =
list
|> List.insertAt 0 1
|> ignore

[<Benchmark>]
member x.ListInsertAtEnd() =
list
|> List.insertAt (x.Length - 1) 1
|> ignore

[<Benchmark>]
member x.ListInsertManyAtBeginning() =
list
|> List.insertManyAt 0 [1..10]
|> ignore

[<Benchmark>]
member x.ListInsertManyAtEnd() =
list
|> List.insertManyAt (x.Length - 11) [1..10]
|> ignore

[<Benchmark>]
member x.ListUpdateAtBeginning() =
list
|> List.updateAt 0 1
|> ignore

[<Benchmark>]
member x.ListUpdateEnd() =
list
|> List.updateAt (x.Length - 1) 1
|> ignore

/// Array
[<Benchmark>]
member x.ArrayRemoveAtBeginning() =
array
|> Array.removeAt 0
|> ignore

[<Benchmark>]
member x.ArrayRemoveAtEnd() =
array
|> Array.removeAt (x.Length - 1)
|> ignore

[<Benchmark>]
member x.ArrayRemoveManyAtBeginning() =
array
|> Array.removeManyAt 0 10
|> ignore

[<Benchmark>]
member x.ArrayRemoveManyAtEnd() =
array
|> Array.removeManyAt (x.Length - 11) 10
|> ignore

[<Benchmark>]
member x.ArrayInsertAtBeginning() =
array
|> Array.insertAt 0 1
|> ignore

[<Benchmark>]
member x.ArrayInsertAtEnd() =
array
|> Array.insertAt (x.Length - 1) 1
|> ignore

[<Benchmark>]
member x.ArrayInsertManyAtBeginning() =
array
|> Array.insertManyAt 0 [1..10]
|> ignore

[<Benchmark>]
member x.ArrayInsertManyAtEnd() =
array
|> Array.insertManyAt (x.Length - 11) [1..10]
|> ignore

[<Benchmark>]
member x.ArrayUpdateAtBeginning() =
array
|> Array.updateAt 0 1
|> ignore

[<Benchmark>]
member x.ArrayUpdateEnd() =
array
|> Array.updateAt (x.Length - 1) 1
|> ignore

/// Seq
[<Benchmark>]
member x.SeqBaseline() =
array
|> Seq.toList
|> ignore

[<Benchmark>]
member x.SeqRemoveAtBeginning() =
list
|> Seq.removeAt 0
|> Seq.toList
|> ignore

[<Benchmark>]
member x.SeqRemoveAtEnd() =
list
|> Seq.removeAt (x.Length - 1)
|> Seq.toList
|> ignore

[<Benchmark>]
member x.SeqRemoveManyAtBeginning() =
list
|> Seq.removeManyAt 0 10
|> Seq.toList
|> ignore

[<Benchmark>]
member x.SeqRemoveManyAtEnd() =
list
|> Seq.removeManyAt (x.Length - 11) 10
|> Seq.iter ignore

[<Benchmark>]
member x.SeqInsertAtBeginning() =
list
|> Seq.insertAt 0 1
|> Seq.iter ignore

[<Benchmark>]
member x.SeqInsertAtEnd() =
list
|> Seq.insertAt (x.Length - 1) 1
|> Seq.iter ignore

[<Benchmark>]
member x.SeqInsertManyAtBeginning() =
list
|> Seq.insertManyAt 0 [1..10]
|> Seq.iter ignore

[<Benchmark>]
member x.SeqInsertManyAtEnd() =
list
|> Seq.insertManyAt (x.Length - 11) [1..10]
|> Seq.iter ignore

[<Benchmark>]
member x.SeqUpdateAtBeginning() =
list
|> Seq.updateAt 0 1
|> Seq.iter ignore

[<Benchmark>]
member x.SeqUpdateEnd() =
list
|> Seq.updateAt (x.Length - 1) 1
|> Seq.iter ignore
20 changes: 20 additions & 0 deletions src/benchmarks/micro-fsharp/MicrobenchmarksFSharp.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>$(PERFLAB_TARGET_FRAMEWORKS)</TargetFrameworks>
<TargetFrameworks Condition="'$(TargetFrameworks)' == ''">net9.0</TargetFrameworks>
<LangVersion>preview</LangVersion>
</PropertyGroup>

<ItemGroup>
<Compile Include="Categories.fs" />
<Compile Include="Collections.fs" />
<Compile Include="Program.fs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\harness\BenchmarkDotNet.Extensions\BenchmarkDotNet.Extensions.csproj" />
</ItemGroup>

</Project>
37 changes: 37 additions & 0 deletions src/benchmarks/micro-fsharp/MicrobenchmarksFSharp.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.34714.246
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BenchmarkDotNet.Extensions", "..\..\harness\BenchmarkDotNet.Extensions\BenchmarkDotNet.Extensions.csproj", "{D44B5BFC-F333-4165-8830-437FBC8DF6BE}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "MicrobenchmarksFSharp", "MicrobenchmarksFSharp.fsproj", "{CB69071F-0252-4746-9870-786CF4ECCA35}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Reporting", "..\..\tools\Reporting\Reporting\Reporting.csproj", "{B24756BB-B4BB-491C-A053-3441C1030C77}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D44B5BFC-F333-4165-8830-437FBC8DF6BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D44B5BFC-F333-4165-8830-437FBC8DF6BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D44B5BFC-F333-4165-8830-437FBC8DF6BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D44B5BFC-F333-4165-8830-437FBC8DF6BE}.Release|Any CPU.Build.0 = Release|Any CPU
{CB69071F-0252-4746-9870-786CF4ECCA35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CB69071F-0252-4746-9870-786CF4ECCA35}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB69071F-0252-4746-9870-786CF4ECCA35}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB69071F-0252-4746-9870-786CF4ECCA35}.Release|Any CPU.Build.0 = Release|Any CPU
{B24756BB-B4BB-491C-A053-3441C1030C77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B24756BB-B4BB-491C-A053-3441C1030C77}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B24756BB-B4BB-491C-A053-3441C1030C77}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B24756BB-B4BB-491C-A053-3441C1030C77}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {59625A56-73BB-47B5-8B66-02F6918E41BD}
EndGlobalSection
EndGlobal
20 changes: 20 additions & 0 deletions src/benchmarks/micro-fsharp/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module MicroBenchmarks.FSharp.Program

open System
open System.IO
open System.Collections.Immutable

open BenchmarkDotNet.Running
open BenchmarkDotNet.Extensions

[<EntryPoint>]
let main args =
BenchmarkSwitcher
.FromAssembly(typeof<Collections.CollectionsBenchmark>.Assembly)
.Run(args, RecommendedConfig.Create(
artifactsPath = DirectoryInfo(
Path.Combine(
AppContext.BaseDirectory,
"BenchmarkDotNet.Artifacts")),
mandatoryCategories = ImmutableHashSet.Create Categories.FSharpMicroCategory))
.ToExitCode()