everyone. I want to parse 300+Mb text-file with 2.000.000+ lines in it and make some operations(split every line, make comparsions, save data in dict.) with stored data. It takes program ~50+ mins to get expected result (for files with 80.000 lines it takes about 15-20seconds) Is there any way to make it to work faster? Code sample below:
using (FileStream cut_file = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (BufferedStream bs = new BufferedStream(cut_file))
using (StreamReader s_reader = new StreamReader(bs)) {
string line;
while ((line = s_reader.ReadLine()) != null) {
string[] every_item = line.Split('|'); //line sample: jdsga237 | 3332, 3223, 121 |
string car = every_item[0];
string[] cameras = every_item[1].Split(',');
if (!cars.Contains(car)) { //cars is List<string> defined at the beginning of programm
for (int camera = 0; camera < cameras.Count(); camera++) {
if (cams_input.Contains(cameras[camera])) { //cams_input is List<string> defined at the beginning of programm
cars.Add(car);
result[myfile]++; //result is Dictionary<string, int>. Used dict. for parsing several files.
}
}
}
}
}