示例#1
0
        public static int[] RandomArray(int minValue, int maxValue, int minLength, int maxLength)
        {
            Random random = new Random();

            return(EnumerableX
                   .RandomInt32(minValue, maxValue, random).Take(random.Next(minLength, maxLength))
                   .ToArray());
        }
        public void RetryTest()
        {
            int count = 0;

            int[] retry = EnumerableX.Create(() =>
            {
                count++;
                if (count < 5)
                {
                    throw new OperationCanceledException();
                }
                return(count);
            })
                          .Take(2)
                          .Retry <int, OperationCanceledException>(5)
                          .ToArray();
            EnumerableAssert.AreSequentialEqual(new int[] { 5, 6 }, retry);
        }
示例#3
0
        private static void OrderBy(int count, int run, Func <int, int> keySelector)
        {
            int[]     source    = EnumerableX.RandomInt32().Take(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();
        }