20 lines
589 B
Plaintext
20 lines
589 B
Plaintext
![]() |
==== Noncompliant code example
|
||
|
|
||
|
[source,vbnet,diff-id=1,diff-type=noncompliant]
|
||
|
----
|
||
|
Dim start = DateTime.Now ' First call, on March 26th 2:59 am
|
||
|
' Method to be benchmarked
|
||
|
|
||
|
Console.WriteLine($"{CInt((DateTime.Now - start).TotalMilliseconds)} ms") ' Second call happens 2 minutes later but `Now` is March 26th, 4:01 am as there's a shift to summer time
|
||
|
----
|
||
|
|
||
|
==== Compliant solution
|
||
|
|
||
|
[source,vbnet,diff-id=1,diff-type=compliant]
|
||
|
----
|
||
|
Dim stopWatch = Stopwatch.StartNew() ' Compliant
|
||
|
' Method to be benchmarked
|
||
|
stopWatch.Stop()
|
||
|
|
||
|
Console.WriteLine($"{stopWatch.ElapsedMilliseconds} ms")
|
||
|
----
|