CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2007
    Location
    Argentina
    Posts
    579

    Help with optimization

    This line:
    Code:
    L*neasDeArchivo = Split(sr.ReadToEnd(), vbCrLf)
    in this code:
    Code:
    Dim L*neasDeArchivo() as String
    fs = File.OpenRead(FilePath)
    sr = New StreamReader(fs)
    L*neasDeArchivo = Split(sr.ReadToEnd(), vbCrLf)
    fs.Close()
    takes too much time (63 seconds, because there are 2,000,000.0 lines to pass to L*neasDeArchivo() array).
    ¿somebody knows a faster way?
    _

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Help with optimization

    You could as well read one line at a time instead of reading the whole file. Imagine, what happens if the file is greater than 2 GB. I would never read the whole content of file unless I am 100% sure that the file is going to be small.

  3. #3
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Help with optimization

    Also if the lines are independant, you can process each one using a worker thread....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

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

Featured