Ejemplo n.º 1
0
        private static List <BenchmarkCountWordToDictSize> GetResultBenshWordCount()
        {
            var replaceTimer = new Stopwatch();
            var benchmarkCountWordToDictSizes = new List <BenchmarkCountWordToDictSize>();

            for (var wordCount = 1000; wordCount <= 100000000; wordCount *= 10)
            {
                for (var dictLineCount = 1000; dictLineCount <= 128000; dictLineCount *= 2)
                {
                    var text      = GenerateText(1, wordCount);
                    var wordsDict = GenerateDict(dictLineCount);

                    replaceTimer.Start();
                    var replacedData = WordReplacer.ReplaceWordsInStrings(text, wordsDict);
                    replaceTimer.Stop();

                    benchmarkCountWordToDictSizes.Add(new BenchmarkCountWordToDictSize(wordCount, dictLineCount, replaceTimer.ElapsedMilliseconds));

                    Console.WriteLine($"Слов: {wordCount}\n" +
                                      $"Строк в словаре: {dictLineCount}\n" +
                                      $"Замена слов заняла: {replaceTimer.ElapsedMilliseconds} мс\n");
                }
            }

            return(benchmarkCountWordToDictSizes);
        }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            try
            {
                var inputTimer   = new Stopwatch();
                var replaceTimer = new Stopwatch();
                var outputTimer  = new Stopwatch();

                var argParser = new ConsoleArgsParser(args);
                var options   = argParser.Options;
                if (options == null)
                {
                    return;
                }
                var reader = argParser.Reader;
                var writer = argParser.Writer;

                var wordsDict = options.GetWordsFromOptions();
                inputTimer.Start();
                var inputData = reader.ReadAll();
                inputTimer.Stop();

                replaceTimer.Start();
                var replacedData = WordReplacer.ReplaceWordsInStrings(inputData, wordsDict);
                replaceTimer.Stop();

                outputTimer.Start();
                writer.Write(replacedData);
                outputTimer.Stop();

                if (options.TimeTheProgram)
                {
                    Console.WriteLine($"\n\nЧтение заняло: {inputTimer.ElapsedMilliseconds} мс\n" +
                                      $"Замена слов заняла: {replaceTimer.ElapsedMilliseconds} мс\n" +
                                      $"Вывод занял: {outputTimer.ElapsedMilliseconds} мс");
                }
            }

            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
            }
        }