Using a Stop Watch

In PowerShell, to measure time, you can simply subtract datetime values from another:

$Start = Get-Date

$null = Read-Host -Prompt "Press ENTER as fast as you can!"

$Stop = Get-Date
$TimeSpan = $Stop - $Start
$TimeSpan.TotalMilliseconds

An elegant alternative is a stop watch:

$StopWatch = [Diagnostics.Stopwatch]::StartNew()

$null = Read-Host -Prompt "Press ENTER as fast as you can!"

$StopWatch.Stop()
$StopWatch.ElapsedMilliseconds

The specific stop watch advantage is its ability to be paused and continued.

Twitter This Tip! ReTweet this Tip!

GD Star Rating
loading...