Created
June 29, 2017 16:04
-
-
Save dstoza/817dc109c74af8c3dac54a055d0ec72f to your computer and use it in GitHub Desktop.
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.Linq; | |
using System.Text; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace ConsoleApp1 | |
{ | |
class SlowMethod | |
{ | |
public Int64 Run() | |
{ | |
Thread.Sleep(100); | |
return 1000000; | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Int64 sum = 0; | |
Random rnd = new Random(); | |
for (int i = 0; i < 50000; ++i) | |
{ | |
SlowMethod m = (rnd.Next(0, 1000) == 0) ? new SlowMethod() : null; | |
/* | |
if (m == null) | |
{ | |
sum += 1; | |
} else | |
{ | |
sum += m.Run(); | |
} | |
*/ | |
// sum += (m == null) ? 1 : m.Run(); | |
sum += m?.Run() ?? 1; | |
} | |
Console.WriteLine(sum); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment