Measuring program execution time in PowerShell

As I was nearing completion of implementing Ray Tracing in One Weekend in Go, I felt the need to measure the time it would take to render a scene.

My day-to-day work is in CentOS, so I was tempted to try time gortiw in Windows Terminal, as it already …


This content originally appeared on DEV Community and was authored by DEV Community

As I was nearing completion of implementing Ray Tracing in One Weekend in Go, I felt the need to measure the time it would take to render a scene.

My day-to-day work is in CentOS, so I was tempted to try time gortiw in Windows Terminal, as it already had some improvements over cmd, like ssh and an alias for ls. I was disappointed. There was no easily accessible time-like command nor an alias.

After searching a little, I got to a solution: using PowerShell's Measure-Command. Then I just needed to create a function time in my PowerShell profile and it was done.

Steps

  1. Edit your Documents\PowerShell\Microsoft.PowerShell_profile.ps1
  2. Add the line

    function time { $Command = "$args"; Measure-Command { Invoke-Expression $Command 2>&1 | out-default} }
    
  3. Open a new instance or tab of PowerShell to use the new time function. Ex: time gortiw.exe

Satisfied with the results, the next step will be using a profiler to check where to improve.


This content originally appeared on DEV Community and was authored by DEV Community


Print Share Comment Cite Upload Translate Updates
APA

DEV Community | Sciencx (2022-03-05T00:32:33+00:00) Measuring program execution time in PowerShell. Retrieved from https://www.scien.cx/2022/03/05/measuring-program-execution-time-in-powershell/

MLA
" » Measuring program execution time in PowerShell." DEV Community | Sciencx - Saturday March 5, 2022, https://www.scien.cx/2022/03/05/measuring-program-execution-time-in-powershell/
HARVARD
DEV Community | Sciencx Saturday March 5, 2022 » Measuring program execution time in PowerShell., viewed ,<https://www.scien.cx/2022/03/05/measuring-program-execution-time-in-powershell/>
VANCOUVER
DEV Community | Sciencx - » Measuring program execution time in PowerShell. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/03/05/measuring-program-execution-time-in-powershell/
CHICAGO
" » Measuring program execution time in PowerShell." DEV Community | Sciencx - Accessed . https://www.scien.cx/2022/03/05/measuring-program-execution-time-in-powershell/
IEEE
" » Measuring program execution time in PowerShell." DEV Community | Sciencx [Online]. Available: https://www.scien.cx/2022/03/05/measuring-program-execution-time-in-powershell/. [Accessed: ]
rf:citation
» Measuring program execution time in PowerShell | DEV Community | Sciencx | https://www.scien.cx/2022/03/05/measuring-program-execution-time-in-powershell/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.