DEV Community

Cover image for Measuring program execution time in PowerShell
Bruno Baère
Bruno Baère

Posted on • Updated on

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 scene1.

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 it was 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.


  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.


1. Yes, I could have used a timer in Go inside the ray tracer itself, but having a timer like `time` is still useful.

Top comments (1)

johnsantana profile image

implementing such type of information in real life is amazing . thanks for sharing such valuable post with us . Mantra To Control Husband