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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
*.clixml text eol=crlf
*.xml text eol=crlf
*.txt text eol=crlf

Tests/large_sample.ini text eol=lf
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

- name: Cherry pick CHANGELOG.md
id: changelog
uses: MatteoCampinoti94/changelog-to-release@v1.0.0
uses: MatteoCampinoti94/changelog-to-release@v1
with:
version-name: ${{ github.ref_name }}
configuration: ./.github/changelog.configuration.json
Expand Down
18 changes: 18 additions & 0 deletions Tests/Helpers/Get-AverageExecutionTime.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function Get-AverageExecutionTime {
param (
[Parameter(Mandatory, Position = 0)]
[ScriptBlock]$ScriptBlock,

[Int] $Count
)

process {
$executionTimes = @()
for ($i = 0; $i -lt $Count; $i++) {
$executionTime = Measure-Command { & $ScriptBlock }
$executionTimes += $executionTime.TotalMilliseconds
}

[Math]::Round(($executionTimes | Measure-Object -Average).Average, 2)
}
}
45 changes: 45 additions & 0 deletions Tests/PsIni.Performance.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "5.7"; MaximumVersion = "5.999" }

Describe "Performance Tests" -Tag performance {
BeforeAll {
. "$PSScriptRoot/Helpers/Resolve-ModuleSource.ps1"
. "$PSScriptRoot/Helpers/Get-AverageExecutionTime.ps1"
$script:moduleToTest = Resolve-ModuleSource

Remove-Module PSIni -ErrorAction SilentlyContinue
Import-Module $moduleToTest -Force -ErrorAction Stop

$script:dummyFile = "TestDrive:\dummy_$(Get-Random).ini"
$script:bigIniFile = "$PSScriptRoot/large_sample.ini"
}

It "test file is larger than 2.5MB" {
(Get-Item $bigIniFile).Length | Should -BeGreaterThan 2.5MB
(Get-Item $bigIniFile).Length | Should -Be 2889891
}

Describe "Importing" {
BeforeAll {
$script:durationInMs = Get-AverageExecutionTime { Import-Ini $bigIniFile -ErrorAction Stop } -Count 10
}

It "processes a large INI file in less than <_> seconds" -TestCases @(
10, 5, 3, 2.5 #, 2, 1
) {
$durationInMs | Should -BeLessThan ($_ * 1000)
}
}

Describe "Exporting" {
BeforeAll {
$iniContent = Import-Ini $bigIniFile -ErrorAction Stop
$script:durationInMs = Get-AverageExecutionTime { $iniContent | Export-Ini -Path $dummyFile -ErrorAction Stop } -Count 10
}

It "exports a large INI file in less than <_> seconds" -TestCases @(
10, 5, 3, 2.5 #, 2, 1
) {
$durationInMs | Should -BeLessThan ($_ * 1000)
}
}
}
Loading
Loading