Skip to content

Instantly share code, notes, and snippets.

@pawelpabich
Last active December 27, 2015 09:09
Show Gist options
  • Save pawelpabich/7301628 to your computer and use it in GitHub Desktop.
Save pawelpabich/7301628 to your computer and use it in GitHub Desktop.
Long - 0.4s NullableLong - 4s Why? Have a look at Joe Albahari's presentation, around 1:02h mark. http://www.youtube.com/watch?v=aZCzG2I8Hds
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Long();
NullableLong();
Console.ReadLine();
}
private static void Long()
{
var stopwatch = Stopwatch.StartNew();
long result = 0;
for (long i = 0; i < 100000000; i++)
{
result = result + i;
}
stopwatch.Stop();
Console.WriteLine(stopwatch.Elapsed);
}
private static void NullableLong()
{
var stopwatch = Stopwatch.StartNew();
long? result = 0;
for (long? i = 0; i < 100000000; i++)
{
result = result + i;
}
stopwatch.Stop();
Console.WriteLine(stopwatch.Elapsed);
}
}
}
@pawelpabich
Copy link
Author

Yep, Joe Albahari explains it nicely

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment