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

on:
push:
branches:
- MyReleaseBranch
pull_request:
branches:
- MyReleaseBranch

jobs:
benchmark:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Setup necessary dotnet SDKs
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.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: 'benchmarks/**/BenchmarkDotNet.Artifacts/results/*.json'
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
# 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'
1 change: 1 addition & 0 deletions Content/Library/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
<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" />
</ItemGroup>
</Project>
17 changes: 17 additions & 0 deletions Content/Library/MyLib.1.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{ACBEE43C
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "MyLib.1.Tests", "tests\MyLib.1.Tests\MyLib.1.Tests.fsproj", "{1CA2E092-2320-451D-A4F0-9ED7C7C528CA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{B5B6CE6A-9B36-4F0F-8624-9B2CE14AC287}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "MyLib.1.Benchmarks", "benchmarks\MyLib.1.Benchmarks\MyLib.1.Benchmarks.fsproj", "{E6C4F8E5-9B5D-4A12-8F1E-2A9C7D3E4B6F}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "build", "build\build.fsproj", "{40D2259D-991D-44C4-B45D-C88CE0710C23}"
EndProject
Global
Expand Down Expand Up @@ -62,9 +66,22 @@ Global
{40D2259D-991D-44C4-B45D-C88CE0710C23}.Release|x64.Build.0 = Release|Any CPU
{40D2259D-991D-44C4-B45D-C88CE0710C23}.Release|x86.ActiveCfg = Release|Any CPU
{40D2259D-991D-44C4-B45D-C88CE0710C23}.Release|x86.Build.0 = Release|Any CPU
{E6C4F8E5-9B5D-4A12-8F1E-2A9C7D3E4B6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E6C4F8E5-9B5D-4A12-8F1E-2A9C7D3E4B6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E6C4F8E5-9B5D-4A12-8F1E-2A9C7D3E4B6F}.Debug|x64.ActiveCfg = Debug|x64
{E6C4F8E5-9B5D-4A12-8F1E-2A9C7D3E4B6F}.Debug|x64.Build.0 = Debug|x64
{E6C4F8E5-9B5D-4A12-8F1E-2A9C7D3E4B6F}.Debug|x86.ActiveCfg = Debug|x86
{E6C4F8E5-9B5D-4A12-8F1E-2A9C7D3E4B6F}.Debug|x86.Build.0 = Debug|x86
{E6C4F8E5-9B5D-4A12-8F1E-2A9C7D3E4B6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E6C4F8E5-9B5D-4A12-8F1E-2A9C7D3E4B6F}.Release|Any CPU.Build.0 = Release|Any CPU
{E6C4F8E5-9B5D-4A12-8F1E-2A9C7D3E4B6F}.Release|x64.ActiveCfg = Release|x64
{E6C4F8E5-9B5D-4A12-8F1E-2A9C7D3E4B6F}.Release|x64.Build.0 = Release|x64
{E6C4F8E5-9B5D-4A12-8F1E-2A9C7D3E4B6F}.Release|x86.ActiveCfg = Release|x86
{E6C4F8E5-9B5D-4A12-8F1E-2A9C7D3E4B6F}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{5D30E174-2538-47AC-8443-318C8C5DC2C9} = {C397A34C-84F1-49E7-AEBC-2F9F2B196216}
{1CA2E092-2320-451D-A4F0-9ED7C7C528CA} = {ACBEE43C-7A88-4FB1-9B06-DB064D22B29F}
{E6C4F8E5-9B5D-4A12-8F1E-2A9C7D3E4B6F} = {B5B6CE6A-9B36-4F0F-8624-9B2CE14AC287}
EndGlobalSection
EndGlobal
1 change: 1 addition & 0 deletions Content/Library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,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>net8.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
21 changes: 21 additions & 0 deletions Content/Library/build/build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,23 @@ let watchTests _ =

cancelEvent.Cancel <- true

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

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

if
result.ExitCode
<> 0
then
Trace.traceError $"Warning: Benchmark failed for project %s{proj}"
Trace.traceError "This may be due to sandbox environment limitations"
)

let generateAssemblyInfo _ =

let (|Fsproj|Csproj|Vbproj|) (projFileName: string) =
Expand Down Expand Up @@ -727,6 +744,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 @@ -782,6 +800,9 @@ let initTargets () =
"DotnetBuild"
==>! "WatchDocs"

"DotnetBuild"
==>! "RunBenchmarks"

"DotnetTest"
==> "GenerateCoverageReport"
==>! "ShowCoverageReport"
Expand Down
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
Loading