wordpress   发布时间:2022-04-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了使用WIndows PowerShell 1.0或2.0来评估可执行文件的性能大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我正在 Windows PowerSHell上编写一个简单的脚本,以评估可执行文件的性能. 重要的假设如下:我有一个可执行文件,它可以是用任何可能的语言编写的应用程序(.net而不是,Viual-Prolog,C,C,可以编译为.exe文件的所有内容).我想描述一下执行时间. 我这样做了: Function Time-It { Param ([String]$ProgramPath, [s
我正在 Windows PowerSHell上编写一个简单的脚本,以评估可执行文件性能.

重要的假设如下:我有一个可执行文件,它可以是用任何可能的语言编写的应用程序(.net而不是,Viual-Prolog,C,可以编译为.exe文件的所有内容).我想描述一下执行时间.

我这样做了

Function Time-It {
    Param ([String]$ProgramPath,[String]$Arguments)
    $Watch = New-Object System.Diagnostics.Stopwatch
    $NsecPerTick = (1000 * 1000 * 1000) / [System.Diagnostics.Stopwatch]::Frequency
    Write-Output "Stopwatch created! NSecPerTick = $NsecPerTick"
    $Watch.Start() # Starts the timer
    [System.Diagnostics.process]::Start($ProgramPath,$Arguments)
    $Watch.Stop() # Stops the timer
    # Collectiong timings
    $Ticks = $Watch.ElapsedTicks
    $NSecs = $Watch.ElapsedTicks * $NsecPerTick
    Write-Output "Program executed: time is: $Nsecs ns ($Ticks ticks)"
}

功能使用秒表.
那么,functoin接受一个程序路径,秒表启动,程序运行,然后秒表停止.问题:System.Diagnostics.process.Start是异步的,当应用程序完成时,不执行下一条指令(watch stopped).创建了一个新流程……

一旦程序结束,我需要停止计时器.

虑过Process类,加厚它有关于执行时间的一些信息……不幸运……

怎么解决这个?

解决方法

你可以使用Process.WaitForExit()

$proc = new-object "System.Diagnostics.process"
$proc.StarTinfo.Filename = "notepad.exe"
$proc.StarTinfo.UseSHellExecute = $false
$proc.Start()
$proc.WaitForExit()

大佬总结

以上是大佬教程为你收集整理的使用WIndows PowerShell 1.0或2.0来评估可执行文件的性能全部内容,希望文章能够帮你解决使用WIndows PowerShell 1.0或2.0来评估可执行文件的性能所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。