-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrace-Example.ps1
More file actions
33 lines (29 loc) · 1.11 KB
/
Trace-Example.ps1
File metadata and controls
33 lines (29 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#region setup
Import-Module "$(Get-Location)\PSPerformance.psm1"
$Services = Get-Service
#endregion
#region Initial Trace-Command
$BaselineCode = {
foreach ($svc in $Services) {
if ($svc.Status -eq 'Running' -and $Svc.StartupType -eq 'Automatic') {
Write-Output $svc.Name
}
}
}
Trace-Command -Name TypeConversion -ListenerOption Timestamp -Expression $BaselineCode -PSHost
#endregion
#region Trace-Command with Enum Called out
$OptimizedCode = {
foreach ($svc in $Services) {
if ($svc.Status -eq [System.ServiceProcess.ServiceControllerStatus]::Running -and $Svc.StartupType -eq [System.ServiceProcess.ServiceStartMode]::Automatic) {
Write-Output $svc.Name
}
}
}
Trace-Command -Name TypeConversion -ListenerOption Timestamp -Expression $OptimizedCode -PSHost
#endregion
#Lets Compare
$Baseline = Test-Performance -Count 10 -ScriptBlock $BaselineCode
$WithEnum = Test-Performance -Count 10 -ScriptBlock $OptimizedCode
Get-Winner -AName 'Baseline' -AValue $Baseline.Median -BName "Enumerated" -BValue $WithEnum.Median
#endregion