Exemplo n.º 1
0
        private static void OrderByTest(Func <int, int> keySelector, int count, int run)
        {
            int[]     source    = EnumerableX.RandomInt32(count: count).ToArray();
            Stopwatch stopwatch = Stopwatch.StartNew();

            Enumerable.Range(0, run).ForEach(_ =>
            {
                int[] sequential = source.OrderBy(keySelector).ToArray();
            });
            stopwatch.Stop();
            $"Sequential:{stopwatch.ElapsedMilliseconds}".WriteLine();

            stopwatch.Restart();
            Enumerable.Range(0, run).ForEach(_ =>
            {
                int[] parallel1 = source.AsParallel().OrderBy(keySelector).ToArray();
            });
            stopwatch.Stop();
            $"Parallel:{stopwatch.ElapsedMilliseconds}".WriteLine();
        }
        internal static void OrderByTest(Func <int, int> keySelector, int sourceCount, int testRepeatCount)
        {
            int[] source = EnumerableX
                           .RandomInt32(min: int.MinValue, max: int.MaxValue, count: sourceCount)
                           .ToArray();
            Stopwatch stopwatch = Stopwatch.StartNew();

            Enumerable.Range(0, testRepeatCount).ForEach(_ =>
            {
                int[] sequentialResults = source.OrderBy(keySelector).ToArray();
            });
            stopwatch.Stop();
            $"Sequential:{stopwatch.ElapsedMilliseconds}".WriteLine();

            stopwatch.Restart();
            Enumerable.Range(0, testRepeatCount).ForEach(_ =>
            {
                int[] parallel1Results = source.AsParallel().OrderBy(keySelector).ToArray();
            });
            stopwatch.Stop();
            $"Parallel:{stopwatch.ElapsedMilliseconds}".WriteLine();
        }
Exemplo n.º 3
0
 public static int[] RandomArray(int minValue, int maxValue, int minLength, int maxLength) =>
 EnumerableX
 .RandomInt32(minValue, maxValue).Take(new Random().Next(minLength, maxLength))
 .ToArray();