Pipeline progress / time display

Adds about 82ms per million objects on my system:

function time_pipeline {
param ($increment  = 1000)
begin{$i=0;$timer = [diagnostics.stopwatch]::startnew()}
process {
    $i++
    if (!($i % $increment)){Write-host “`rProcessed $i in $($timer.elapsed.totalmilliseconds) ms” -nonewline}
    $_
    }
end {write-host “`rProcessed $i in $($timer.elapsed.totalmilliseconds) ms”}
}

example:

gci c:\ -recurse -ea silentlycontinue | time_pipeline -i 2000 | out-null

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s