Results 1 to 6 of 6

Thread: Faster Code Needed

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2008
    Location
    Vancouver, BC, Canada
    Posts
    24

    Faster Code Needed

    I have a simple sub within a project that is executed about 2 or 3 x 10^6 times during processing of data stored in txt files. It basically does something like the following.

    StrArray = Split(Str, ",") - Line results in StrArray with a length of about 12
    RetVal1 = CINT(StrArray(0))
    RetVal2 = CDBL(StrArray(1))
    RetVal3 = DateTime.ParseExact(StrArray(2), "FormatStr", CulturalInfo)
    ...and a few more lines like the last three. I'm going by memory, but there isn't much more than that really.

    The values Ret1, Ret2(...) are ByRef variables that are not reinitiated within the sub every time it is called.

    That's about it. The result is a couple minutes of processing time, which is beyond my patience reserves. The Split() function seems to take the most amount of time.

    I can't think of any way of speeding this up other than creating a non-managed DLL using C++. Would that be substantially quicker? I haven't used C++ much (the last version I ever used was Borland 2.0) but I imagine I could figure out some simple code like this. Would it be much of an improvement? Is there a better/easier way to speed this up?

    Thanks.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Faster Code Needed

    you could probably speed it up with LINQ, working with the entire file would be quicker

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Faster Code Needed

    hhmmmmm you're splitting it up on a comma.... I'm guessing it's a CSV text file of some kind? How are you reading the file?
    You might be able to read the file into a DataTable instead.... should be faster than doing all that string manipulation.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Faster Code Needed

    I think you can attach to that like a database and suck the whole thing into a datatable in one step. I forget whether I have tried it, but I have seen something about that. I am doing something in one project where I read in CSV files, but I forget how I was doing it. I suspect that it wasn't all that fast, as the files were kind of unusual. If you are going for speed, I would definitely be looking at querying the file.
    My usual boring signature: Nothing

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Faster Code Needed

    yup pretty much that's the way it works.... get the connection string right and it'll suck it right in. Done it before, works great. They have the connectionstring over at connectionstrings.com ... I'm pretty sure that's where I got it. The down side is that the fields aren't typed, I think they stay as strings. Never tried it with a typed DT though... not sure if that would work.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Faster Code Needed

    Actually, the fields should be type Object, which is all you get for the untyped Datatable object.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width