Skip to content

Instantly share code, notes, and snippets.

@dstoza
Created June 29, 2017 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dstoza/817dc109c74af8c3dac54a055d0ec72f to your computer and use it in GitHub Desktop.
Save dstoza/817dc109c74af8c3dac54a055d0ec72f to your computer and use it in GitHub Desktop.
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