private static int Fast(ConsoleCardPrinter consoleCardPrinter) { int numberOfHands = 0; bool isStillRunning = true; While(new ParallelOptions { MaxDegreeOfParallelism = 5 }, () => { return(isStillRunning); }, state => { var deck = new Deck(new GuidShuffler(), new ANormalDeck()); deck.Shuffle(); var hand = deck.TakeOneHand(); if (CheckIfHandHoldFourAces(hand)) { var cards = hand.Cards(); consoleCardPrinter.Print(cards); isStillRunning = false; } deck.Reset(); numberOfHands++; }); return(numberOfHands); }
private static int Slow(ConsoleCardPrinter consoleCardPrinter) { bool isStillRunning = true; int numberOfHands = 0; var deck = new Deck(new GuidShuffler(), new ANormalDeck()); do { deck.Shuffle(); var hand = deck.TakeOneHand(); if (CheckIfHandHoldFourAces(hand)) { var cards = hand.Cards(); consoleCardPrinter.Print(cards); isStillRunning = false; } deck.Reset(); numberOfHands++; } while (isStillRunning); return(numberOfHands); }
static void Main(string[] args) { var consoleCardPrinter = new ConsoleCardPrinter(); bool isStillRunning = true; int numberOfHands = 0; var stopwatch = new Stopwatch(); stopwatch.Start(); Console.WriteLine("SLOW..."); numberOfHands = Slow(consoleCardPrinter); stopwatch.Stop(); Console.WriteLine("DONE in {0} - {1}", stopwatch.Elapsed, numberOfHands); stopwatch.Reset(); stopwatch.Start(); Console.WriteLine("FAST..."); numberOfHands = Fast(consoleCardPrinter); stopwatch.Stop(); Console.WriteLine("DONE in {0} - {1}", stopwatch.Elapsed, numberOfHands); Console.ReadLine(); }
private static int Fast(ConsoleCardPrinter consoleCardPrinter) { int numberOfHands = 0; bool isStillRunning = true; While(new ParallelOptions {MaxDegreeOfParallelism = 5}, () => { return isStillRunning; }, state => { var deck = new Deck(new GuidShuffler(), new ANormalDeck()); deck.Shuffle(); var hand = deck.TakeOneHand(); if (CheckIfHandHoldFourAces(hand)) { var cards = hand.Cards(); consoleCardPrinter.Print(cards); isStillRunning = false; } deck.Reset(); numberOfHands++; }); return numberOfHands; }
private static int Slow(ConsoleCardPrinter consoleCardPrinter) { bool isStillRunning = true; int numberOfHands = 0; var deck = new Deck(new GuidShuffler(), new ANormalDeck()); do { deck.Shuffle(); var hand = deck.TakeOneHand(); if (CheckIfHandHoldFourAces(hand)) { var cards = hand.Cards(); consoleCardPrinter.Print(cards); isStillRunning = false; } deck.Reset(); numberOfHands++; } while (isStillRunning); return numberOfHands; }