Last active
December 27, 2015 09:09
-
-
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
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; | |
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); | |
} | |
} | |
} |
Yep, Joe Albahari explains it nicely
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From ILSpy,
Long()
loop body is:NullableLong()
loop body is: