Skip to content

Instantly share code, notes, and snippets.

@sebastienros
Created November 17, 2015 00:43
Show Gist options
  • Save sebastienros/40981268e057eb9235f3 to your computer and use it in GitHub Desktop.
Save sebastienros/40981268e057eb9235f3 to your computer and use it in GitHub Desktop.
Ticks performance
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