question

BrettOssman-3361 avatar image
0 Votes"
BrettOssman-3361 asked TianyuSun-MSFT edited

Timing Sections of .Net Code

Using Visual Studio 2019, VB .Net.

Looking for the best way to time sections of code to find a the exact code causing new delays running a command.
These are applications on client workstations running against a a SQL Server database.

I did some tracing and profiling MANY years ago, but wondering if there's a better way today. I want to have minimal to no impact on client performance, while running these checks, if possible, or get a feel for anticipated performance impact.

If there is a significant impact, the quicker I can disable the timing checks, the better.

dotnet-visual-basic
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DewayneBasnett-7583 avatar image
0 Votes"
DewayneBasnett-7583 answered BrettOssman-3361 commented

Use a StopWatch. A quick example.

         Dim stpw As New Stopwatch
    
         'code to time
         stpw.Restart()
         For x As Integer = 1 To 1000000
             Dim i As Integer = x
         Next
    
         'timing done
         stpw.Stop()
         Debug.WriteLine(stpw.Elapsed)


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hmm, that could work with minimal impact, especially compared with tracing or profiling.
I could also set up the config file to activate it or not.
I'll see what others come up with, but may well flag this as the answer.
Thanks

0 Votes 0 ·
karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered BrettOssman-3361 commented

Hello,

Working also with a StopWatch as @DewayneBasnett-7583 check out the following code sample on GitHub.

Provides

  • Access to a StopWatch using a singleton which means you can all functionality any place in your project

  • Option to write to comma delimited file

There is plenty of room for customization.







· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks.
Appreciated.

0 Votes 0 ·