小编Bob*_*Bob的帖子

如何保证在Powershell中实例化对象的顺序?

这是相当简单的代码块使用时间的Measure-Command,[system.diagnostics.stopwatch]或通过版本比较了几个Get-Date电话,但这里的奇怪的事情;

当我包装Measure-Command两个日期对象时,有时Measure-Command.TotalMilliseconds长于($EndTime - $StartTime).TotalMilliSeconds。

完成$EndTime之前是否实例化了对象Measure-Command?

如果我运行单线程,为什么仍会发生这种情况?powershell.exe -sta?

结束后是否有任何强制$EndTime设置的方法Measure-Command?

StartTime之前有没有保证Measure-Command?

显然,这种特定方法不是评估代码执行时间的明智方法。

$Stopwatch = [system.diagnostics.stopwatch]::startNew() 
$mc =Measure-Command{Invoke-WebRequest -Uri "http://www.google.com" -Method Head}
$Stopwatch.stop()


$mc.TotalMilliseconds
$Stopwatch.Elapsed.TotalMilliSeconds
"="
 $Stopwatch.Elapsed.TotalMilliSeconds - $mc.TotalMilliseconds


"`n"

$StartTime = (get-Date)
$mc = Measure-Command{Invoke-WebRequest -Uri "http://www.google.com" -Method Head}
$EndTime = (get-Date)

$mc.TotalMilliseconds
($EndTime - $StartTime).TotalMilliSeconds
"="
($EndTime - $StartTime).TotalMilliSeconds - $mc.TotalMilliseconds #This should never be negative …
Run Code Online (Sandbox Code Playgroud)

powershell multithreading

5
推荐指数
1
解决办法
65
查看次数

标签 统计

multithreading ×1

powershell ×1