Created
November 17, 2015 00:43
-
-
Save sebastienros/40981268e057eb9235f3 to your computer and use it in GitHub Desktop.
Ticks performance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
var iterations = 1000000; | |
var sw = new System.Diagnostics.Stopwatch(); | |
sw.Restart(); | |
for(int i=0; i< iterations; ) | |
{ | |
var x = Environment.TickCount; | |
if(x != 0) | |
{ | |
i++; | |
} | |
} | |
Console.WriteLine(sw.ElapsedMilliseconds); | |
sw.Restart(); | |
for(int i=0; i< iterations; ) | |
{ | |
var x = DateTime.UtcNow.Ticks; | |
if(x != 0) | |
{ | |
i++; | |
} | |
} | |
Console.WriteLine(sw.ElapsedMilliseconds); | |
sw.Restart(); | |
for(int i=0; i< iterations; ) | |
{ | |
var x = DateTime.Now.Ticks; | |
if(x != 0) | |
{ | |
i++; | |
} | |
} | |
Console.WriteLine(sw.ElapsedMilliseconds); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment