Esempio n. 1
0
 private static void SyncOperations(ComputeSync lComputeSync, ulong[] lNumbers, Stopwatch lStopwatch)
 {
     lStopwatch.Restart();
     foreach (ulong number in lNumbers)
     {
         Console.WriteLine(lComputeSync.GetFactorial(lComputeSync.GetFibonacci(number)));
     }
     Console.WriteLine($"Sync ops: {lStopwatch.ElapsedMilliseconds}");
 }
Esempio n. 2
0
        private static void ParallelOperations(ComputeSync lComputeSync, ulong[] lNumbers, Stopwatch lStopwatch)
        {
            CancellationTokenSource tokenSource = new CancellationTokenSource(200);

            lStopwatch.Restart();

            Parallel.ForEach(lNumbers, number => Console.WriteLine(lComputeSync.GetFactorial(lComputeSync.GetFibonacci(number))));
            Console.WriteLine($"Parallel ops: {lStopwatch.ElapsedMilliseconds}");
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            ComputeAsync lComputeAsync = new ComputeAsync();
            ComputeSync  lComputeSync  = new ComputeSync();

            ulong[]   lNumbers   = new ulong[10];
            int       lWaitTime  = 100000000;
            Stopwatch lStopwatch = new Stopwatch();

            for (int i = lNumbers.Length - 1; i >= 0; i--)
            {
                lNumbers[i] = (ulong)i + 1;
            }

            SyncOperations(lComputeSync, lNumbers, lStopwatch);
            AsyncOperations(lComputeAsync, lNumbers, lStopwatch, lWaitTime);
            AsyncOperationWhenAny(lComputeAsync, lNumbers, lStopwatch, lWaitTime);
            ParallelOperations(lComputeSync, lNumbers, lStopwatch);
        }