Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Apart from the problem writing to the console, you also have a <strong>O(m*n) runtime</strong> for n being the number of lines in the file and m being the number of messages. This is bad if m or n is big. You can reduce this to an O(n) operation by using a <code>Dictionary</code> instead and eliminating the inner loop. </p> <p>You can put your messages in a <code>Dictionary</code>, using the Time as a key. In the loop you only have to ask the dictionary for the messages at a specific time:</p> <pre><code> string fmtLine = ""; string[] splitedFmtLine; int counterFMTlines = 0; var messageTimes = new Dictionary&lt;string, LinkedList&lt;L3Message&gt;&gt;(); foreach (L3Message message in rez) { LinkedList&lt;L3Message&gt; list=null; messageTimes.TryGetValue(message.Time, out list); list = list ?? new LinkedList&lt;L3Message&gt;(); list.AddLast(message); messageTimes[message.Time] = list; } foreach (string fmtF in fmtFiles) { using (StreamReader sr = new StreamReader(fmtF)) { while ((fmtLine = sr.ReadLine()) != null) { //Console.WriteLine(counterFMTlines++); splitedFmtLine = fmtLine.Split('\t'); LinkedList&lt;L3Message&gt; messageList = null; messageTimes.TryGetValue(splitedFmtLine[0], out messageList); if(messageList != null) { foreach (var message in messageList) { message.ScramblingCode = splitedFmtLine[7]; } messageTimes.Remove(splitedFmtLine[0]); //see comments } if(messageTimes.Count==0) break; //see comments } } if(messageTimes.Count==0) break; //see comments } </code></pre> <p>This should be super fast.</p> <p><strong>Edit:</strong> I changed the example so that it supports cases where there is more than one message for one time.</p> <p><strong>Edit2:</strong> I added an optimization based on the fact that message time and ScramblingCode always correlate (see comments).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload