How to find minimum execution time in powershell?

Member

by kadin , in category: Third Party Scripts , 6 months ago

How to find minimum execution time in powershell?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by daisha , 6 months ago

@kadin 

To find the minimum execution time in PowerShell, you can use the Measure-Command cmdlet to measure the execution time of a scriptblock or command. Here's an example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$times = @()
1..10 | ForEach-Object {
    $time = (Measure-Command {
        # Your scriptblock or command goes here
        Start-Sleep -Seconds 1
    }).TotalMilliseconds
    $times += $time
}

$minTime = $times | Measure-Object -Minimum
Write-Host "Minimum execution time: $($minTime.Minimum)"


In this example, we are measuring the execution time of a Start-Sleep command that sleeps for 1 second, but you can replace it with your own scriptblock or command. The script runs the command 10 times and stores the execution times in an array. Then, we use the Measure-Object cmdlet to find the minimum execution time from the array and output it to the console.

Related Threads:

How to reduce execution time of graphql data fetching?
How to execute find command with powershell?
How to find time difference in seconds using moment.js?
How to find the last access time of a schema in oracle?
How to group time column into 5 second intervals and count rows using presto?
How to only display the minimum of a count in sparql?