Example #1
0
        static void TestFuzzyMatch()
        {
            Demo.PrintSeparator();
            Console.WriteLine("Fuzzy Match");
            Func <Action, Action[]> run = (func) => new Action[] { () => { func(); } };

            var fuzzyMatchImplementations =
                new[]
            {
                //new Tuple<String, Action[]>(
                //    "C# Sequential FuzzyMatch", run(ProcessFuzzyMacth.LinqFuzzyMatch)),
                //new Tuple<String, Action[]>(
                //    "C# Multiple Tasks FuzzyMatch", run(ProcessFuzzyMacth.MultipleTasksFuzzyMatch)),
                //new Tuple<String, Action[]>(
                //    "C# Parallel Loop FuzzyMatch", run(ProcessFuzzyMacth.ParallelLoopFuzzyMatch)),
                //new Tuple<String, Action[]>(
                //    "C# Parallel FuzzyMatch", run(ProcessFuzzyMacth.ParallelLinqFuzzyMatch)),
                new Tuple <String, Action[]>(
                    "C# Parallel PLINQ Partitioner FuzzyMatch", run(ProcessFuzzyMacth.ParallelLinqPartitionerFuzzyMatch))
            };

            Application.Run(
                PerfVis.toChart("C# FuzzyMatch")
                .Invoke(PerfVis.fromTuples(fuzzyMatchImplementations)));
        }
Example #2
0
        static void TestPrimeNumbersSum()
        {
            Demo.PrintSeparator();
            Console.WriteLine("Prime Sum [0..10^7]");
            Func <Func <long>, Action[]> runSum = (func) =>
                                                  new Action[]
            {
                () =>
                {
                    var result = func();
                    Console.WriteLine($"Sum = {result}");
                }
            };

            var sumImplementations =
                new[]
            {
                new Tuple <String, Action[]>(
                    "C# Sequential", runSum(PrimeNumbers.PrimeSumSequential)),
                new Tuple <String, Action[]>(
                    "C# Parallel.For", runSum(PrimeNumbers.PrimeSumParallel)),
                new Tuple <String, Action[]>(
                    "C# Parallel.For ThreadLocal", runSum(PrimeNumbers.PrimeSumParallelThreadLocal)),
                new Tuple <String, Action[]>(
                    "C# Parallel LINQ", runSum(PrimeNumbers.PrimeSumParallelLINQ))
            };

            Application.Run(
                PerfVis.toChart("C# Prime Sum")
                .Invoke(PerfVis.fromTuples(sumImplementations)));
        }
Example #3
0
        static void Main(string[] args)
        {
            Random rand     = new Random((int)DateTime.Now.Ticks);
            int    attempts = 5;

            int[][] dataSamples =
                Enumerable.Range(0, attempts)
                .Select(x =>
            {
                var A = new int[1000000];
                for (int i = 0; i < 1000000; ++i)
                {
                    A[i] = rand.Next();
                }
                return(A);
            }).ToArray();

            Func <Action <int[]>, Action[]> run = (sortFunc) =>
                                                  dataSamples.Select(data => (Action)(() => sortFunc(data))).ToArray();

            var implementations =
                new[]
            {
                new Tuple <String, Action[]>(
                    "Sequential", run(QuickSort.QuickSort_Sequential)),
                new Tuple <String, Action[]>(
                    "Parallel", run(QuickSort.QuickSort_Parallel)),
                new Tuple <String, Action[]>(
                    "ParallelWithDepth", run(QuickSort.QuickSort_Parallel_Threshold)),
            };

            Application.Run(
                PerfVis.toChart("C# QuickSort")
                .Invoke(PerfVis.fromTuples(implementations)));
        }
Example #4
0
        public static void RunPerfComparison(int[] fileSizesInGb, int[] degreesOfParallelism)
        {
            const long bytesInGb    = 1024L * 1024 * 1024;
            string     templateFile = sourceFile_132;

            if (!Directory.Exists(workDirectory))
            {
                Directory.CreateDirectory(workDirectory);
            }

            string inFile  = Path.Combine(workDirectory, "inFile.txt");
            string outFile = Path.Combine(workDirectory, "outFile.txt");

            var results = new List <List <TimeSpan> >();

            foreach (var size in fileSizesInGb)
            {
                Console.WriteLine($"Creating input file {size}GB ...");
                if (System.IO.File.Exists(inFile))
                {
                    System.IO.File.Delete(inFile);
                }
                CreateTextFileWithSize(inFile, templateFile, bytesInGb * size);

                for (var i = 0; i < degreesOfParallelism.Length; i++)
                {
                    var dop = degreesOfParallelism[i];
                    if (System.IO.File.Exists(outFile))
                    {
                        System.IO.File.Delete(outFile);
                    }

                    Console.WriteLine($"Running compression with degreeOfParallelism={dop} ...");
                    var sw = System.Diagnostics.Stopwatch.StartNew();
                    RunCompression(inFile, outFile, dop);
                    sw.Stop();
                    Console.WriteLine($"\t Elapsed = {sw.Elapsed}");

                    if (i == results.Count)
                    {
                        results.Add(new List <TimeSpan>());
                    }
                    results[i].Add(sw.Elapsed);
                }
            }

            var keys   = fileSizesInGb.Select(s => $"{s}Gb").ToList();
            var charts = new List <ChartTypes.GenericChart>();

            for (var i = 0; i < results.Count; i++)
            {
                var line      = results[i].Select(t => t.TotalMilliseconds).ToList();
                var lineChart = PerfVis.CreateLineChart(line, keys, $"dop={degreesOfParallelism[i]}");
                charts.Add(lineChart);
            }
            Application.Run(PerfVis.CombineToForm(charts, "Dataflow compression with different degree of parallelism(dop)"));
        }
Example #5
0
        static void Main(string[] args)
        {
            bool IsPrime(int n)
            {
                if (n == 1)
                {
                    return(false);
                }
                if (n == 2)
                {
                    return(true);
                }
                var boundary = (int)Math.Floor(Math.Sqrt(n));

                for (int i = 2; i <= boundary; ++i)
                {
                    if (n % i == 0)
                    {
                        return(false);
                    }
                }
                return(true);
            }

            BigInteger ToPow(int n) => (BigInteger)Math.BigMul(n, n);

            var numbers = Enumerable.Range(0, 100000000).ToList();

            BigInteger SeqOperation() => numbers.Where(IsPrime).Select(ToPow).Aggregate(BigInteger.Add);
            BigInteger ParallelLinqOperation() => numbers.AsParallel().Where(IsPrime).Select(ToPow).Aggregate(BigInteger.Add);
            BigInteger ParallelFilterMapInline() => numbers.FilterMap(IsPrime, ToPow).Aggregate(BigInteger.Add);

            Demo.PrintSeparator();
            Console.WriteLine("Square Prime Sum [0..10000000]");
            Func <Func <BigInteger>, Action[]> runSum = (func) =>
                                                        new Action[]
            {
                () =>
                {
                    var result = func();
                    Console.WriteLine($"Sum = {result}");
                }
            };
            var sumImplementations =
                new[]
            {
                new Tuple <String, Action[]>(
                    "C# Sequential", runSum(SeqOperation)),
                new Tuple <String, Action[]>(
                    "C# Parallel LINQ", runSum(ParallelLinqOperation)),
                new Tuple <String, Action[]>(
                    "C# Parallel FilterMap inline", runSum(ParallelFilterMapInline))
            };

            Application.Run(
                PerfVis.toChart("C# Square Prime Sum").Invoke(PerfVis.fromTuples(sumImplementations)));
        }
Example #6
0
        public static void Run()
        {
            var dataPath = @"Shakespeare";

            Func <Func <string, Dictionary <string, int> >, Action[]> run = (func) =>
                                                                            new Action[] { () => { func(dataPath); } };

            var implementations =
                new[]
            {
                new Tuple <String, Action[]>(
                    "WordCounter", run(WordsCounter)),
                new Tuple <String, Action[]>(
                    "Pure WordCounter", run(WordsUnpureCounter))
            };

            Application.Run(
                PerfVis.toChart("WordCount")
                .Invoke(PerfVis.fromTuples(implementations)));
        }
Example #7
0
        static void TestMandelbrot()
        {
            Console.WriteLine("Mandelbrot Performance Comparison");
            Func <Func <Bitmap>, Action[]> run = (func) =>
                                                 new Action[] { () => { func(); } };

            var implementations =
                new[]
            {
                new Tuple <String, Action[]>(
                    "C# Sequential", run(Mandelbrot.SequentialMandelbrot)),
                new Tuple <String, Action[]>(
                    "C# Parallel.For", run(Mandelbrot.ParallelMandelbrot)),
                new Tuple <String, Action[]>(
                    "C# Parallel.For Saturated", run(Mandelbrot.ParallelMandelbrotOversaturation)),
                new Tuple <String, Action[]>(
                    "C# Parallel.For Struct", run(Mandelbrot.ParallelStructMandelbrot))
            };

            Application.Run(
                PerfVis.toChart("C# Mandelbrot")
                .Invoke(PerfVis.fromTuples(implementations)));
        }
Example #8
0
        static void Main(string[] args)
        {
            //var fm = new ProcessFuzzyMacth();
            //fm.MultipleTasksFuzzyMatch();
            //fm.ParallelArrayFuzzyMatch();
            //Console.ReadLine();


            //Console.WriteLine("Mandelbrot Performance Comparison");
            //Func<Func<Bitmap>, Action[]> run = (func) =>
            //        new Action[] { () => { func(); } };

            //var implementations =
            //    new[]
            //    {
            //        new Tuple<String, Action[]>(
            //            "C# Sequential", run(Mandelbrot.SequentialMandelbrot)),
            //        new Tuple<String, Action[]>(
            //            "C# Parallel.For", run(Mandelbrot.ParallelMandelbrot)),
            //        new Tuple<String, Action[]>(
            //            "C# Parallel.For Saturated", run(Mandelbrot.ParallelMandelbrotOversaturation)),
            //        new Tuple<String, Action[]>(
            //            "C# Parallel.For Struct", run(Mandelbrot.ParallelStructMandelbrot))
            //    };

            //Application.Run(
            //    PerfVis.toChart("C# Mandelbrot")
            //        .Invoke(PerfVis.fromTuples(implementations)));

            //// --------------------------------------------
            //Demo.PrintSeparator();
            //Console.WriteLine("Draw Mandelbrot");
            //var pictureBox = new PictureBox
            //{
            //    Dock = DockStyle.Fill,
            //    Image = Mandelbrot.ParallelStructMandelbrot(),
            //    SizeMode = PictureBoxSizeMode.StretchImage
            //};
            //var form = new Form();
            //form.Controls.Add(pictureBox);
            //Application.Run(form);


            // --------------------------------------------
            Demo.PrintSeparator();
            Console.WriteLine("Prime Sum [0..10^7]");
            Func <Func <long>, Action[]> runSum = (func) =>
                                                  new Action[]
            {
                () =>
                {
                    var result = func();
                    Console.WriteLine($"Sum = {result}");
                }
            };
            var sumImplementations =
                new[]
            {
                new Tuple <String, Action[]>(
                    "C# Sequential", runSum(PrimeNumbers.PrimeSumSequential)),
                new Tuple <String, Action[]>(
                    "C# Parallel.For", runSum(PrimeNumbers.PrimeSumParallel)),
                new Tuple <String, Action[]>(
                    "C# Parallel.For ThreadLocal", runSum(PrimeNumbers.PrimeSumParallelThreadLocal)),
                new Tuple <String, Action[]>(
                    "C# Parallel LINQ", runSum(PrimeNumbers.PrimeSumParallelLINQ))
            };

            Application.Run(
                PerfVis.toChart("C# Prime Sum")
                .Invoke(PerfVis.fromTuples(sumImplementations)));
        }