Click here to Skip to main content
15,894,343 members
Home / Discussions / C#
   

C#

 
GeneralRe: How can I optimize this code Pin
Nagy Vilmos15-May-09 4:27
professionalNagy Vilmos15-May-09 4:27 
GeneralRe: How can I optimize this code Pin
MumbleB15-May-09 23:28
MumbleB15-May-09 23:28 
GeneralRe: How can I optimize this code Pin
Luc Pattyn16-May-09 1:08
sitebuilderLuc Pattyn16-May-09 1:08 
GeneralRe: How can I optimize this code Pin
MumbleB16-May-09 5:55
MumbleB16-May-09 5:55 
GeneralRe: How can I optimize this code Pin
Luc Pattyn16-May-09 6:54
sitebuilderLuc Pattyn16-May-09 6:54 
GeneralRe: How can I optimize this code Pin
MumbleB17-May-09 22:32
MumbleB17-May-09 22:32 
GeneralRe: How can I optimize this code Pin
Luc Pattyn18-May-09 0:37
sitebuilderLuc Pattyn18-May-09 0:37 
GeneralRe: How can I optimize this code Pin
MumbleB18-May-09 7:11
MumbleB18-May-09 7:11 
The way I had the code written was that for each instance of ID in file1 found in file2 it wrote the whole of file2 as I had file2 completely read into memory and for some stupidness of myself I had it coded that way. Now, I have ammended this code to the below which seems to work just fine but the performance is still "pish" as it itterates 2000* through 80000 records to find a match. There are instances where an ID in FILE1 could exist more then once in FILE2. So, on a file of 80000 records it does a 160 000 000 reads on file2 which could mean a major hit on performance.

Luc Pattyn wrote:
Now start looking at what you have, and stop making up stories


I swear I'm not making up stories. Laugh | :laugh:

THis is what I have refined the code to now but I am sure it CAN be sped up much more.
My actual files have these amounts of records on it.
FILE1 = 10948 Lines of 25 characters per line. (289KB)
FILE2 = 360 Lines of 650 characters per line. (247KB)
FILE3 = 79341 Lines of 650 characters per line. (54,392KB)
FILE4 = 76283 Lines of 700 characters per line. (50,508KB)

To process this it takes all of 34.61 seconds to complete which is fine and the resultant file is 100% spot on.

Now, processing FILE1 with 10948 lines of data against another file, say FILE3 with 79341 lines with 650 characters per line it takes forever.

The code implimented is as follows:
string fileNot;
string fileHid;
string outPath = @"c:\Documents and Settings\Mumbleb\Desktop\Ess\";
fileNot = textBox1.Text;
fileHid = textBox2.Text;
StreamWriter sw = new StreamWriter(outPath + "ER_AU_TBSZ_SEQMHN.TXT");
string[] LineHID = File.ReadAllLines(fileHid);
string[] LineNot = File.ReadAllLines(fileNot);
foreach (string hid in LineHID)
{
    string OldHid = hid.Substring(0, 11);
    string NewHid = hid.Substring(14, 11);
    foreach (string content in LineNot)
    {

        string matchid = content.Substring(0, 11);
        string noting = content.Substring(11, 605).Trim();
        if (OldHid == matchid)
        {
            string contentnew = Regex.Replace(content, matchid, NewHid);
            sw.WriteLine(NewHid + noting);
        }
    }
}
sw.Close();

I am about to try and process the bigger files on my Dualcore Laptop and see what the performance is like. I will post if I have any timings on the performance.

Excellence is doing ordinary things extraordinarily well.

GeneralRe: How can I optimize this code Pin
Luc Pattyn18-May-09 7:30
sitebuilderLuc Pattyn18-May-09 7:30 
GeneralRe: How can I optimize this code Pin
MumbleB18-May-09 20:17
MumbleB18-May-09 20:17 
AnswerRe: How can I optimize this code Pin
Henry Minute15-May-09 4:18
Henry Minute15-May-09 4:18 
QuestionWeb setup project fails in Windows vista and IIS7 Pin
Muhammad Sohaib Yousaf15-May-09 1:44
Muhammad Sohaib Yousaf15-May-09 1:44 
QuestionAccepting user input Pin
Rajdeep.NET is BACK15-May-09 1:15
Rajdeep.NET is BACK15-May-09 1:15 
AnswerRe: Accepting user input Pin
Pete O'Hanlon15-May-09 1:21
mvePete O'Hanlon15-May-09 1:21 
GeneralRe: Accepting user input Pin
Rajdeep.NET is BACK15-May-09 2:19
Rajdeep.NET is BACK15-May-09 2:19 
GeneralRe: Accepting user input Pin
Tom Deketelaere15-May-09 2:28
professionalTom Deketelaere15-May-09 2:28 
GeneralRe: Accepting user input Pin
Rajdeep.NET is BACK15-May-09 2:37
Rajdeep.NET is BACK15-May-09 2:37 
GeneralRe: Accepting user input Pin
Tom Deketelaere15-May-09 2:47
professionalTom Deketelaere15-May-09 2:47 
GeneralRe: Accepting user input Pin
Rajdeep.NET is BACK15-May-09 2:58
Rajdeep.NET is BACK15-May-09 2:58 
GeneralRe: Accepting user input Pin
tom57200715-May-09 3:18
tom57200715-May-09 3:18 
GeneralRe: Accepting user input Pin
Dave Kreskowiak15-May-09 2:37
mveDave Kreskowiak15-May-09 2:37 
GeneralRe: Accepting user input Pin
Pete O'Hanlon15-May-09 3:10
mvePete O'Hanlon15-May-09 3:10 
GeneralRe: Accepting user input Pin
Nagy Vilmos15-May-09 4:01
professionalNagy Vilmos15-May-09 4:01 
GeneralRe: Accepting user input Pin
Luc Pattyn15-May-09 4:10
sitebuilderLuc Pattyn15-May-09 4:10 
GeneralRe: Accepting user input PinPopular
Pete O'Hanlon15-May-09 4:41
mvePete O'Hanlon15-May-09 4:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.