Fix 'Start-Benchmarking' to put 'TargetPSVersion' and 'TargetFramework' in separate parameter sets (#15508)
The CIs won't run for files under the path test/perf, because files there don't affect production code or tests.
This commit is contained in:
parent
e2ee8e7e1f
commit
6c8d7c0410
|
@ -24,12 +24,12 @@ This folder contains micro benchmarks that test the performance of PowerShell En
|
|||
You can run the benchmarks directly using `dotnet run` in this directory:
|
||||
1. To run the benchmarks in Interactive Mode, where you will be asked which benchmark(s) to run:
|
||||
```
|
||||
dotnet run -c Release
|
||||
dotnet run -c Release -f net6.0
|
||||
```
|
||||
|
||||
2. To list all available benchmarks ([read more](https://github.com/dotnet/performance/blob/main/docs/benchmarkdotnet.md#Listing-the-Benchmarks)):
|
||||
```
|
||||
dotnet run -c Release --list [flat/tree]
|
||||
dotnet run -c Release -f net6.0 --list [flat/tree]
|
||||
```
|
||||
|
||||
3. To filter the benchmarks using a glob pattern applied to `namespace.typeName.methodName` ([read more](https://github.com/dotnet/performance/blob/main/docs/benchmarkdotnet.md#Filtering-the-Benchmarks)]):
|
||||
|
@ -44,7 +44,11 @@ You can run the benchmarks directly using `dotnet run` in this directory:
|
|||
|
||||
You can also use the function `Start-Benchmarking` from the module [`perf.psm1`](../perf.psm1) to run the benchmarks:
|
||||
```powershell
|
||||
Start-Benchmarking [[-TargetPSVersion] <string>] [[-List] <string>] [[-Filter] <string[]>] [[-Artifacts] <string>] [-KeepFiles] [<CommonParameters>]
|
||||
Start-Benchmarking [-TargetFramework <string>] [-List <string>] [-Filter <string[]>] [-Artifacts <string>] [-KeepFiles] [<CommonParameters>]
|
||||
|
||||
Start-Benchmarking [-TargetPSVersion <string>] [-Filter <string[]>] [-Artifacts <string>] [-KeepFiles] [<CommonParameters>]
|
||||
|
||||
Start-Benchmarking -Runtime <string[]> [-Filter <string[]>] [-Artifacts <string>] [-KeepFiles] [<CommonParameters>]
|
||||
```
|
||||
Run `Get-Help Start-Benchmarking -Full` to see the description of each parameter.
|
||||
|
||||
|
|
|
@ -32,19 +32,19 @@ function Start-Benchmarking
|
|||
.PARAMETER KeepFiles
|
||||
Indicates to keep all temporary files produced for running benchmarks.
|
||||
#>
|
||||
[CmdletBinding(DefaultParameterSetName = 'Default')]
|
||||
[CmdletBinding(DefaultParameterSetName = 'TargetFramework')]
|
||||
param(
|
||||
[Parameter(ParameterSetName = 'Default')]
|
||||
[Parameter(ParameterSetName = 'TargetPSVersion')]
|
||||
[ValidatePattern(
|
||||
'^7\.(0|1|2)\.\d+(-preview\.\d{1,2})?$',
|
||||
ErrorMessage = 'The package version is invalid or not supported')]
|
||||
[string] $TargetPSVersion,
|
||||
|
||||
[Parameter(ParameterSetName = 'Default')]
|
||||
[Parameter(ParameterSetName = 'TargetFramework')]
|
||||
[ValidateSet('netcoreapp3.1', 'net5.0', 'net6.0')]
|
||||
[string] $TargetFramework = 'net6.0',
|
||||
|
||||
[Parameter(ParameterSetName = 'Default')]
|
||||
[Parameter(ParameterSetName = 'TargetFramework')]
|
||||
[ValidateSet('flat', 'tree')]
|
||||
[string] $List,
|
||||
|
||||
|
@ -70,23 +70,6 @@ function Start-Benchmarking
|
|||
Remove-Item -Path $Artifacts -Recurse -Force -ErrorAction Stop
|
||||
}
|
||||
|
||||
if ($TargetPSVersion) {
|
||||
## Validate the specified 'TargetPSVersion' and 'TargetFramework' are compatible.
|
||||
$TargetFramework -match '\d.\d' > $null
|
||||
$targetDotNetVersion = $Matches[0]
|
||||
|
||||
$minimalDotNetVersion = switch -Wildcard ($TargetPSVersion) {
|
||||
'7.0.*' { '3.1' }
|
||||
'7.1.*' { '5.0' }
|
||||
'7.2.*' { '6.0' }
|
||||
}
|
||||
|
||||
if ($targetDotNetVersion -lt $minimalDotNetVersion) {
|
||||
$dotnetVer = $minimalDotNetVersion -eq '3.1' ? 'netcoreapp3.1' : "net$minimalDotNetVersion"
|
||||
throw "The '$TargetPSVersion' version of 'Microsoft.PowerShell.SDK' requires '$dotnetVer' as the minimal target framework."
|
||||
}
|
||||
}
|
||||
|
||||
if ($Runtime) {
|
||||
## Remove duplicate values.
|
||||
$hash = [ordered]@{}
|
||||
|
@ -113,26 +96,35 @@ function Start-Benchmarking
|
|||
if ($List) { $runArgs += '--list', $List }
|
||||
if ($KeepFiles) { $runArgs += "--keepFiles" }
|
||||
|
||||
if ($PSCmdlet.ParameterSetName -eq 'Default') {
|
||||
if ($TargetPSVersion) {
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
'TargetPSVersion' {
|
||||
Write-Log -message "Run benchmarks targeting '$TargetFramework' and the 'Microsoft.PowerShell.SDK' version '$TargetPSVersion' ..."
|
||||
$env:PERF_TARGET_VERSION = $TargetPSVersion
|
||||
}
|
||||
elseif ($TargetFramework -eq 'net6.0') {
|
||||
Write-Log -message "Run benchmarks targeting the current PowerShell code base ..."
|
||||
}
|
||||
else {
|
||||
Write-Log -message "Run benchmarks targeting '$TargetFramework' and the corresponding latest version of 'Microsoft.PowerShell.SDK' ..."
|
||||
|
||||
## Use 'Release' instead of 'release' (note the capital case) because BDN uses 'Release' when building the auto-generated
|
||||
## project, and MSBuild somehow recognizes 'release' and 'Release' as two different configurations and thus will rebuild
|
||||
## all dependencies unnecessarily.
|
||||
dotnet run -c Release -f $TargetFramework $runArgs
|
||||
}
|
||||
|
||||
## Use 'Release' instead of 'release' (note the capital case) because BDN uses 'Release' when building the auto-generated
|
||||
## project, and MSBuild somehow recognizes 'release' and 'Release' as two different configurations and thus will rebuild
|
||||
## all dependencies unnecessarily.
|
||||
dotnet run -c Release -f $TargetFramework $runArgs
|
||||
}
|
||||
else {
|
||||
Write-Log -message "Run benchmarks targeting multiple .NET runtimes: $Runtime ..."
|
||||
dotnet run -c Release -f net6.0 --runtimes $Runtime $runArgs
|
||||
'TargetFramework' {
|
||||
$message = if ($TargetFramework -eq 'net6.0') { 'the current PowerShell code base ...' } else { "the corresponding latest version of 'Microsoft.PowerShell.SDK' ..." }
|
||||
Write-Log -message "Run benchmarks targeting '$TargetFramework' and $message"
|
||||
|
||||
## Use 'Release' instead of 'release' (note the capital case) because BDN uses 'Release' when building the auto-generated
|
||||
## project, and MSBuild somehow recognizes 'release' and 'Release' as two different configurations and thus will rebuild
|
||||
## all dependencies unnecessarily.
|
||||
dotnet run -c Release -f $TargetFramework $runArgs
|
||||
}
|
||||
|
||||
'Runtimes' {
|
||||
Write-Log -message "Run benchmarks targeting multiple .NET runtimes: $Runtime ..."
|
||||
|
||||
## Use 'Release' instead of 'release' (note the capital case) because BDN uses 'Release' when building the auto-generated
|
||||
## project, and MSBuild somehow recognizes 'release' and 'Release' as two different configurations and thus will rebuild
|
||||
## all dependencies unnecessarily.
|
||||
dotnet run -c Release -f net6.0 --runtimes $Runtime $runArgs
|
||||
}
|
||||
}
|
||||
|
||||
if (Test-Path $Artifacts) {
|
||||
|
@ -211,3 +203,5 @@ function Compare-BenchmarkResult
|
|||
Pop-Location
|
||||
}
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function 'Start-Benchmarking', 'Compare-BenchmarkResult'
|
||||
|
|
Loading…
Reference in a new issue