Медленное выполнение программы

207
18 октября 2017, 04:18

Написал программу которая считывает информацию из файла в лист и выводит N раз. Но программа работает оооочень медленно. 1000000 записей за 9 минут, а надо за 1-2 .-. Подскажите в чём может быть причина? Как сделать выполнение быстрее. Вот код:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace FirstTask
{
    class Program
    {
        static List<string> MyInformation = new List<string>();
        static Random rand = new Random();
        static void Main(string[] args)
        {
            int countOfValue = Convert.ToInt32(Console.ReadLine());
            string region = Console.ReadLine();
            List<int> countOfSomeElenents = new List<int>();
            List<string> namesOfFile = new List<string>() { "cities", "streets", "house", "name", "surname", "numbers"};
            foreach (string i in namesOfFile)
            {
                countOfSomeElenents.Add(CreateFileStream(region, i));
            }
            for (int i = 0; i < countOfValue; i++)
            {
                OutPutInformation(countOfSomeElenents);
                Console.WriteLine();
            }
            Console.Read();
        }
        static int CreateFileStream (string region, string nameOfFile){
            FileStream file1 = new FileStream(String.Format("..\\..\\Data\\{0}_{1}.txt", region,nameOfFile), FileMode.Open); //создаем файловый поток
            StreamReader reader = new StreamReader(file1,System.Text.Encoding.GetEncoding(1251));
            while (String.Compare(reader.ReadLine(), null) > 0)
            {
                InformationToArray(Convert.ToString(reader.ReadLine()));
            }
            MyInformation.Remove(null);
            return MyInformation.Count;
        }
        static void InformationToArray (string someInformations){
            MyInformation.Add(someInformations);
        }
        static void OutPutInformation(List<int> countOfSomeElenents)
        {
            int min = 0;
            for (int i = 0; i < countOfSomeElenents.Count; i++)
            {
                Console.Write(MyInformation[rand.Next(min,countOfSomeElenents[i])]);
                min = countOfSomeElenents[i];
                Console.Write(' ');
            }
        }
    }
}
READ ALSO
Как читать строку из запущенной консоли на C#?

Как читать строку из запущенной консоли на C#?

Проблема заключается в следующем

252
Работа с SortedDictionary - C# [требует правки]

Работа с SortedDictionary - C# [требует правки]

Есть число в каждой строчке, + оно добавляется, - нужно убрать

210
Обработка big data, оптимизация сортировки

Обработка big data, оптимизация сортировки

Имеется входной файл ~ 1млн строк, которые должны сортироваться по определенному принципуНа данный момент сортировка происходит следующим...

258