real time stock quotes, StreamReader performance optimization

Posted by sean717 on Stack Overflow See other posts from Stack Overflow or by sean717
Published on 2010-04-15T17:16:42Z Indexed on 2010/04/15 17:33 UTC
Read the original article Hit count: 269

Filed under:

I am working on a program that extracts real time quote for 900+ stocks from a website. I use HttpWebRequest to send HTTP request to the site and store the response to a stream and open a stream using the following code:

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream ();
StreamReader reader = new  StreamReader( stream )

the size of the received HTML is large (5000+ lines), so it takes a long time to parse it and extract the price. For 900 files, It takes about 6 mins for parsing and extracting. Which my boss isn't happy with, he told me he'd want the whole process to be done in TWO mins.

I've identified the part of the program that takes most of time to finish is parsing and extracting. I've tried to optimize the code to make it faster, the following is what I have now after some optimization:

// skip lines at the top
for(int i=0;i<1500;++i) 
  reader.ReadLine();

// read the line that contains the price 
string theLine = reader.ReadLine();  

// ... extract the price from the line

now it takes about 4 mins to process all the files, there is still a significant gap to what my boss's expecting. So I am wondering, is there other way that I can further speed up the parsing and extracting and have everything done within 2 mins?

© Stack Overflow or respective owner

Related posts about c#