2

I have been using Measure-Command in PowerShell to time the execution of a Python script:

Measure-Command{C:\Python27\python.exe script.py}

This displays the execution time in a number of forms, including TotalSeconds.

In order to minimize the effect of overhead, I would like to run the script 10 times and find the minimal TotalSeconds value across the 10 runs. Is there a simple way to do this in PowerShell?

1 Answer 1

4

Use Measure-Object command, like in this SO answer:

C:\PS> 1..10 | % { Measure-Command { C:\Python27\python.exe script.py } } | Measure-Object -Minimum

Count    : 3
Average  : 
Sum      : 
Maximum  : 
Minimum  : 00:00:00.0095165
Property : 
Sign up to request clarification or add additional context in comments.

1 Comment

It looks like the Measure-Object command needs to be Measure-Object -Minimum TotalSeconds, but otherwise this works well. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.