Skip to content

Instantly share code, notes, and snippets.

@SimonWahlin
Last active January 18, 2019 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SimonWahlin/449ab379509bb0f75851e6572e00a8f8 to your computer and use it in GitHub Desktop.
Save SimonWahlin/449ab379509bb0f75851e6572e00a8f8 to your computer and use it in GitHub Desktop.
Testing Speed
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