Esempio n. 1
0
        private static void Compare(BenchmarkParameters parameters)
        {
            Console.WriteLine("=== Start and Compare ===");

            var actions = new Action[]
            {
                ActionToTest1
            };

            var comparisons = Benchmarker.StartAndCompare(ActionToTest, parameters, actions);

            Console.WriteLine("Method comparisons executed against ActionToTest method:\n");
            Console.WriteLine("Method\tTotal ms\tTotal ticks\tAvg. ms\tAvg. ticks\tGC0\tGC1\tGC2\t");
            for (int i = 0; i < comparisons.Length; i++)
            {
                var comparison = comparisons[i];

                var line = actions[i].Method.Name + "\t";
                line += comparison.ElapsedMillisecondsDifferencePercentage + "% (" + comparison.ElapsedMillisecondsDifference + " ms)\t";
                line += comparison.ElapsedTicksDifferencePercentage + "% (" + comparison.ElapsedTicksDifference + " ticks)\t";
                line += comparison.AverageMillisecondsDifferencePercentage + "% (" + comparison.AverageMillisecondsDifference + " ms)\t";
                line += comparison.AverageTicksDifferencePercentage + "% (" + comparison.AverageTicksDifference + " ticks)\t";
                line += comparison.GCCollections0DifferencePercentage + "% (" + comparison.GCCollections0Difference + ")\t";
                line += comparison.GCCollections1DifferencePercentage + "% (" + comparison.GCCollections1Difference + ")\t";
                line += comparison.GCCollections2DifferencePercentage + "% (" + comparison.GCCollections2Difference + ")\t";

                Console.WriteLine(line);
            }
        }
Esempio n. 2
0
        public static void DemoKeyLengthPerformance()
        {
            Dictionary <string, int> _dict = new Dictionary <string, int> {
                { DataGenerator.GetRandomString(), DataGenerator.GetRandomInt(1, 9) },
                { DataGenerator.GetRandomString(), DataGenerator.GetRandomInt(1, 9) },
                { DataGenerator.GetRandomString(), DataGenerator.GetRandomInt(1, 9) },
            };

            string key0 = "00000000000000000001";

            //TODO 1.13: try this with shorter keys

            Benchmarker.Benchmark(() =>
            {
                _dict.ContainsKey(key0);
            }, "ContainsKey(20 chars)", _count);

            Benchmarker.Benchmark(() =>
            {
                _dict.ContainsKey(key0);
            }, "ContainsKey(10 chars)", _count);

            Benchmarker.Benchmark(() =>
            {
                _dict.ContainsKey(key0);
            }, "ContainsKey(5 chars)", _count);

            Benchmarker.Benchmark(() =>
            {
                _dict.ContainsKey(key0);
            }, "ContainsKey(1 char)", _count);

            Console.WriteLine();
        }
        public static void DetermineStringBuilderReusagePerformance()
        {
            string[] stringArray = DataGenerator.GetRandomStringArray(10);

            Benchmarker.Benchmark(() =>
            {
                StringBuilder builder = new StringBuilder();
                foreach (string str in stringArray)
                {
                    builder.Append(str);
                }
                var string1 = builder.ToString();
            }, "Without StringBuilder reusage", _count);

            Benchmarker.Benchmark(() =>
            {
                //TODO 1.4: Use static builder instead of new()
                StringBuilder builder = new StringBuilder();
                builder.Clear();
                foreach (string value in stringArray)
                {
                    builder.Append(value);
                }
                var string2 = builder.ToString();
            }, "With StringBuilder reusage", _count);

            Console.WriteLine();
        }
Esempio n. 4
0
        public void benchmark()
        {
            const int HeapSize = 5000;

            int[]           randomValues = Enumerable.Range(0, 100000).Select(_ => _random.Next()).ToArray();
            BenchmarkResult r1           = Benchmarker.BenchmarkTime(() =>
            {
                BestKeeper <int> sut = new BestKeeper <int>(HeapSize, (n1, n2) => n1 - n2);
                for (int i = 0; i < randomValues.Length; i++)
                {
                    sut.Add(randomValues[i]);
                }
            }, 100);

            BenchmarkResult r2 = Benchmarker.BenchmarkTime(() =>
            {
                OrderedArrayBestKeeper <int> sut = new OrderedArrayBestKeeper <int>(HeapSize, (n1, n2) => n1 - n2);
                for (int i = 0; i < randomValues.Length; i++)
                {
                    sut.Add(randomValues[i]);
                }
            }, 100);

            Assert.That(r1.IsSignificantlyBetterThan(r2), Is.True);
        }
        public static void DemoMultipleReturnValues()
        {
            Benchmarker.Benchmark(() =>
            {
                DataGenerator.GetMultipleStrings(out var string1, out var string2);
            }, "Multiple out parameters", _count);

            Benchmarker.Benchmark(() =>
            {
                DataGenerator.GetMultipleStringsAsKeyValuePair();
            }, "KeyValuePair", _count);

            Benchmarker.Benchmark(() =>
            {
                DataGenerator.GetMultipleStringsAsValueTuple();
            }, "ValueTuple", _count);

            Console.WriteLine();
            /*
             * Summary: out parameters are a lot slower than KeyValuePairs. 
             * KeyValuePairs and tuple performance is almost equal
             * However, tuples are a better practice:
             *   - it allows more than 2 return parameters
             *   - it allows naming each return parameter
             *  Naming:
             *   2-tuple is called a pair.
             *   3-tuple is called a triple.
             *   4-tuple is called a quadruple.
             *   ...
             *   Tuples > 7 are called n-tuples.
             */
        }
        public static void DemoStaticFieldVsLocalVariable()
        {
            Benchmarker.Benchmark(() =>
            {
                _staticInt++;
            }, "Static field ++", _count);

            _staticInt = 0;

            Benchmarker.Benchmark(() =>
            {
                int localInt = _staticInt;
                for (int c = 0; c < _count; c++)
                {
                    localInt++;
                }
                _staticInt = localInt;
            }, "Local variable ++", 1, _count);

            _staticInt = 0;

            Console.WriteLine();

            /* 
             * Summary:
             * Stack vs. heap => local value type variables are stored on the stack
             * Fields (stored on heap) are slower to access.
             */
        }
Esempio n. 7
0
        public static void DemoLoopIncrementVsDecrement()
        {
            int result = 0;

            Benchmarker.Benchmark(() =>
            {
                for (int i = 0; i < _count; i++)
                {
                    result = i;
                }
            }, "Increment", 1, _count);

            result = 0;

            Benchmarker.Benchmark(() =>
            {
                for (int i = _count - 1; i >= 0; i--)
                {
                    result = i;
                }
            }, "Decrement", 1, _count);

            Console.WriteLine();

            /*
             * Summary:
             * Testing against zero (decrementing) could be a lot faster on your system
             * (possible explanation: processor instruction optimizations).
             */
        }
Esempio n. 8
0
        static int Main(string[] args)
        {
            if (args.Length > 0 && args[0].ToLowerInvariant().Contains("detailed"))
            {
                BenchmarkRunner.Run <Basics>();
                BenchmarkRunner.Run <Strings>();
                BenchmarkRunner.Run <List>();
                BenchmarkRunner.Run <Dictionary>();
            }
            else
            {
                Console.WriteLine("Quick benchmarks. Pass --detailed for Benchmark.net numbers.");
                Benchmarker runner = new Benchmarker();

                runner.Run <Basics>();
                runner.Run <Strings>();
                runner.Run <List>();
                runner.Run <Dictionary>();

                runner.WriteSummary();
                return(runner.HasFailures ? -1 : 0);
            }

            return(0);
        }
Esempio n. 9
0
 protected Sample()
 {
     Benchmarker = new Benchmarker()
     {
         CopyResultsToClipboard = true
     };
 }
        public static void DemoCustomContains()
        {
            List <int> list      = DataGenerator.GetRandomIntArray(10, 10, 10000).ToList();
            bool       itemFound = false;

            Benchmarker.Benchmark(() =>
            {
                itemFound = list.Contains(5);
            }, "Using extension method Contains()", _count);

            Benchmarker.Benchmark(() =>
            {
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i] == 5)
                    {
                        //found item, stop searching
                        itemFound = true;
                        break;
                    }
                }
                itemFound = false;
            }, "Using custom Contains method", _count);

            Console.WriteLine();
        }
        public static void DemoRemoveListVsRemoveDictionary()
        {
            List <int>            list           = DataGenerator.GetRandomIntArray(_count).ToList();
            var                   listCopy       = list.ToList();
            Dictionary <int, int> dictionary     = DataGenerator.GetRandomIntDictionary(_count, 1, 1000000000);
            var                   dictionaryCopy = dictionary.ToDictionary(x => x.Key, x => x.Value);

            Benchmarker.Benchmark(() =>
            {
                foreach (var item in listCopy)
                {
                    list.Remove(item);
                }
            }, "List removal", 1, _count);

            Benchmarker.Benchmark(() =>
            {
                foreach (var item in dictionaryCopy)
                {
                    dictionary.Remove(item.Key);
                }
            }, "Dictionary removal", 1, _count);

            /*
             * A List is a contiguous collection of elements.
             * When you remove an element from it, all following elements must be copied forward.
             * This requires allocations and computations.
             * For large Lists, this can be slow
             */

            Console.WriteLine();
        }
Esempio n. 12
0
        static async Task Main(string[] args)
        {
            //GrpcEnvironment.SetLogger(new Grpc.Core.Logging.ConsoleLogger());

            var host = "0.0.0.0";
            var port = int.Parse(Environment.GetEnvironmentVariable("DFRAME_MASTER_CONNECT_TO_PORT") ?? "12345");
            var workerConnectToHost = Environment.GetEnvironmentVariable("DFRAME_MASTER_CONNECT_TO_HOST") ?? $"dframe-master.local";

            Console.WriteLine($"port {port}, workerConnectToHost {workerConnectToHost}");

            var reportId = Environment.GetEnvironmentVariable("BENCH_REPORTID") ?? throw new ArgumentNullException($"Environment variables BENCH_REPORTID is missing.");
            var path     = Environment.GetEnvironmentVariable("BENCH_S3BUCKET") ?? throw new ArgumentNullException($"Environment variables BENCH_S3BUCKET is missing.");

            if (Environment.GetEnvironmentVariable("IS_LOCAL")?.ToLower() == "true")
            {
                reportId = DateTime.Now.ToString("yyyyMMdd-HHmmss");
                System.IO.File.WriteAllText("current_report_id", reportId);
            }
            Console.WriteLine($"bucket {path}, reportId {reportId}");

            if (args.Length == 0)
            {
                // master
                args = "request -processCount 1 -workerPerProcess 1 -executePerWorker 1 -workerName UnaryWorker".Split(' ');
                //args = "request -processCount 1 -workerPerProcess 1 -executePerWorker 1 -workerName GrpcWorker".Split(' ');
                //args = "request -processCount 1 -workerPerProcess 1 -executePerWorker 1 -workerName ApiWorker".Split(' ');

                // expand thread pool
                //ModifyThreadPool(Environment.ProcessorCount * 5, Environment.ProcessorCount * 5);
            }
            else if (args.Contains("--worker-flag"))
            {
                // worker
                // connect to
                host = workerConnectToHost;
            }

            Console.WriteLine($"args {string.Join(", ", args)}, host {host}");
            await Host.CreateDefaultBuilder(args)
            .ConfigureLogging(logging =>
            {
                logging.ClearProviders();
                logging.SetMinimumLevel(LogLevel.Trace);
                logging.AddZLoggerConsole(options =>
                {
                    options.EnableStructuredLogging = false;
                });
            })
            .RunDFrameAsync(args, new DFrameOptions(host, port, workerConnectToHost, port, new EcsScalingProvider())
            {
                Timeout         = TimeSpan.FromMinutes(120),
                OnExecuteResult = (results, option, scenario) =>
                {
                    using var cts = new CancellationTokenSource(TimeSpan.FromMinutes(10));
                    Console.WriteLine("Generating html.");
                    var benchmarker = new Benchmarker(path, null, cts.Token);
                    benchmarker.GenerateHtmlAsync(reportId).GetAwaiter().GetResult();
                },
            });
Esempio n. 13
0
        static void Main(string[] args)
        {
            //string connStr = ConfigurationManager.ConnectionStrings["OrmBenchmark.ConsoleUI.Properties.Settings.OrmBenchmarkConnectionString"].ConnectionString;
            string connStr = Settings.Default.OrmBenchmarkConnectionString; //ConfigurationManager.ConnectionStrings["sqlServerLocal"].ConnectionString;

            TestConnection(connStr);

            bool warmUp = false;

            var benchmarker = new Benchmarker(connStr, 500);

            benchmarker.RegisterOrmExecuter(new Ado.PureAdoExecuter());
            //benchmarker.RegisterOrmExecuter(new Ado.PureAdoExecuterGetValues());
            //benchmarker.RegisterOrmExecuter(new SimpleData.SimpleDataExecuter());
            benchmarker.RegisterOrmExecuter(new Dapper.DapperExecuter());

            /* benchmarker.RegisterOrmExecuter(new Dapper.DapperBufferedExecuter());
             * benchmarker.RegisterOrmExecuter(new Dapper.DapperFirstOrDefaultExecuter());
             * benchmarker.RegisterOrmExecuter(new Dapper.DapperContribExecuter());
             * benchmarker.RegisterOrmExecuter(new PetaPoco.PetaPocoExecuter());
             * benchmarker.RegisterOrmExecuter(new PetaPoco.PetaPocoFastExecuter());
             * benchmarker.RegisterOrmExecuter(new PetaPoco.PetaPocoFetchExecuter());
             * benchmarker.RegisterOrmExecuter(new PetaPoco.PetaPocoFetchFastExecuter());
             * benchmarker.RegisterOrmExecuter(new OrmToolkit.OrmToolkitExecuter());
             * benchmarker.RegisterOrmExecuter(new OrmToolkit.OrmToolkitNoQueryExecuter());
             * benchmarker.RegisterOrmExecuter(new OrmToolkit.OrmToolkitAutoMapperExecuter());
             * benchmarker.RegisterOrmExecuter(new OrmToolkit.OrmToolkitTestExecuter());
             */
            benchmarker.RegisterOrmExecuter(new EntityFramework.EntityFrameworkExecuter());
            benchmarker.RegisterOrmExecuter(new EntityFrameworkCore.EntityFrameworkCoreExecuter());
            benchmarker.RegisterOrmExecuter(new Linq2SqlExecuter());

            /*benchmarker.RegisterOrmExecuter(new InsightDatabase.InsightDatabaseExecuter());
             * benchmarker.RegisterOrmExecuter(new InsightDatabase.InsightSingleDatabaseExecuter());
             * benchmarker.RegisterOrmExecuter(new OrmLite.OrmLiteExecuter());
             */

            Console.Write("\nDo you like to have a warm-up stage(y/[n])?");
            var str = Console.ReadLine();

            if (str.Trim().ToLower() == "y" || str.Trim().ToLower() == "yes")
            {
                warmUp = true;
            }

            Console.WriteLine(".NET: " + Environment.Version);
            Console.WriteLine("Connection string: {0}", connStr);
            Console.WriteLine("\nRunning...");

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("\tStep {0}", i + 1);
                benchmarker.Run(warmUp);
                OutputResult(benchmarker, warmUp);
            }
            Console.WriteLine("Finished.");

            Console.ReadLine();
        }
Esempio n. 14
0
        private static void StartSingle(BenchmarkParameters parameters)
        {
            Console.WriteLine("=== Start Single ===");

            var result = Benchmarker.Start(ActionToTest, parameters);

            Console.WriteLine(result.ToString());
        }
Esempio n. 15
0
        public TestFactory()
        {
            // See app.config:
            Types = Benchmarker.GetImplementations(typeof(IGraph <>), true).ToList();

            //// FindImplementations classes that implement IGraph
            //FindImplementations();
        }
 void Start()
 {
     //Debug.Log("Atkin");
     //Benchmarker.Benchmark(GetPrimesAtkin, iterations);
     //Debug.Log("Eratosthenes with culling");
     //Benchmarker.Benchmark(GetPrimesEratosthenes, iterations);
     Debug.Log("Eratosthenes with culling and multi threaded");
     Benchmarker.Benchmark(GetPrimesEratosthenesMultiThreaded, iterations);
 }
Esempio n. 17
0
        static void Main(string[] args)
        {
            var    bench  = new Benchmarker();
            var    chall  = new _48_SelfPowers();
            string result = "";

            bench.Benchmark(() => result = chall.Run());
            Console.WriteLine(result);
            Console.ReadLine();
        }
        public static void DemoTryCatchInnerLoop()
        {
            Benchmarker.Benchmark(() =>
            {
                for (int c = 0; c < _count; c++)
                {
                    try
                    {
                        //inner is slower
                        if (c < 0)
                        {
                            throw new Exception();
                        }
                        //no difference if u would change the previous statement by the following line of code:
                        //if (c < 0) return;
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }, "Inline try catch", 1, _count);

            Benchmarker.Benchmark(() =>
            {
                //TODO 1.26: move try catch
                for (int c = 0; c < _count; c++)
                {
                    try
                    { //outer is faster
                        if (c < 0)
                        {
                            throw new Exception();
                        }
                        //no difference if u would change the previous statement by the following line of code:
                        //if (c < 0) return;
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }, "Outer try catch", 1, _count);

            Console.WriteLine();

            /*
             * Summary: if we try this with code that can't throw an exception inside the try catch,
             * it doesn't seem to matter if the try catch statement is located inside or outside of the loop
             * However, from the moment an exception could occur,
             * it's significantly faster to wrap your try catch statement around the loop
             *
             * (test this yourself, check the comments in code)
             */
        }
Esempio n. 19
0
        public static void ExecuteDemoBoxingVsGenerics()
        {
            var        randomData = DataGenerator.GetRandomIntArray(3);
            ArrayList  objectList = new ArrayList(randomData.ToList());
            List <int> intList    = randomData.ToList();
            int        newNr      = DataGenerator.GetRandomInt();

            Benchmarker.Benchmark(() =>
            {
                //With boxing (the wrong way):
                objectList.Add(newNr); // boxing required
            }, "Using arrayList(boxing required)", _count);

            Benchmarker.Benchmark(() =>
            {
                //Without boxing (the right way):
                intList.Add(newNr);
            }, "Using generics (no boxing required)", _count);

            Console.WriteLine();

            Benchmarker.Benchmark(() =>
            {
                //With unboxing (the wrong way):
                int firstValue = (int)objectList[0]; // unboxing & casting required
            }, "Using arrayList (unboxing & casting required)", _count);

            Benchmarker.Benchmark(() =>
            {
                //Without unboxing (the right way):
                int orderId = intList[0];  // unboxing & casting not required
            }, "Using generics (unboxing & casting not required)", _count);

            Console.WriteLine();

            Benchmarker.Benchmark(() =>
            {
                //With (un)boxing (the wrong way):
                objectList.Add(newNr);               // boxing required
                int firstValue = (int)objectList[0]; // unboxing & casting required
            }, "Using arrayList (boxing, unboxing & casting required)", _count);

            Benchmarker.Benchmark(() =>
            {
                //Without (un)boxing (the right way):
                intList.Add(newNr);
                int orderId = intList[0];  // unboxing & casting not required
            }, "Using generics (no boxing, unboxing & casting required)", _count);

            Console.WriteLine();
        }
Esempio n. 20
0
        public static void DemoForVsForEach()
        {
            var intArray = DataGenerator.GetRandomIntArray(20);

            Benchmarker.Benchmark(() =>
            {
                int a = 0;
                foreach (int value in intArray)
                {
                    a += value;
                }
            }, "Foreach with 1x item access / iteration", 1, intArray.Length);

            Benchmarker.Benchmark(() =>
            {
                int a = 0;
                for (int i = intArray.Length - 1; i >= 0; i--)
                {
                    a += intArray[i];
                }
            }, "For with 1x array access / iteration", 1, intArray.Length);

            Benchmarker.Benchmark(() =>
            {
                int a = 0;
                for (int i = intArray.Length - 1; i >= 0; i--)
                {
                    a += intArray[i];
                    a += intArray[i];
                }
            }, "For with 2x array access / iteration", 1, intArray.Length);

            Benchmarker.Benchmark(() =>
            {
                int a = 0;
                foreach (int value in intArray)
                {
                    a += value;
                    a += value;
                }
            }, "Foreach with 2x item access / iteration", 1, intArray.Length);

            Console.WriteLine();

            /*
             * Summary: a for loop is usually faster if the array only has to be accessed once per iteration
             * Foreach uses a local variable to save the value of the array element,
             * which increases performance when this value has to be accessed multiple times.
             * This also explains the delay when an item only has to be accessed once (allocation of the local variable)
             */
        }
        public static void DemoInlining()
        {
            //Inlining: optimization by which a method call is replaced with the method body

            Benchmarker.Benchmark(() =>
            {
                NoInliningMethod();
            }, "No inlining", 1);

            Benchmarker.Benchmark(() =>
            {
                DefaultInliningMethod();
            }, "Default inlining", 1);

            Benchmarker.Benchmark(() =>
            {
                AggressiveInliningMethod();
            }, "Aggressive inlining", 1);

            Console.WriteLine();

            Benchmarker.Benchmark(() =>
            {
                NoInliningMethod();
            }, "No inlining loop", _count);

            Benchmarker.Benchmark(() =>
            {
                DefaultInliningMethod();
            }, "Default inlining loop", _count);

            Benchmarker.Benchmark(() =>
            {
                AggressiveInliningMethod();
            }, "Aggressive inlining loop", _count);

            Console.WriteLine();

            /*
             * Summary: If a method is only called in a single place in a program, it MAY help to inline it agressively.
             * However, if a method is called in many places, inlining it may ruin performance due to messed up references
             * (this is especially the case for larger methods)
             * 
             * You might think this is helpful when using private methods in a class only once, however:
             *  - if another developer reuses this method in the future, your program's performance may become negatively impacted
             *  - if the code that calls your method is executed multiple times, default inlining could actually be faster
             *  - results are mixed, depending on the underlying code
             *  
             *  Conclusion: DO NOT USE THIS OR YOU/SOMEONE ELSE WILL PROBABLY CAUSE THE PROGRAM TO SLOW DOWN AT SOME POINT IN TIME
             */
        }
Esempio n. 22
0
        public static void LoopOverCharacters()
        {
            var input = " " + string.Concat(DataGenerator.GetRandomStringArray(50));

            // Check characters in string with ToString() extension method.
            Benchmarker.Benchmark(() =>
            {
                int spaces = 0;
                for (int i = 0; i < input.Length; i++)
                {
                    if (input[i].ToString() == " ")
                    {
                        spaces++;
                    }
                }
                Console.WriteLine($"Results: {spaces}");
            }, "Spaces with char ToString()", 1);

            // Check characters in string with Contains() extension method.
            Benchmarker.Benchmark(() =>
            {
                int spaces = input.Count(x => x.Equals(' '));
                Console.WriteLine($"Results: {spaces}");
            }, "Space chars with Linq's Count() method", 1);

            Benchmarker.Benchmark(() =>
            {
                int spaces = input.Count(x => x.Equals(" "));
                Console.WriteLine($"Results: {spaces}");
            }, "Space strings with Linq's Count() method (incorrect result!)", 1);

            // Check characters in string.
            Benchmarker.Benchmark(() =>
            {
                int spaces = 0;
                for (int i = 0; i < input.Length; i++)
                {
                    if (input[i] == ' ')
                    {
                        spaces++;
                    }
                }
                Console.WriteLine($"Results: {spaces}");
            }, "Spaces with char", 1);

            Console.WriteLine();

            //Don't use ToString() extension method when checking characters. Don't use LINQ either
        }
Esempio n. 23
0
        public override async Task SetupAsync(WorkerContext context)
        {
            Console.WriteLine("Setup");
            _cts         = new CancellationTokenSource();
            _hostAddress = Environment.GetEnvironmentVariable("BENCH_SERVER_HOST") ?? throw new ArgumentNullException($"Environment variables BENCH_SERVER_HOST is missing.");
            _reportId    = Environment.GetEnvironmentVariable("BENCH_REPORTID") ?? throw new ArgumentNullException($"Environment variables BENCH_REPORTID is missing.");
            var path        = Environment.GetEnvironmentVariable("BENCH_S3BUCKET") ?? throw new ArgumentNullException($"Environment variables BENCH_S3BUCKET is missing.");
            var duration    = Environment.GetEnvironmentVariable("BENCH_DURATION") ?? "30s";
            var concurrency = Environment.GetEnvironmentVariable("BENCH_CONCURRENCY") ?? "50";
            var connections = Environment.GetEnvironmentVariable("BENCH_CONNECTIONS") ?? "20";

            // must add port like server.local:80
            if (_hostAddress.StartsWith("http://"))
            {
                _hostAddress = _hostAddress?.Replace("http://", "") + ":80";
            }
            if (_hostAddress.StartsWith("https://"))
            {
                _hostAddress = _hostAddress?.Replace("https://", "") + ":443";
            }

            // non ssl localhost
            //_hostAddress = "localhost:5000";
            //_reportId = "abc-123";
            //var path = "magiconionbenchmarkcdkstack-bucket83908e77-1ado8gtcl00cb";

            // ssl local host
            //_hostAddress = "server.local:5001"; // makesure you have create hosts record for `server.local`.
            //_reportId = "abc-123";
            //var path = "magiconionbenchmarkcdkstack-bucket83908e77-1ado8gtcl00cb";

            var iterations = new[] { 1 };

            _waitMilliseconds = 240_000; // 1000 = 1sec
            _isHttps          = _hostAddress.StartsWith("https://");

            Console.WriteLine($"waitMilliseconds {_waitMilliseconds}ms, iterations {string.Join(",", iterations)}, hostAddress {_hostAddress}, reportId {_reportId}, path {path}");
            _benchmarker = new Benchmarker(path, null, _cts.Token)
            {
                Config = new BenchmarkerConfig
                {
                    ClientConcurrency   = int.Parse(concurrency),
                    ClientConnections   = int.Parse(connections),
                    Duration            = duration,
                    TotalRequests       = iterations,
                    UseSelfCertEndpoint = _hostAddress.StartsWith("https://"),
                }
            };
        }
Esempio n. 24
0
        private async void Button_Click(object sender, System.EventArgs e)
        {
            try
            {
                Benchmarker benchmarker = new Benchmarker();
                var         results     = await benchmarker.RunAsync();

                this.recyclerView.SetAdapter(new ChartsAdapter(results));
                this.recyclerView.SetLayoutManager(new LinearLayoutManager(this));
            }
            catch (System.Exception)
            {
                throw;
            }
        }
Esempio n. 25
0
 private static void Run(RunSettings options)
 {
     if (options.Benchmark)
     {
         Benchmarker.RunBenchmark(options.Bench);
     }
     else if (options.RunAllSieves)
     {
         SieveRunner.RunAllSieves(options);
     }
     else
     {
         SieveRunner.RunSieve(options);
     }
 }
        public static void DemoNestedVsSequential()
        {
            Benchmarker.Benchmark(() =>
            {
                Nested1();
            }, "Nested", _count);

            Benchmarker.Benchmark(() =>
            {
                Sequential1();
            }, "Sequential", _count);

            Console.WriteLine();

            //Summary: deeper call stack should be less performant, however the difference seems negligible
        }
Esempio n. 27
0
        public static string GetHash(string path, Hash hashType, bool log = true, bool quick = true)
        {
            Benchmarker.Start();
            string hashStr = "";

            if (IsPathDirectory(path))
            {
                Logger.Log($"Path '{path}' is directory! Returning empty hash.", true);
                return(hashStr);
            }
            try
            {
                var stream = File.OpenRead(path);

                if (hashType == Hash.MD5)
                {
                    MD5 md5  = MD5.Create();
                    var hash = md5.ComputeHash(stream);
                    hashStr = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
                }

                if (hashType == Hash.CRC32)
                {
                    var crc        = new Crc32Algorithm();
                    var crc32bytes = crc.ComputeHash(stream);
                    hashStr = BitConverter.ToUInt32(crc32bytes, 0).ToString();
                }

                if (hashType == Hash.xxHash)
                {
                    ulong xxh64 = xxHash64.ComputeHash(stream, 8192, (ulong)GetFilesize(path));
                    hashStr = xxh64.ToString();
                }

                stream.Close();
            }
            catch (Exception e)
            {
                Logger.Log($"Error getting file hash for {Path.GetFileName(path)}: {e.Message}", true);
                return("");
            }
            if (log)
            {
                Logger.Log($"Computed {hashType} for '{Path.GetFileNameWithoutExtension(path).Trunc(40) + Path.GetExtension(path)}' ({GetFilesizeStr(path)}) in {Benchmarker.GetTimeStr(true)}: {hashStr}", true);
            }
            return(hashStr);
        }
Esempio n. 28
0
        public static void Benchmark(params Action[] fn)
        {
            if (!FiTechCoreExtensions.EnableBenchMarkers)
            {
                fn.ForEach(a => a?.Invoke());
                return;
            }
            Benchmarker bm = new Benchmarker();
            var         i  = 0;

            foreach (var a in fn)
            {
                bm.Mark($"{++i}");
                a?.Invoke();
            }
            bm.FinalMark();
        }
Esempio n. 29
0
        private static ValueTuple <int, int> RunBenchmark(int sourceLength, int subCollectionLength)
        {
            const int N = 100000;

            var source        = Enumerable.Range(1, sourceLength).ToArray();
            var subCollection = Enumerable.Range(1, subCollectionLength).ToArray(); // This gets repeated `sourceLength` times.

            var iterator = source.SelectMany(_ => subCollection);

            return(Benchmarker.Bench(state =>
            {
                for (int i = 0; i < N; i++)
                {
                    state.ToArray();
                }
            }, iterator));
        }
Esempio n. 30
0
        private static void StartScope(BenchmarkParameters parameters)
        {
            Console.WriteLine("=== Start Scope ===");

            var iterations = parameters.BenchmarkIterations;
            var result     = new BenchmarkResult();

            using (var benchmark = Benchmarker.StartScope(result))
            {
                for (long i = 0; i < iterations; i++)
                {
                    ActionToTest();
                }
            }

            Console.WriteLine(result.ToString());
        }
Esempio n. 31
0
	static async Task<ParseObject> GetPullRequestBaselineRunSet (string pullRequestURL, Benchmarker.Common.Git.Repository repository, Config config)
	{
		var gitHubClient = GitHubInterface.GitHubClient;
		var match = Regex.Match (pullRequestURL, @"^https?://github\.com/mono/mono/pull/(\d+)/?$");
		if (match == null) {
			Console.WriteLine ("Error: Cannot parse pull request URL.");
			Environment.Exit (1);
		}
		var pullRequestNumber = Int32.Parse (match.Groups [1].Value);
		Console.WriteLine ("pull request {0}", pullRequestNumber);

		var pullRequest = await gitHubClient.PullRequest.Get ("mono", "mono", pullRequestNumber);

		var prRepo = pullRequest.Head.Repository.SshUrl;
		var prBranch = pullRequest.Head.Ref;

		var prSha = repository.Fetch (prRepo, prBranch);
		if (prSha == null) {
			Console.Error.WriteLine ("Error: Could not fetch pull request branch {0} from repo {1}", prBranch, prRepo);
			Environment.Exit (1);
		}

		var masterSha = repository.Fetch ("[email protected]:mono/mono.git", "master");
		if (masterSha == null) {
			Console.Error.WriteLine ("Error: Could not fetch master.");
			Environment.Exit (1);
		}

		var baseSha = repository.MergeBase (prSha, masterSha);
		if (baseSha == null) {
			Console.Error.WriteLine ("Error: Could not determine merge base of pull request.");
			Environment.Exit (1);
		}

		Console.WriteLine ("Merge base sha is {0}", baseSha);

		var revList = repository.RevList (baseSha);
		if (revList == null) {
			Console.Error.WriteLine ("Error: Could not get rev-list for merge base {0}.", baseSha);
			Environment.Exit (1);
		}
		Console.WriteLine ("{0} commits in rev-list", revList.Length);

		var configObj = await config.GetFromParse ();
		if (configObj == null) {
			Console.Error.WriteLine ("Error: The config does not exist.");
			Environment.Exit (1);
		}

		var machineObj = await RunSet.GetMachineFromParse ();
		if (machineObj == null) {
			Console.Error.WriteLine ("Error: The machine does not exist.");
			Environment.Exit (1);
		}

		var runSets = await ParseInterface.PageQueryWithRetry (() => ParseObject.GetQuery ("RunSet")
			.WhereEqualTo ("machine", machineObj)
			.WhereEqualTo ("config", configObj)
			.WhereDoesNotExist ("pullRequest")
			.Include ("commit"));
		Console.WriteLine ("{0} run sets", runSets.Count ());

		var runSetsByCommits = new Dictionary<string, ParseObject> ();
		foreach (var runSet in runSets) {
			var sha = runSet.Get<ParseObject> ("commit").Get<string> ("hash");
			if (runSetsByCommits.ContainsKey (sha)) {
				// FIXME: select between them?
				continue;
			}
			runSetsByCommits.Add (sha, runSet);
		}

		foreach (var sha in revList) {
			if (runSetsByCommits.ContainsKey (sha)) {
				Console.WriteLine ("tested base commit is {0}", sha);
				return runSetsByCommits [sha];
			}
		}

		return null;
	}
Esempio n. 32
0
 protected Sample()
 {
     Benchmarker = new Benchmarker() {CopyResultsToClipboard = true};
 }