使用WIndows PowerShell 1.0或2.0来评估可执行文件的性能
发布时间:2020-12-14 02:02:49 所属栏目:Windows 来源:网络整理
导读:我正在 Windows PowerShell上编写一个简单的脚本,以评估可执行文件的性能. 重要的假设如下:我有一个可执行文件,它可以是用任何可能的语言编写的应用程序(.net而不是,Viual-Prolog,C,可以编译为.exe文件的所有内容).我想描述一下执行时间. 我这样做了: Func
我正在
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)" } 此功能使用秒表. 一旦程序结束,我需要停止计时器. 我考虑过Process类,加厚它有关于执行时间的一些信息……不幸运…… 怎么解决这个? 解决方法
你可以使用Process.WaitForExit()
$proc = new-object "System.Diagnostics.Process" $proc.StartInfo.FileName = "notepad.exe" $proc.StartInfo.UseShellExecute = $false $proc.Start() $proc.WaitForExit() (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 如何在Windows上使用Python的协议缓冲区?
- 在Windows 2.7.2中使用subprocess.call()的问题
- [转帖]windows+xshell+xming访问非桌面版Linux服务器
- windows – 以编程方式更新桌面“拖动时显示窗口内容”设置
- ffmpeg下载m3u8流媒体
- Windows Phone 7 – 当WP7中显示软键盘时,防止屏幕向上滚动
- 单元测试 – 使用Microsoft Fakes和静态通用方法填充
- twilio – 可编程聊天 – Xamarin表示面向Windows(UWP)和Ma
- windows-server-2008 – Windows Server 2008群集错误
- windows – SetupDiGetClassDevs是否与文档中的设备实例ID一