Last active
January 18, 2019 07:46
-
-
Save SimonWahlin/449ab379509bb0f75851e6572e00a8f8 to your computer and use it in GitHub Desktop.
Testing Speed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Send-PSNotification { | |
[cmdletbinding()] | |
param( | |
[Parameter(Mandatory,ValueFromPipeline,Position=0)] | |
[object] | |
$Body, | |
[String] | |
$Summary = 'PowerShell Notification', | |
[ValidateSet('low', 'normal', 'critical')] | |
$Urgency, | |
[int] | |
$ExpireTime, | |
[string[]] | |
$Icon = "powershell-logo", | |
[string[]] | |
$Category, | |
[string] | |
[ValidateNotNullOrEmpty()] | |
$SoundFile | |
) | |
$notifySendArgs = @() | |
switch ($true) { | |
([bool]$Urgency) { $notifySendArgs += "--urgency=$Urgency" } | |
([bool]$ExpireTime) { $notifySendArgs += "--expire-time=$ExpireTime" } | |
([bool]$Catagory) { $notifySendArgs += "--category=$($Catagory -join ',')" } | |
([bool]$SoundFile) { $notifySendArgs += "--hint=string:sound-file:$SoundFile" } | |
([bool]$Icon) { | |
if ($Icon -eq "powershell-logo") { | |
Add-DefaultPSIcon | |
} | |
$notifySendArgs += "--icon=$($Icon -join ',')" | |
} | |
Default {} | |
} | |
} | |
Write-Verbose -Message 'Testing original switch' -Verbose | |
$Watch = [System.Diagnostics.Stopwatch]::StartNew() | |
1..1000000 | foreach {Send-PSNotification -Body 'sdf' -Summary 'sum' -Urgency critical -ExpireTime 4 -Icon 'testIcon'} | |
$Watch.Stop() | |
$Watch.Elapsed | |
function Send-PSNotification { | |
[cmdletbinding()] | |
param( | |
[Parameter(Mandatory,ValueFromPipeline,Position=0)] | |
[object] | |
$Body, | |
[String] | |
$Summary = 'PowerShell Notification', | |
[ValidateSet('low', 'normal', 'critical')] | |
$Urgency, | |
[int] | |
$ExpireTime, | |
[string[]] | |
$Icon = "powershell-logo", | |
[string[]] | |
$Category, | |
[string] | |
[ValidateNotNullOrEmpty()] | |
$SoundFile | |
) | |
$notifySendArgs = switch ($PSBoundParameters.Keys) { | |
'Urgency' { "--urgency=$Urgency" } | |
'ExpireTime' { "--expire-time=$ExpireTime" } | |
'Catagory' { "--category=$($Catagory -join ',')" } | |
'SoundFile' { "--hint=string:sound-file:$SoundFile" } | |
'Icon' { | |
if ($Icon -eq "powershell-logo") { | |
Add-DefaultPSIcon | |
} | |
"--icon=$($Icon -join ',')" | |
} | |
default {} | |
} | |
} | |
Write-Verbose -Message 'Testing looping switch' -Verbose | |
$Watch = [System.Diagnostics.Stopwatch]::StartNew() | |
1..1000000 | foreach {Send-PSNotification -Body 'sdf' -Summary 'sum' -Urgency critical -ExpireTime 4 -Icon 'testIcon'} | |
$Watch.Stop() | |
$Watch.Elapsed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment