Example #1
0
        static void RunAsyncBenchmark(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                Console.WriteLine($"{nameof(RunAsyncBenchmark)} {nameof(MillionAsync)}");
                using (var millionAsync = new MillionAsync())
                {
                    millionAsync.Run();
                }
            }

            if (string.IsNullOrEmpty(name))
            {
                Console.WriteLine($"{nameof(RunAsyncBenchmark)} {nameof(AsyncHandles)} (1)");
                using (var asyncThreads = new AsyncHandles(1))
                {
                    asyncThreads.Run();
                }

                if (processorCount >= 2)
                {
                    Console.WriteLine($"{nameof(RunAsyncBenchmark)} {nameof(AsyncHandles)} (2)");
                    using (var asyncThreads = new AsyncHandles(2))
                    {
                        asyncThreads.Run();
                    }
                }

                if (processorCount >= 4)
                {
                    Console.WriteLine($"{nameof(RunAsyncBenchmark)} {nameof(AsyncHandles)} (4)");
                    using (var asyncThreads = new AsyncHandles(4))
                    {
                        asyncThreads.Run();
                    }
                }

                if (processorCount >= 8)
                {
                    Console.WriteLine($"{nameof(RunAsyncBenchmark)} {nameof(AsyncHandles)} (8)");
                    using (var asyncThreads = new AsyncHandles(8))
                    {
                        asyncThreads.Run();
                    }
                }
            }

            if (string.IsNullOrEmpty(name) ||
                string.Compare(name, "pummel", StringComparison.CurrentCultureIgnoreCase) == 0)
            {
                Console.WriteLine($"{nameof(RunAsyncBenchmark)} {nameof(AsyncPummel)} (1)");
                using (var asyncPummel = new AsyncPummel(1))
                {
                    asyncPummel.Run();
                }

                if (processorCount >= 2)
                {
                    Console.WriteLine($"{nameof(RunAsyncBenchmark)} {nameof(AsyncPummel)} (2)");
                    using (var asyncPummel = new AsyncPummel(2))
                    {
                        asyncPummel.Run();
                    }
                }

                if (processorCount >= 4)
                {
                    Console.WriteLine($"{nameof(RunAsyncBenchmark)} {nameof(AsyncPummel)} (4)");
                    using (var asyncPummel = new AsyncPummel(4))
                    {
                        asyncPummel.Run();
                    }
                }

                if (processorCount >= 8)
                {
                    Console.WriteLine($"{nameof(RunAsyncBenchmark)} {nameof(AsyncPummel)} (8)");
                    using (var asyncPummel = new AsyncPummel(8))
                    {
                        asyncPummel.Run();
                    }
                }
            }
        }
Example #2
0
        static void RunAsyncBenchmark(IReadOnlyCollection <string> list)
        {
            if (list.Contains("asyncHandles", StringComparer.OrdinalIgnoreCase))
            {
                Console.WriteLine($"{nameof(RunAsyncBenchmark)} {nameof(MillionAsync)}");
                using (var millionAsync = new MillionAsync())
                {
                    millionAsync.Run();
                }
            }

            if (list.Contains("asyncSend", StringComparer.OrdinalIgnoreCase))
            {
                Console.WriteLine($"{nameof(RunAsyncBenchmark)} {nameof(AsyncHandles)} (1)");
                using (var asyncThreads = new AsyncHandles(1))
                {
                    asyncThreads.Run();
                }

                if (processorCount >= 2)
                {
                    Console.WriteLine($"{nameof(RunAsyncBenchmark)} {nameof(AsyncHandles)} (2)");
                    using (var asyncThreads = new AsyncHandles(2))
                    {
                        asyncThreads.Run();
                    }
                }

                if (processorCount >= 4)
                {
                    Console.WriteLine($"{nameof(RunAsyncBenchmark)} {nameof(AsyncHandles)} (4)");
                    using (var asyncThreads = new AsyncHandles(4))
                    {
                        asyncThreads.Run();
                    }
                }

                if (processorCount >= 8)
                {
                    Console.WriteLine($"{nameof(RunAsyncBenchmark)} {nameof(AsyncHandles)} (8)");
                    using (var asyncThreads = new AsyncHandles(8))
                    {
                        asyncThreads.Run();
                    }
                }
            }

            if (list.Contains("asyncPummel", StringComparer.OrdinalIgnoreCase))
            {
                Console.WriteLine($"{nameof(RunAsyncBenchmark)} {nameof(AsyncPummel)} (1)");
                using (var asyncPummel = new AsyncPummel(1))
                {
                    asyncPummel.Run();
                }

                if (processorCount >= 2)
                {
                    Console.WriteLine($"{nameof(RunAsyncBenchmark)} {nameof(AsyncPummel)} (2)");
                    using (var asyncPummel = new AsyncPummel(2))
                    {
                        asyncPummel.Run();
                    }
                }

                if (processorCount >= 4)
                {
                    Console.WriteLine($"{nameof(RunAsyncBenchmark)} {nameof(AsyncPummel)} (4)");
                    using (var asyncPummel = new AsyncPummel(4))
                    {
                        asyncPummel.Run();
                    }
                }

                if (processorCount >= 8)
                {
                    Console.WriteLine($"{nameof(RunAsyncBenchmark)} {nameof(AsyncPummel)} (8)");
                    using (var asyncPummel = new AsyncPummel(8))
                    {
                        asyncPummel.Run();
                    }
                }
            }
        }