Timing a command's execution in PowerShell

前端 未结 7 847
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 01:13

Is there a simple way to time the execution of a command in PowerShell, like the \'time\' command in Linux?
I came up with this:

$s=Get-Date; .\\do_somet         


        
7条回答
  •  不知归路
    2020-11-28 01:56

    Here's a function I wrote which works similarly to the Unix time command:

    function time {
        Param(
            [Parameter(Mandatory=$true)]
            [string]$command,
            [switch]$quiet = $false
        )
        $start = Get-Date
        try {
            if ( -not $quiet ) {
                iex $command | Write-Host
            } else {
                iex $command > $null
            }
        } finally {
            $(Get-Date) - $start
        }
    }
    

    Source: https://gist.github.com/bender-the-greatest/741f696d965ed9728dc6287bdd336874

提交回复
热议问题