Add to Technorati Favorites
Welcome to ThePowerShellGuy.com Sign in | Join | Help

PowerShell Performance Series Part 2 (Get-PerformanceHistory.ps1)

Jaykul, made a Get-PerformanceHistory function we also used during the Scripting games  but I could find only the CTP2 version in the repository , and to compare V1 to CTP2 we need to be able to run it on both versions, hence I used a quick one-liner to query the history, but Jaykul made an updated version that also works on V1    http://powershellcentral.com/scripts/424 and still has naming, the Average column, formatting linecount -etc

PoSH> Get-PerformanceHistory 7

Duration Average Commmand
-------- ------- --------
5.29700 0.00011 1..50000 | % { dummy }
4.03800 0.00008 1..50000 | % { $obj = 1 }
1.16000 0.00002 for($i = 0; $i -lt 50000;$i++ ) { dummy }
0.12400 0.00000 for($i = 0; $i -lt 50000;$i++ ) { $obj = 1 }
1.52900 0.00003 1..50000 |  &{ process {dummy} }
0.00000 0.00000 function k% ([scriptblock]$sb){process {&$sb }}
9.32100 0.00019 1..50000 | K% { dummy }

For the CTP2 version see :  http://powershellcentral.com/scripts/155 

This function is very handy, it also uses get-history we do not need to rerun a command  to time it, and the processing has no effect on the testing as processing is afterwards, using data available anyway, so we are able to use it anytime without preparements , so for future tests I'm going  to use this function.

enjoy,

Greetings /\/\o\/\/

Published Wednesday, June 11, 2008 8:34 PM by MoW
Filed under: ,

Comments

# re: PowerShell Performance Series Part 2 (Get-PerformanceHistory.ps1)

Hi MoW,

I did some performance test before. I paste some testcases here. Most of them are exploring the Invoke-Expression's overhead. I realize that so many people enjoys to execute codes using Invoke-Expression. So I think this topic would be useful.

overhead of calling Invoke-Expression:

Measure-Command -Expression {for ($($i = 0; $s = 0); $i -lt 50KB; $i++) { 1 -eq 1 }}

Measure-Command -Expression {for ($($i = 0; $s = 0); $i -lt 50KB; $i++) { iex '1 -eq 1' }}

Overhead of Calling other Cmdlet in Invoke-Expression:

Measure-Command -Expression {for ($($i = 0; $s = 0); $i -lt 1KB; $i++) { dir . > $null } }

Measure-Command -Expression {for ($($i = 0; $s = 0); $i -lt 1KB; $i++) { iex 'dir .' }}

Measure-Command {for ($i = 0; $i -lt 100KB; $i++) { '1' }}

Measure-Command {for ($i = 0; $i -lt 100KB; $i++) { iex '1' }}

Overhead of pipeline or Where-Object:

Measure-Command {1..100kb > $null}

Measure-Command {1..100kb | ?{$true} > $null}

I hope these trivial testcases can help you get this series more comprehensive.

Thursday, June 12, 2008 11:50 AM by Tao Ma

# re: PowerShell Performance Series Part 2 (Get-PerformanceHistory.ps1)

Tested your commands Tao on PowerShell v1.0.  I had to change them a bit to use the Get-PerformanceHistory script and to remove the effect of printing to the console (I don't know why the averages aren't working):

Duration-- Average--- Commmand

---------- ---------- --------

0:12.06250 0:12.06250 for ($($i = 0; $s = 0); $i -lt 50KB; $i++) { 1 -eq 1 > $null }

0:46.96875 0:46.96875 for ($($i = 0; $s = 0); $i -lt 50KB; $i++) { iex '1 -eq 1' > $null }

0:11.39062 0:11.39062 for ($($i = 0; $s = 0); $i -lt 1KB; $i++) { dir . > $null }

0:12.00000 0:12.00000 for ($($i = 0; $s = 0); $i -lt 1KB; $i++) { iex 'dir .' > $null }

0:23.57812 0:23.57812 for ($i = 0; $i -lt 100KB; $i++) { '1' > $null }

1:30.64062 1:30.64062 for ($i = 0; $i -lt 100KB; $i++) { iex '1' > $null }

0:00.48438 0:00.48438 1..40kb > $null

0:06.60938 0:06.60938 1..40kb | ?{$true} > $null

Thursday, June 12, 2008 1:46 PM by jasonmarcher

# re: PowerShell Performance Series Part 2 (Get-PerformanceHistory.ps1)

I decided to hand calculate the averages, since it makes it easier to see the real difference:

Duration   Average    Commmand

0000000000 0000000000 0000000000

0:12.06250 0:00.00023 for ($($i = 0; $s = 0); $i -lt 50KB; $i++) { 1 -eq 1 > $null }

0:46.96875 0:00.00091 for ($($i = 0; $s = 0); $i -lt 50KB; $i++) { iex '1 -eq 1' > $null }

0:11.39062 0:00.01112 for ($($i = 0; $s = 0); $i -lt 1KB; $i++) { dir . > $null }

0:12.00000 0:00.01171 for ($($i = 0; $s = 0); $i -lt 1KB; $i++) { iex 'dir .' > $null }

0:23.57812 0:00.00023 for ($i = 0; $i -lt 100KB; $i++) { '1' > $null }

1:30.64062 0:00.00088 for ($i = 0; $i -lt 100KB; $i++) { iex '1' > $null }

0:00.48438 0:00.00001 1..40kb > $null

0:06.60938 0:00.00016 1..40kb | ?{$true} > $null

Thursday, June 12, 2008 2:01 PM by jasonmarcher

# PowerShell Performance Series Part 2 (.NET method call not always faster as PowerShell shortcut)

  Continuing  on from Karl's post's : Fast New PSCustomObject. generating a "PropertyBag"

Sunday, June 15, 2008 11:14 AM by The PowerShell Guy
Anonymous comments are disabled