Skip to content
Draft
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
43 changes: 43 additions & 0 deletions Content/Library/.github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Benchmark

on:
push:
branches:
- MyReleaseBranch

permissions:
# contents permission to update benchmark contents in MyReleaseBranch
contents: write

jobs:
benchmark:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Setup necessary dotnet SDKs
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
10.x
- name: Run benchmarks
run: |
chmod +x ./build.sh
./build.sh RunBenchmarks
env:
CI: true
CONFIGURATION: Release
- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
with:
name: MyLib.1 Benchmark
tool: 'benchmarkdotnet'
output-file-path: 'BenchmarkDotNet.Artifacts/results/*.json'
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
gh-pages-branch: MyReleaseBranch
benchmark-data-dir-path: docs/benchmarks
# Show alert with commit comment on detecting possible performance regression
alert-threshold: '200%'
comment-on-alert: true
fail-on-alert: false
alert-comment-cc-users: '@MyGithubUsername'
3 changes: 3 additions & 0 deletions Content/Library/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,6 @@ tmp/
temp/
.fsdocs
docs/

# BenchmarkDotNet artifacts
BenchmarkDotNet.Artifacts/
1 change: 1 addition & 0 deletions Content/Library/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<PackageVersion Include="Fake.BuildServer.GitHubActions" Version="$(FakeVersion)" />
<PackageVersion Include="MSBuild.StructuredLogger" Version="2.2.441" />
<PackageVersion Include="Argu" Version="6.0" />
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />

<!-- Analyzers -->
<PackageVersion Include="FSharp.Analyzers.Build" Version="0.4.0" />
Expand Down
6 changes: 6 additions & 0 deletions Content/Library/MyLib.1.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,11 @@
<Platform Solution="*|x86" Project="x86" />
</Project>
</Folder>
<Folder Name="/benchmarks/">
<Project Path="benchmarks/MyLib.1.Benchmarks/MyLib.1.Benchmarks.fsproj">
<Platform Solution="*|x64" Project="x64" />
<Platform Solution="*|x86" Project="x86" />
</Project>
</Folder>
<Project Path="build/build.fsproj" />
</Solution>
1 change: 1 addition & 0 deletions Content/Library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ src/MyLib.1/bin/
- `GenerateCoverageReport` - Code coverage is run during `DotnetTest` and this generates a report via [ReportGenerator](https://github.com/danielpalme/ReportGenerator).
- `ShowCoverageReport` - Shows the report generated in `GenerateCoverageReport`.
- `WatchTests` - Runs [dotnet watch](https://docs.microsoft.com/en-us/aspnet/core/tutorials/dotnet-watch?view=aspnetcore-3.0) with the test projects. Useful for rapid feedback loops.
- `RunBenchmarks` - Runs [BenchmarkDotNet](https://benchmarkdotnet.org/) benchmarks in the `benchmarks` folder.
- `GenerateAssemblyInfo` - Generates [AssemblyInfo](https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.applicationservices.assemblyinfo?view=netframework-4.8) for libraries.
- `DotnetPack` - Runs [dotnet pack](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-pack). This includes running [Source Link](https://github.com/dotnet/sourcelink).
- `SourceLinkTest` - Runs a Source Link test tool to verify Source Links were properly generated.
Expand Down
3 changes: 3 additions & 0 deletions Content/Library/benchmarks/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
<Import Project="../Directory.Build.props" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace MyLib._1.Benchmarks

open BenchmarkDotNet.Attributes
open MyLib._1
open System

[<MemoryDiagnoser>]
type LibraryBenchmarks() =

let samplePerson = {
Say.Person.Name = "Benchmark"
Say.Person.FavoriteNumber = 42
Say.Person.FavoriteColor = Say.FavoriteColor.Blue
Say.Person.DateOfBirth = DateTimeOffset.Now
}

[<Benchmark>]
member _.HelloPerson() = Say.helloPerson samplePerson

[<Benchmark>]
member _.AddNumbers() = Say.add 100 200

[<Benchmark>]
member _.AddNumbersLoop() =
let mutable result = 0

for i in 1..1000 do
result <- Say.add result i

result
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../../src/MyLib.1/MyLib.1.fsproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" />
</ItemGroup>
<ItemGroup>
<Compile Include="Library.Benchmarks.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
</Project>
11 changes: 11 additions & 0 deletions Content/Library/benchmarks/MyLib.1.Benchmarks/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Program

open BenchmarkDotNet.Running
open MyLib._1.Benchmarks

[<EntryPoint>]
let main args =
BenchmarkRunner.Run<LibraryBenchmarks>()
|> ignore

0
15 changes: 15 additions & 0 deletions Content/Library/build/build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,17 @@ let watchTests _ =

cancelEvent.Cancel <- true

let benchmarksGlob =
rootDirectory
</> "benchmarks/**/*.??proj"

let runBenchmarks _ =
!!benchmarksGlob
|> Seq.iter (fun proj ->
DotNet.exec id "run" $"--project \"{proj}\" --configuration Release"
|> ignore
)

let generateAssemblyInfo _ =

let (|Fsproj|Csproj|Vbproj|) (projFileName: string) =
Expand Down Expand Up @@ -731,6 +742,7 @@ let initTargets () =
Target.create "GenerateCoverageReport" generateCoverageReport
Target.create "ShowCoverageReport" showCoverageReport
Target.create "WatchTests" watchTests
Target.create "RunBenchmarks" runBenchmarks
Target.create "GenerateAssemblyInfo" generateAssemblyInfo
Target.create "DotnetPack" dotnetPack
Target.create "SourceLinkTest" sourceLinkTest
Expand Down Expand Up @@ -786,6 +798,9 @@ let initTargets () =
"DotnetBuild"
==>! "WatchDocs"

"DotnetBuild"
==>! "RunBenchmarks"

"DotnetTest"
==> "GenerateCoverageReport"
==>! "ShowCoverageReport"
Expand Down
11 changes: 11 additions & 0 deletions Content/Library/docsSrc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,15 @@ I created it because I had to solve an issue with this other thing.
</div>
</div>
</div>
<div class="col">
<div class="card h-100">
<div class="card-body">
<h5 class="card-title">Benchmarks</h5>
<p class="card-text">Performance benchmark results over time.</p>
</div>
<div class="card-footer text-right border-top-0">
<a href="{{root}}benchmarks/index.html" class="btn btn-primary">View Benchmarks</a>
</div>
</div>
</div>
</div>
13 changes: 13 additions & 0 deletions tests/MiniScaffold.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,15 @@ module Tests =
"-n MyCoolLib --githubUsername CoolPersonNo2",
[
yield! projectStructureAsserts
Assert.``File exists`` ".github/workflows/benchmark.yml"
Assert.``File exists``
"benchmarks/MyCoolLib.Benchmarks/MyCoolLib.Benchmarks.fsproj"
Assert.``File exists``
"benchmarks/MyCoolLib.Benchmarks/Library.Benchmarks.fs"
Assert.``File exists`` "benchmarks/MyCoolLib.Benchmarks/Program.fs"
Assert.``project can build target`` "DotnetPack"
Assert.``project can build target`` "BuildDocs"
Assert.``project can build target`` "RunBenchmarks"
]


Expand Down Expand Up @@ -187,6 +194,12 @@ module Tests =
"-n fsharp-data-sample --githubUsername CoolPersonNo2",
[
yield! projectStructureAsserts
Assert.``File exists`` ".github/workflows/benchmark.yml"
Assert.``File exists``
"benchmarks/fsharp-data-sample.Benchmarks/fsharp-data-sample.Benchmarks.fsproj"
Assert.``File exists``
"benchmarks/fsharp-data-sample.Benchmarks/Library.Benchmarks.fs"
Assert.``File exists`` "benchmarks/fsharp-data-sample.Benchmarks/Program.fs"
Assert.``project can build target`` "DotnetPack"
]
testCase,
Expand Down