Stopwatches

Drew Furgiuele explains how to use the .NET Stopwatch class in Powershell:

We can see I cleared the history buffer of my session ( Clear-History ), then ran a script. It’s nothing fancy; just connecting to my local instance of SQL Server and outputting a list of tables to a text file. With Get-History , I can see every command I put in the buffer, and using expressions I can calculate how long a command took.

And that’s great and all, but that’s the entire execution time. If there are multiple steps to your function, how long does each step take? If your script execution is 186 seconds, how much of time is spent on a database query? What about a loop? How long does each iteration take? Are you writing to a network share, and want to know what the latency is? Get-History  isn’t the tool of this, but thankfully we have other methods.

I use the stopwatch a lot for similar things; it’s a useful tool.

Related Posts

Scoping And Powershell Script Blocks

Shane O’Neill looks at variable scope within script blocks in Powershell: Now what happens if we don’t want to use switch? What happens if we tried to do this with script blocks instead? I’ve created 3 different script blocks here just for ease of use. If you want to create a single script block to […]

Read More

Concatenating Multiple SQL Files

Steve Stedman has a quick Powershell one-liner to concatenate multiple files: I come across the need occasionally to deploy a set of sql files that are all checked into source control in different files with a file hierarchy like this: Database Name Type of object (proc, table, view, etc) Name of object When I go […]

Read More

Categories

April 2017
MTWTFSS
« Mar May »
 12
3456789
10111213141516
17181920212223
24252627282930