Skip to content

Commit 9868cff

Browse files
🩹 [Patch]: Resolve benchmark script linter warnings
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 77226c8 commit 9868cff

4 files changed

Lines changed: 25 additions & 20 deletions

File tree

tools/benchmark/Build-LocalModule.ps1

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
param(
1414
# Path to the module source folder. Defaults to <repo>/src.
1515
[Parameter()]
16-
[string] $SourcePath = (Join-Path $PSScriptRoot '..' '..' 'src'),
16+
[string] $SourcePath = (Join-Path -Path $PSScriptRoot -ChildPath '..\..\src'),
1717

1818
# Folder in which the 'Sodium' module folder is created.
1919
[Parameter(Mandatory)]
@@ -37,31 +37,31 @@ New-Item -ItemType Directory -Path $moduleDir -Force | Out-Null
3737
$sb = [System.Text.StringBuilder]::new()
3838
$publicFunctions = @()
3939

40-
foreach ($file in (Get-ChildItem (Join-Path $SourcePath 'variables' 'private') -Filter *.ps1 -ErrorAction SilentlyContinue)) {
40+
foreach ($file in (Get-ChildItem (Join-Path -Path $SourcePath -ChildPath 'variables\private') -Filter *.ps1 -ErrorAction SilentlyContinue)) {
4141
[void]$sb.AppendLine((Get-Content $file.FullName -Raw))
4242
}
43-
foreach ($file in (Get-ChildItem (Join-Path $SourcePath 'functions' 'private') -Filter *.ps1)) {
43+
foreach ($file in (Get-ChildItem (Join-Path -Path $SourcePath -ChildPath 'functions\private') -Filter *.ps1)) {
4444
[void]$sb.AppendLine((Get-Content $file.FullName -Raw))
4545
}
46-
foreach ($file in (Get-ChildItem (Join-Path $SourcePath 'functions' 'public') -Filter *.ps1)) {
46+
foreach ($file in (Get-ChildItem (Join-Path -Path $SourcePath -ChildPath 'functions\public') -Filter *.ps1)) {
4747
[void]$sb.AppendLine((Get-Content $file.FullName -Raw))
4848
$publicFunctions += $file.BaseName
4949
}
50-
$mainPath = Join-Path $SourcePath 'main.ps1'
50+
$mainPath = Join-Path -Path $SourcePath -ChildPath 'main.ps1'
5151
if (Test-Path $mainPath) {
5252
[void]$sb.AppendLine((Get-Content $mainPath -Raw))
5353
}
5454
[void]$sb.AppendLine("Export-ModuleMember -Function '$($publicFunctions -join "', '")' -Alias '*'")
5555

56-
Set-Content -Path (Join-Path $moduleDir 'Sodium.psm1') -Value $sb.ToString() -Encoding UTF8BOM
56+
Set-Content -Path (Join-Path -Path $moduleDir -ChildPath 'Sodium.psm1') -Value $sb.ToString() -Encoding UTF8BOM
5757

58-
Copy-Item -Path (Join-Path $SourcePath 'libs') -Destination $moduleDir -Recurse
58+
Copy-Item -Path (Join-Path -Path $SourcePath -ChildPath 'libs') -Destination $moduleDir -Recurse
5959

60-
New-ModuleManifest -Path (Join-Path $moduleDir 'Sodium.psd1') `
60+
New-ModuleManifest -Path (Join-Path -Path $moduleDir -ChildPath 'Sodium.psd1') `
6161
-RootModule 'Sodium.psm1' `
6262
-ModuleVersion '999.0.0' `
6363
-FunctionsToExport $publicFunctions `
6464
-CmdletsToExport @() -VariablesToExport @() -AliasesToExport @()
6565

6666
Write-Verbose "Built module at $moduleDir" -Verbose
67-
Join-Path $moduleDir 'Sodium.psd1'
67+
Join-Path -Path $moduleDir -ChildPath 'Sodium.psd1'

tools/benchmark/Invoke-ImportBenchmark.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ param(
3030
$ErrorActionPreference = 'Stop'
3131

3232
if (-not $ModulePath) {
33-
$ModulePath = & (Join-Path $PSScriptRoot 'Build-LocalModule.ps1') -OutputPath (Join-Path ([System.IO.Path]::GetTempPath()) 'SodiumBench')
33+
$ModulePath = & (Join-Path -Path $PSScriptRoot -ChildPath 'Build-LocalModule.ps1') -OutputPath (Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath 'SodiumBench')
3434
}
3535

3636
$times = for ($i = 0; $i -lt $Samples; $i++) {
@@ -50,7 +50,7 @@ $result = [pscustomobject]@{
5050
MinMs = [math]::Round($stats.Minimum, 1)
5151
MaxMs = [math]::Round($stats.Maximum, 1)
5252
}
53-
$result | Format-Table -AutoSize | Out-String | Write-Host
54-
$outFile = Join-Path $OutputPath "import-$Label.json"
53+
$result | Format-Table -AutoSize | Out-String | Write-Output
54+
$outFile = Join-Path -Path $OutputPath -ChildPath "import-$Label.json"
5555
$result | ConvertTo-Json | Set-Content -Path $outFile
5656
Write-Verbose "Saved $outFile" -Verbose

tools/benchmark/Invoke-PerformanceBenchmark.ps1

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ param(
3131
$ErrorActionPreference = 'Stop'
3232

3333
if (-not $ModulePath) {
34-
$ModulePath = & (Join-Path $PSScriptRoot 'Build-LocalModule.ps1') -OutputPath (Join-Path ([System.IO.Path]::GetTempPath()) 'SodiumBench')
34+
$ModulePath = & (Join-Path -Path $PSScriptRoot -ChildPath 'Build-LocalModule.ps1') -OutputPath (Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath 'SodiumBench')
3535
}
3636

3737
Import-Module $ModulePath -Force
3838

3939
function Measure-Op {
40+
<#
41+
.SYNOPSIS
42+
Measures an operation over N iterations and returns aggregate timing metrics.
43+
#>
4044
param([string]$Name, [scriptblock]$Setup, [scriptblock]$Op, [int]$N = $Iterations)
4145
$ctx = if ($Setup) { & $Setup } else { $null }
4246
for ($i = 0; $i -lt 25; $i++) { $null = & $Op $ctx }
@@ -99,11 +103,11 @@ $results += Measure-Op -Name 'Full roundtrip (keypair+seal+open)' -N ([math]::Ma
99103
}
100104

101105
$results += Measure-Op -Name 'ConvertTo-SodiumSealedBox invalid key (throw)' -N 500 -Op {
102-
try { ConvertTo-SodiumSealedBox -Message 'x' -PublicKey 'InvalidKey' } catch { }
106+
try { ConvertTo-SodiumSealedBox -Message 'x' -PublicKey 'InvalidKey' } catch { $null = $_ }
103107
}
104108

105109
$results += Measure-Op -Name 'Get-SodiumPublicKey invalid key (throw)' -N 500 -Op {
106-
try { Get-SodiumPublicKey -PrivateKey 'InvalidKey' } catch { }
110+
try { Get-SodiumPublicKey -PrivateKey 'InvalidKey' } catch { $null = $_ }
107111
}
108112

109113
# Mirrors the 'Parallel sessions' test context: module import + crypto roundtrip in 4 runspaces.
@@ -125,7 +129,7 @@ $results += [pscustomobject]@{
125129
OpsPerSec = [math]::Round(1 / $swPar.Elapsed.TotalSeconds, 2)
126130
}
127131

128-
$results | Format-Table -AutoSize | Out-String -Width 200 | Write-Host
129-
$outFile = Join-Path $OutputPath "bench-$Label.json"
132+
$results | Format-Table -AutoSize | Out-String -Width 200 | Write-Output
133+
$outFile = Join-Path -Path $OutputPath -ChildPath "bench-$Label.json"
130134
$results | ConvertTo-Json | Set-Content -Path $outFile
131135
Write-Verbose "Saved $outFile" -Verbose

tools/benchmark/Invoke-ProfilerTrace.ps1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,18 @@ param(
2727
$ErrorActionPreference = 'Stop'
2828

2929
if (-not $ModulePath) {
30-
$ModulePath = & (Join-Path $PSScriptRoot 'Build-LocalModule.ps1') -OutputPath (Join-Path ([System.IO.Path]::GetTempPath()) 'SodiumBench')
30+
$ModulePath = & (Join-Path -Path $PSScriptRoot -ChildPath 'Build-LocalModule.ps1') -OutputPath (Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath 'SodiumBench')
3131
}
3232

3333
Import-Module Profiler
3434
Import-Module $ModulePath -Force
3535

3636
$kp = New-SodiumKeyPair
3737
$box = ConvertTo-SodiumSealedBox -Message 'Hello world!' -PublicKey $kp.PublicKey
38+
$traceIterations = $Iterations
3839

3940
$trace = Trace-Script {
40-
for ($i = 0; $i -lt $Iterations; $i++) {
41+
for ($i = 0; $i -lt $traceIterations; $i++) {
4142
$null = New-SodiumKeyPair
4243
$null = New-SodiumKeyPair -Seed 'DeterministicSeed'
4344
$null = ConvertTo-SodiumSealedBox -Message 'Hello world!' -PublicKey $kp.PublicKey
@@ -49,6 +50,6 @@ $trace = Trace-Script {
4950

5051
$trace.Top50SelfDuration |
5152
Select-Object -First $Top SelfPercent, SelfDuration, HitCount, Function, Line, Text |
52-
Format-Table -AutoSize | Out-String -Width 220 | Write-Host
53+
Format-Table -AutoSize | Out-String -Width 220 | Write-Output
5354

5455
$trace

0 commit comments

Comments
 (0)