static void Main(string[] args)
        {
            var time = -1.0;
              var repetitions = -1;
              var CPU_FRQ = 0L;
              string input;
              do {
            Console.Write("How many repetitions [3]: ");
            input = Console.ReadLine().Trim();
            if (input == string.Empty) repetitions = 3;
            else int.TryParse(input, NumberStyles.None, CultureInfo.CurrentCulture.NumberFormat, out repetitions);
              } while (repetitions < 1);

              do {
            Console.Write("How many seconds per repetition [60]: ");
            input = Console.ReadLine().Trim();
            if (input == string.Empty) time = 60;
            else double.TryParse(input, NumberStyles.AllowDecimalPoint, CultureInfo.CurrentCulture.NumberFormat, out time);
              } while (time <= 0);

              do {
            Console.Write("Please specify your CPU frequency in GHz [{0:0.0}]: ", 2.6);
            input = Console.ReadLine().Trim();
            if (input == string.Empty) CPU_FRQ = 2600000000;
            else {
              double ghz;
              if (double.TryParse(input,
            NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite | NumberStyles.AllowThousands,
            CultureInfo.CurrentCulture.NumberFormat, out ghz))
            CPU_FRQ = (long)Math.Round(ghz * 1E9);
            }
              } while (CPU_FRQ <= 0);

              Console.WriteLine();
              Console.WriteLine("== Starting Benchmark: {0} repetitions for {1:##,###}ms each. CPU clock frequency is {2:##,###}Hz ==", repetitions, (int)(time * 1000), CPU_FRQ);
              Console.WriteLine();
              var frqMod = CPU_FRQ / (double)Stopwatch.Frequency;

              var sumTime = 0.0;
              var sumPerf = 0.0;
              foreach (var n in new[] { 1, 10, 100, 1000, 10000 }) {
            for (var r = 0; r < repetitions; r++) {
              var env = new SimSharp.Environment();
              terminate = new Event(env);
              var clk = new Timer((int)(time * 1000));
              clk.Elapsed += Timeout;
              clk.Start();
              sumTime += Benchmark1(env, n);
              sumPerf += perf;
              clk.Stop();
              clk.Elapsed -= Timeout;
            }
            sumTime /= repetitions;
            sumPerf /= repetitions;
            Console.WriteLine("Benchmark 1 (n = {0,6:##,0}): {1,7:0,0} clock cycles ({2,10:0,0} entities / s)", n, frqMod * sumTime / sumPerf, Stopwatch.Frequency * sumPerf / sumTime);
              }

              sumTime = 0.0;
              sumPerf = 0.0;
              for (var r = 0; r < repetitions; r++) {
            var env = new SimSharp.Environment();
            terminate = new Event(env);
            var clk = new Timer((int)(time * 1000));
            clk.Elapsed += Timeout;
            clk.Start();
            sumTime += Benchmark2(env);
            sumPerf += perf;
            clk.Stop();
            clk.Elapsed -= Timeout;
              }
              sumTime /= repetitions;
              sumPerf /= repetitions;
              Console.WriteLine("Benchmark 2: {0,20:0,0} clock cycles ({1,10:0,0} entities / s)", frqMod * sumTime / sumPerf, Stopwatch.Frequency * sumPerf / sumTime);

              sumTime = 0.0;
              sumPerf = 0.0;
              for (var r = 0; r < repetitions; r++) {
            var env = new SimSharp.Environment();
            terminate = new Event(env);
            var clk = new Timer((int)(time * 1000));
            clk.Elapsed += Timeout;
            clk.Start();
            sumTime += Benchmark3(env);
            sumPerf += perf;
            clk.Stop();
            clk.Elapsed -= Timeout;
              }
              sumTime /= repetitions;
              sumPerf /= repetitions;
              Console.WriteLine("Benchmark 3: {0,20:0,0} clock cycles ({1,10:0,0} entities / s)", frqMod * sumTime / sumPerf, Stopwatch.Frequency * sumPerf / sumTime);
              Console.WriteLine();
              Console.WriteLine("== Finished Benchmark ==");
              Console.ReadLine();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var    time        = -1.0;
            var    repetitions = -1;
            var    CPU_FRQ     = 0L;
            string input;

            do
            {
                Console.Write("How many repetitions [3]: ");
                input = Console.ReadLine().Trim();
                if (input == string.Empty)
                {
                    repetitions = 3;
                }
                else
                {
                    int.TryParse(input, NumberStyles.None, CultureInfo.CurrentCulture.NumberFormat, out repetitions);
                }
            } while (repetitions < 1);

            do
            {
                Console.Write("How many seconds per repetition [60]: ");
                input = Console.ReadLine().Trim();
                if (input == string.Empty)
                {
                    time = 60;
                }
                else
                {
                    double.TryParse(input, NumberStyles.AllowDecimalPoint, CultureInfo.CurrentCulture.NumberFormat, out time);
                }
            } while (time <= 0);

            do
            {
                Console.Write("Please specify your CPU frequency in GHz [{0:0.0}]: ", 2.6);
                input = Console.ReadLine().Trim();
                if (input == string.Empty)
                {
                    CPU_FRQ = 2600000000;
                }
                else
                {
                    double ghz;
                    if (double.TryParse(input,
                                        NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite | NumberStyles.AllowThousands,
                                        CultureInfo.CurrentCulture.NumberFormat, out ghz))
                    {
                        CPU_FRQ = (long)Math.Round(ghz * 1E9);
                    }
                }
            } while (CPU_FRQ <= 0);

            Console.WriteLine();
            Console.WriteLine("== Starting Benchmark: {0} repetitions for {1:##,###}ms each. CPU clock frequency is {2:##,###}Hz ==", repetitions, (int)(time * 1000), CPU_FRQ);
            Console.WriteLine();
            var frqMod = CPU_FRQ / (double)Stopwatch.Frequency;

            var sumTime = 0.0;
            var sumPerf = 0.0;

            foreach (var n in new[] { 1, 10, 100, 1000, 10000 })
            {
                for (var r = 0; r < repetitions; r++)
                {
                    var env = new SimSharp.Environment();
                    terminate = new Event(env);
                    var clk = new Timer((int)(time * 1000));
                    clk.Elapsed += Timeout;
                    clk.Start();
                    sumTime += Benchmark1(env, n);
                    sumPerf += perf;
                    clk.Stop();
                    clk.Elapsed -= Timeout;
                }
                sumTime /= repetitions;
                sumPerf /= repetitions;
                Console.WriteLine("Benchmark 1 (n = {0,6:##,0}): {1,7:0,0} clock cycles ({2,10:0,0} entities / s)", n, frqMod * sumTime / sumPerf, Stopwatch.Frequency * sumPerf / sumTime);
            }

            sumTime = 0.0;
            sumPerf = 0.0;
            for (var r = 0; r < repetitions; r++)
            {
                var env = new SimSharp.Environment();
                terminate = new Event(env);
                var clk = new Timer((int)(time * 1000));
                clk.Elapsed += Timeout;
                clk.Start();
                sumTime += Benchmark2(env);
                sumPerf += perf;
                clk.Stop();
                clk.Elapsed -= Timeout;
            }
            sumTime /= repetitions;
            sumPerf /= repetitions;
            Console.WriteLine("Benchmark 2: {0,20:0,0} clock cycles ({1,10:0,0} entities / s)", frqMod * sumTime / sumPerf, Stopwatch.Frequency * sumPerf / sumTime);

            sumTime = 0.0;
            sumPerf = 0.0;
            for (var r = 0; r < repetitions; r++)
            {
                var env = new SimSharp.Environment();
                terminate = new Event(env);
                var clk = new Timer((int)(time * 1000));
                clk.Elapsed += Timeout;
                clk.Start();
                sumTime += Benchmark3(env);
                sumPerf += perf;
                clk.Stop();
                clk.Elapsed -= Timeout;
            }
            sumTime /= repetitions;
            sumPerf /= repetitions;
            Console.WriteLine("Benchmark 3: {0,20:0,0} clock cycles ({1,10:0,0} entities / s)", frqMod * sumTime / sumPerf, Stopwatch.Frequency * sumPerf / sumTime);
            Console.WriteLine();
            Console.WriteLine("== Finished Benchmark ==");
            Console.ReadLine();
        }