HiveBrain v1.2.0
Get Started
← Back to all entries
snippetcsharpMinor

How do I make this function faster?

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
thismakefunctionfasterhow

Problem

I have all large file of all the order sold in one week. This file gives one line for every order. We have over 5000 orders a day. It read the file line by line and then adds the sale to a database of sales. to I really need to boost performance.

static void sold4weeks1()
    {
        string sold, asin;
        string[] lines = System.IO.File.ReadAllLines(@"C:\out\qqqqq.txt");

        inventoryBLL u = new inventoryBLL();
        try
        {
            foreach (string line in lines)
            {

                char[] tabs = { '\t' };
                string[] words = line.Split(tabs);
                asin = words[12];
                sold = words[14];

                if (words[0].Substring(0, 3) == "S01") continue;
                try
                {
                    if (words[4] == "Shipped" || words[4] == "Unshipped")
                    {

                        u.setSoldin28(asin, Convert.ToInt16(sold));
                        Console.WriteLine("Update");
                    }
                }
                catch
                {
                }
            }
        }
        catch
        { }
    }

Solution

Is u.setSoldin28(asin, Convert.ToInt16(sold)); writing to the database?

Save up all your changes and make them all under a single connection when the parse is finished. That should save quite a bit of time.

You have alot of other issues with this code though. I strongly urge you to look into proper exception handling techniques.

Context

StackExchange Code Review Q#4965, answer score: 8

Revisions (0)

No revisions yet.