CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2006
    Posts
    180

    Improving speed and performance

    Hello! I have a code that is searches a search engine like google, and then gets the results by getting the page source, and adds it to the list. But it seems to be pretty slow. I'm thinking about putting it on a separate thread to improve my program's performance. But for speed, it takes about 20-30 seconds, which is pretty slow... Anyways here is my code.

    'Sending' is the CString that has the send data, that I'm about to send. Got is a array of char that collects the info, and finally collect a CString which the whole page source is collected.
    Code:
    hp=gethostbyname("www.thottbot.com");
    	server.sin_family= AF_INET;
    	server.sin_port=htons(80);
    	server.sin_addr.s_addr=*(unsigned long*)hp->h_addr;
    	if(connect(sClient, (struct sockaddr *)&server,sizeof(server)) ==SOCKET_ERROR)
    	{MessageBox("connect");
    		return;
    	}
    	
    			send(sClient,sending,strlen(sending),0);
    int cbRecvd=0;
    while(cbRecvd=recv(sClient,got,39999,0))
    {if(cbRecvd<0)
    	{
    		break;
    	}
    	got[cbRecvd] = '\0';
    	collect+=got;
    	
    UpdateData(FALSE);
    }
    Any suggestions to make this code faster?

    Thanks!

  2. #2
    Join Date
    Feb 2002
    Posts
    5,757

    Re: Improving speed and performance

    set socket i/o buffer size to, say, 1024. now see if recv() returns almost immediately after the 1024 byte buffer is filled.

    Kuphryn

  3. #3
    Join Date
    Sep 2006
    Posts
    180

    Re: Improving speed and performance

    Thanks for the reply. But I know the source will return more than 1,204 value. It was about 20,000 something when I checked it. But will lowering the value got by one loop effect performance/speed? Like this.
    Code:
    while(cbRecvd=recv(sClient,got,1024,0))
    {if(cbRecvd<0)
    	{
    		break;
    	}
    	got[cbRecvd] = '\0';
    	collect+=got;
    	
    
    }
    Any more ideas?

  4. #4
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: Improving speed and performance

    Quote Originally Posted by cenk01
    Any suggestions to make this code faster?
    Your code is fast enough. It's the server that's causing the delays.

    As a test, open the site in a browser like IE. Make sure that you go to the exact same URL as in "Sending". Does it open any faster in the browser than in your program? If not, then the fault is a delay on the part of the server, over which you have zero control, and can not do anything to improve speed.

    Mike

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