Using WIndows PowerShell 1.0 or 2.0 to evaluate performance of executable files.

Posted by Andry on Stack Overflow See other posts from Stack Overflow or by Andry
Published on 2011-03-04T23:20:07Z Indexed on 2011/03/04 23:24 UTC
Read the original article Hit count: 202

Filed under:
|
|

Hello!

I am writing a simple script on Windows PowerShell in order to evaluate performance of executable files.

The important hypothesisi is the following: I have an executable file, it can be an application written in any possible language (.net and not, Viual-Prolog, C++, C, everything that can be compiled as an .exe file). I want to profile it getting execution times.

I did this:

Function Time-It {
    Param ([string]$ProgramPath, [string]$Arguments)
    $Watch = New-Object System.Diagnostics.Stopwatch
    $NsecPerTick = (1000 * 1000 * 1000) / [System.Diagnostics.Stopwatch]::Frequency
    Write-Output "Stopwatch created! NSecPerTick = $NsecPerTick"
    $Watch.Start() # Starts the timer
    [System.Diagnostics.Process]::Start($ProgramPath, $Arguments)
    $Watch.Stop() # Stops the timer
    # Collectiong timings
    $Ticks = $Watch.ElapsedTicks
    $NSecs = $Watch.ElapsedTicks * $NsecPerTick
    Write-Output "Program executed: time is: $Nsecs ns ($Ticks ticks)"
}

This function uses stopwatch. Well, the functoin accepts a program path, the stopwatch is started, the program run and the stopwatch then stopped. Problem: the System.Diagnostics.Process.Start is asynchronous and the next instruction (watch stopped) is not executed when the application finishes. A new process is created...

I need to stop the timer once the program ends.

I thought about the Process class, thicking it held some info regarding the execution times... not lucky...

How to solve this?

© Stack Overflow or respective owner

Related posts about Performance

Related posts about powershell