<commit_before>﻿#region License Information
/* SimSharp - A .NET port of SimPy, discrete event simulation framework
Copyright (C) 2016  Heuristic and Evolutionary Algorithms Laboratory (HEAL)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.*/
#endregion

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Timers;

namespace SimSharp.Benchmarks {
  class Program {
    private static long perf = 0;
    private static Event terminate;

    private static void Timeout(object sender, ElapsedEventArgs e) {
      terminate.Succeed();
    }

    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;
        }<commit_msg>Accept decimal points in Benchmarks input for CPU Frequency<commit_after>﻿#region License Information
/* SimSharp - A .NET port of SimPy, discrete event simulation framework
Copyright (C) 2016  Heuristic and Evolutionary Algorithms Laboratory (HEAL)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.*/
#endregion

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Timers;

namespace SimSharp.Benchmarks {
  class Program {
    private static long perf = 0;
    private static Event terminate;

    private static void Timeout(object sender, ElapsedEventArgs e) {
      terminate.Succeed();
    }

    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.AllowDecimalPoint | 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;
        }
{'fraction_non_alphanumeric': 0.10671151200122306, 'fraction_numerical': 0.02079192783977985, 'mean_word_length': 2.812354312354312, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '792187', 'n_tokens_mistral': 1957, 'n_tokens_neox': 1798, 'n_words': 639}