你能告诉我详细的时间命令执行流程吗?
我在powershell中有一个用户创建的函数,它将按以下方式计算执行命令的时间.1.它将打开新的PowerShell窗口.2.它将执行命令.它将关闭powershell窗口.3.它将使用GetProcessTimes函数获得不同的执行时间.网址ref:http://msdn.microsoft.com/en-us/library/windows/desktop/ms683223( v = vs.85).aspx
我想知道unix中的"time command"是否也以同样的方式计算.
谢谢你的意见.
Sha*_*evy 15
该Measure-Command
cmdlet的是你的朋友.
PS> Measure-Command -Expression {dir}
Run Code Online (Sandbox Code Playgroud)
您还可以从命令历史记录(此示例中的上一次执行命令)获取执行时间:
$h = Get-History -Count 1
$h.EndExecutionTime - $h.StartExecutionTime
Run Code Online (Sandbox Code Playgroud)
我一直在这样做:
Time {npm --version ; node --version}
Run Code Online (Sandbox Code Playgroud)
使用此功能,您可以将其放入$profile
文件中:
function Time([scriptblock]$scriptblock, $name)
{
<#
.SYNOPSIS
Run the given scriptblock, and say how long it took at the end.
.DESCRIPTION
.PARAMETER scriptBlock
A single computer name or an array of computer names. You mayalso provide IP addresses.
.PARAMETER name
Use this for long scriptBlocks to avoid quoting the entire script block in the final output line
.EXAMPLE
time { ls -recurse}
.EXAMPLE
time { ls -recurse} "All the things"
#>
if (!$stopWatch)
{
$script:stopWatch = new-object System.Diagnostics.StopWatch
}
$stopWatch.Reset()
$stopWatch.Start()
. $scriptblock
$stopWatch.Stop()
if ($name -eq $null) {
$name = "$scriptblock"
}
"Execution time: $($stopWatch.ElapsedMilliseconds) ms for $name"
}
Run Code Online (Sandbox Code Playgroud)
Measure-Command
工作,但它吞下了正在运行的命令的标准输出。(另请参阅在 PowerShell 中计时命令的执行)
归档时间: |
|
查看次数: |
2032 次 |
最近记录: |