<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Hilfe mein Code ist super lahm]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe gerade ein tool geschrieben das sich filminformationen runterlädt ( <a href="http://filmdb.de" rel="nofollow">filmdb.de</a> ) und diese ausgibt. Leider ist mein code super lahm geraten 20secs - über eine minute.</p>
<p>Bitte schaut doch mal drüber und gebt verbesserungsvorschläge insbesondere evtl eine bufferung anstatt der txt files die ich erzeuge.</p>
<p>Leider bin ich kein programmierguru, bitte schreibt ein kurzes codebeispriel zu euren vorschlägen</p>
<p>tia</p>
<p>und hier der code :</p>
<pre><code>#pragma comment(lib,&quot;ws2_32&quot;)
#pragma comment( lib, &quot;psapi.lib&quot; )

#include &lt;winsock2.h&gt;
#include &lt;Windows.h&gt;
#include &lt;Tlhelp32.h&gt;
#include &lt;stdio.h&gt;
#include &quot;psapi.h&quot;

void main(int argc, char *argv[]){
	if(argv[1]==NULL) return;

	//doppelstart checken

	HANDLE hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
	if (hSnapshot==NULL){
		return;
	}

	HANDLE hProcess;
	PROCESSENTRY32 pex;
	char szModName[MAX_PATH];
	char *test;
	short malzwei=0;

	pex.dwSize=sizeof(PROCESSENTRY32);

	BOOL retval=Process32First(hSnapshot,&amp;pex);
	while(retval){
		hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, pex.th32ProcessID );
        GetModuleFileNameEx( hProcess, NULL, szModName, sizeof(szModName));
		test=strstr(pex.szExeFile,&quot;filmdb&quot;);
		if(test!=NULL) malzwei++;
		if(malzwei==2) return; //falls doppelt gestartet exit
		pex.dwSize=sizeof(PROCESSENTRY32);
		retval=Process32Next(hSnapshot,&amp;pex);
	}

	CloseHandle(hSnapshot);

	remove(&quot;Ergebnis.txt&quot;);

    int sock;
    int G_Port = 0;
    struct sockaddr_in host_addr;
    struct hostent *hostinfo;
    char host[10]= &quot;filmdb.de&quot;;
    char command[1024];
    char buf[1024];
    int bytes_sent, bytes_recv, G_zaehl,G_filmid;
    FILE  * G_la;
	WSADATA wsaData;
	char *link,*G_buffer;
	long lSize;
	int G_hit=0;
	char linkX[200];
	int i;

	WSAStartup(MAKEWORD(2,2), &amp;wsaData);

	i=1;
	while(argv[i]!=NULL) i++;
	i--;

	switch(i){
		case 1:
			//sprintf (command, &quot;GET /globalsuche.php?name=%s HTTP/1.1\r\nHost: %s\r\n\r\n&quot;,argv[1], &quot;filmdb.de&quot;);
			sprintf(command, &quot;POST /globalsuche.php  HTTP/1.1\r\nHost: %s \r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %i\r\n\r\nname=%s&quot;,&quot;filmdb.de&quot;,5+strlen(argv[1]),argv[1]);
			break;
		case 2:
			//sprintf (command, &quot;GET /globalsuche.php?name=%s %s HTTP/1.1\r\nHost: %s\r\n\r\n&quot;,argv[1], argv[2], &quot;filmdb.de&quot;);
			sprintf(command, &quot;POST /globalsuche.php  HTTP/1.1\r\nHost: %s \r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %i\r\n\r\nname=%s %s&quot;,&quot;filmdb.de&quot;,5+strlen(argv[1])+strlen(argv[2])+1,argv[1], argv[2]);
			break;
		case 3:
			//sprintf (command, &quot;GET /globalsuche.php?name=%s %s %s HTTP/1.1\r\nHost: %s\r\n\r\n&quot;,argv[1], argv[2], argv[3], &quot;filmdb.de&quot;);
			sprintf(command, &quot;POST /globalsuche.php  HTTP/1.1\r\nHost: %s \r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %i\r\n\r\nname=%s %s %s&quot;,&quot;filmdb.de&quot;,5+strlen(argv[1])+strlen(argv[2])+2+strlen(argv[3]),argv[1], argv[2], argv[3]);
			break;
		case 4:
			//sprintf (command, &quot;GET /globalsuche.php?name=%s %s %s %s HTTP/1.1\r\nHost: %s\r\n\r\n&quot;,argv[1], argv[2], argv[3], argv[4], &quot;filmdb.de&quot;);
			sprintf(command, &quot;POST /globalsuche.php  HTTP/1.1\r\nHost: %s \r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %i\r\n\r\nname=%s %s %s %s&quot;,&quot;filmdb.de&quot;,5+strlen(argv[1])+strlen(argv[2])+3+strlen(argv[3])+strlen(argv[4]),argv[1], argv[2], argv[3], argv[4]);
			break;
		case 5:
			//sprintf (command, &quot;GET /globalsuche.php?name=%s %s %s %s %s HTTP/1.1\r\nHost: %s\r\n\r\n&quot;,argv[1], argv[2], argv[3], argv[4], argv[5], &quot;filmdb.de&quot;);
			sprintf(command, &quot;POST /globalsuche.php  HTTP/1.1\r\nHost: %s \r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %i\r\n\r\nname=%s %s %s %s %s&quot;,&quot;filmdb.de&quot;,5+strlen(argv[1])+strlen(argv[2])+4+strlen(argv[3])+strlen(argv[4])+strlen(argv[5]),argv[1], argv[2], argv[3], argv[4], argv[5]);
			break;
		case 6:
			sprintf(command, &quot;POST /globalsuche.php  HTTP/1.1\r\nHost: %s \r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %i\r\n\r\nname=%s %s %s %s %s %s&quot;,&quot;filmdb.de&quot;,5+strlen(argv[1])+strlen(argv[2])+5+strlen(argv[3])+strlen(argv[4])+strlen(argv[5])+strlen(argv[6]),argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]);
			break;
		default:
			return;
	}
	printf(command);
	i=0;

    // Socket erzeugen
    sock = WSASocket(AF_INET,SOCK_STREAM,0,NULL,NULL,NULL);
    if (sock == -1) {
        perror (&quot;socket()&quot;);
        exit (EXIT_FAILURE);
    }

    // Adresse des Servers festlegen
    memset( &amp;host_addr, 0, sizeof (host_addr));
    host_addr.sin_family = AF_INET;
    host_addr.sin_port = htons (80);;
	host_addr.sin_addr.s_addr = inet_addr (host);

    if (host_addr.sin_addr.s_addr == INADDR_NONE) {
        hostinfo = gethostbyname (host);
        if (hostinfo == NULL) {
            printf(&quot;gethostbyname()&quot;);
            return;
        }
        memcpy((char*) &amp;host_addr.sin_addr.s_addr, hostinfo-&gt;h_addr, hostinfo-&gt;h_length);
    }

    // Verbindung aufbauen
    if (connect(sock, (struct sockaddr *) &amp;host_addr, sizeof(struct sockaddr)) == -1) {
        printf(&quot;connect()&quot;);
        return;
    }

    // HTTP-GET-Befehl erzeugen
    //sprintf (command, &quot;GET /globalsuche.php?name=%s HTTP/1.1\r\nHost: %s\r\n\r\n&quot;,argv[1], &quot;filmdb.de&quot;);

    // Befehl senden
    bytes_sent = send (sock, command, strlen (command), 0);
    if (bytes_sent == -1) {
        printf(&quot;send()&quot;);
        return;
    }
    // Antwort des Servers empfangen und auswerten

	// wichtigen ausschnitt in ein file schreiben
    while ((bytes_recv = recv (sock, buf, sizeof(buf), 0)) &gt; 0) {
		link = strstr(buf,&quot;filmid&quot;);
		if(link!=NULL){
			G_la=fopen(&quot;OUT.2.txt&quot;,&quot;wb&quot;);
			fwrite(buf,1, bytes_recv,G_la);
			fclose(G_la);
			break;
		}
	}
    if (bytes_recv == -1) {
        printf( &quot;recv()&quot;);
        return;
    }
    G_la = fopen ( &quot;OUT.2.txt&quot; , &quot;rb&quot; );

    if (G_la == NULL){
		printf(&quot;Fehler: Keine Daten empfangen&quot;);
		return;
	}

    // Filegroesse ermitteln
    fseek (G_la , 0 , SEEK_END);
    lSize = ftell (G_la);
    rewind (G_la);

    // Speicher reservieren
    G_buffer = (char*) malloc (lSize);
    if (G_buffer == NULL) exit (2);

    // File in den Buffer laden
    fread (G_buffer,1,lSize,G_la);
	fclose(G_la);

    // schlüsselwort filmid wird gesucht ( evtl gibt es hier einen effizienteren algorithmus ? )
    G_zaehl = 0;
    G_filmid = 0;
    while(G_zaehl&lt;lSize){
    	if(!G_filmid){
     		switch (G_buffer[G_zaehl]){
        		case 102:
            		if(G_hit == 0) G_hit++;
					else if(G_hit != 6) G_hit = 0;
                	break;
           		case 105:
                	if(G_hit == 1 || G_hit == 4) G_hit++;
					else if(G_hit != 6) G_hit = 0;
                	break;
        		case 108:
            		if(G_hit == 2) G_hit++;
					else if(G_hit != 6) G_hit = 0;
                	break;
           		case 109:
                	if(G_hit == 3) G_hit++;
					else if(G_hit != 6) G_hit = 0;
                	break;
        		case 100:
            		if(G_hit == 5) G_hit++;
					else if(G_hit != 6) G_hit = 0;
                	break;
            	default:
                	if(G_hit != 6) G_hit = 0;
            }
            if(G_hit == 6){
            	G_filmid = 1;        //filmid gefunden
            }
        }
        else{    //link wird linkX übergeben
			i = 0;
			while(G_buffer[G_zaehl]!=62 &amp;&amp; G_zaehl&lt;(int)strlen(G_buffer)){
				linkX[i]=G_buffer[G_zaehl];
				i++;
				G_zaehl++;
			}
			linkX[i]=0;
			break;
        }
		G_zaehl++;

	}
	closesocket(sock);

//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
    // Socket erzeugen
    sock = WSASocket(AF_INET,SOCK_STREAM,0,NULL,NULL,NULL);
    if (sock == -1) {
        perror (&quot;socket()&quot;);
        exit (EXIT_FAILURE);
    }

    // Adresse des Servers festlegen
    memset( &amp;host_addr, 0, sizeof (host_addr));
    host_addr.sin_family = AF_INET;
    host_addr.sin_port = htons (80);;
	host_addr.sin_addr.s_addr = inet_addr (host);

    if (host_addr.sin_addr.s_addr == INADDR_NONE) {
        // Server wurde nicht mit IP sondern mit dem Namen angegeben
        hostinfo = gethostbyname (host);
        if (hostinfo == NULL) {
            printf(&quot;gethostbyname()&quot;);
            return;
        }
        memcpy((char*) &amp;host_addr.sin_addr.s_addr, hostinfo-&gt;h_addr, hostinfo-&gt;h_length);
    }

	//erneut verbinden
    if (connect(sock, (struct sockaddr *) &amp;host_addr, sizeof(struct sockaddr)) == -1) {
        printf(&quot;connect()&quot;);
        return;
    }

    // HTTP-GET-Befehl erzeugen
    sprintf (command, &quot;GET /filmanzeige.php?filmid%s HTTP/1.1\r\nHost: %s\r\n\r\n&quot;, linkX, &quot;filmdb.de&quot;);

    // Befehl senden
    bytes_sent = send (sock, command, strlen (command), 0);
    if (bytes_sent == -1) {
        printf(&quot;send()&quot;);
        return;
    }

    // Antwort des Servers empfangen und auswerten

	// erstmal alles in ein File schreiben
	G_la = fopen(&quot;OUT.film.txt&quot;,&quot;wb&quot;);
    while ((bytes_recv = recv (sock, buf, sizeof(buf), 0)) &gt; 0) {

		fwrite(buf, 1, bytes_recv, G_la);
	}
    if (bytes_recv == -1) {
        fclose(G_la);
        printf( &quot;recv()22&quot;);
        return;
    }
    fclose(G_la);
//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
	G_la=fopen(&quot;OUT.film.txt&quot;,&quot;r&quot;);

	char bf_destx[1000], titel[1000], desc[1000];
	char *link2;
	int z=0;
	int y=0;
	int chaosfaktor=0;
	short bubu=0;

	link2=strstr(bf_destx, &quot;Filmdatenbank&quot;);

	while(!feof(G_la)){
		fgets(bf_destx, 1000, G_la);
		if(link2==NULL){
			link2=strstr(bf_destx, &quot;Filmdatenbank&quot;);
			if(link2!=NULL){		//titel gefunden wird in variable titel geschrieben
				while(z&lt;(int)strlen(bf_destx)){
					switch(bf_destx[z]){
						case 9:
							y--;
							break;
						case 60:
							chaosfaktor=0;
							while(bf_destx[z] != 62 &amp;&amp; chaosfaktor&lt;25 ){ //entferne html tags
								z++;
								chaosfaktor++;
							}
							y--;
							break;
						default:
							titel[y]=bf_destx[z];
					}
					z++;
					y++;
				}
				titel[y-1]=0;
			}
		}
		else{
			link=strstr(bf_destx,&quot;Inhalt&quot;);	//inhalt gefunden wird in variable desc geschrieben
			if(link!=0){
				link = NULL;
				while(!feof(G_la)){
					fgets(bf_destx, 1000, G_la);
					link=strstr(bf_destx,&quot;cellspacing&quot;);	//erstes cellspacing nach inhalt zeigt den beginn des inhalts an
					if(link!=NULL){
						link = NULL;
						y=0;
						while(!feof(G_la)){
							fgets(bf_destx, 1000, G_la);
							link=strstr(bf_destx,&quot;cellspacing&quot;);
							if(link!=NULL){
								desc[y]=0;
								bubu=1;
								break;
							}
							z=0;
							while(z&lt;(int)strlen(bf_destx)){
								switch(bf_destx[z]){
									case 60:
										chaosfaktor=0;
										while(bf_destx[z] != 62 &amp;&amp; chaosfaktor&lt;25 ){	//entferne html tags
											z++;
											chaosfaktor++;
										}
										y--;
										break;
									default:
										desc[y]=bf_destx[z];
								}
								z++;
								y++;
								if(y % 400 == 0){
									desc[y]=13;
									y++;
									desc[y]=10;
									y++;
								}
							}
						}
					}
					if(bubu==1) break;
				}
			}
		}
	}
	char finaldesc[1000];
	int y1 = 0;
	int y2 = 0;
	//http variablen für umlaute werden durch umlaute ersetzt : ü=&quot;&amp;uuml;&quot; - Ü=&quot;&amp;Uuml; ...
	while(y2&lt;(int)strlen(desc)){
		switch (desc[y2]){
        	case 38:
				switch(desc[y2+1]){
					case 65:
						finaldesc[y1]=(char)142;
						break;
					case 97:
						finaldesc[y1]=(char)132;
						break;
					case 85:
						finaldesc[y1]=(char)154;
						break;
					case 117:
						finaldesc[y1]=(char)129;
						break;
					case 79:
						finaldesc[y1]=(char)153;
						break;
					case 111:
						finaldesc[y1]=(char)148;
						break;
					case 115:
						finaldesc[y1]=(char)225;
					default:
						finaldesc[y1]=(char)38;
						break;
				}
				y2=y2+5;
				break;
			case 9:			//tabulatoren werden entfernt
				y1--;
				break;
           	default:
               	finaldesc[y1]=desc[y2];
		}
		y1++;
		y2++;
	}
	fclose(G_la);
	finaldesc[y1]=0;
	printf(&quot;\r\n\r\n%s&quot;,finaldesc);
	G_la = fopen(&quot;Ergebnis.txt&quot;,&quot;wb&quot;);  //ausgabe in datei ergebnis.txt
	fputs(titel,G_la);
	fputc(13, G_la);
	fputc(10, G_la);
	fputs(&quot;&quot;,G_la);
	fputs(finaldesc,G_la);
	fclose(G_la);
	remove(&quot;OUT.film.txt&quot;);
	remove(&quot;OUT.2.txt&quot;);
    return;
}
</code></pre>
<p>Bin für jede kleine performance verbesserung dankbar und bitte nicht lachen wenn ich einige sachen zu umständlich programmiert habe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /></p>
<p>mfg c°h°</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/153516/hilfe-mein-code-ist-super-lahm</link><generator>RSS for Node</generator><lastBuildDate>Mon, 07 Sep 2026 14:06:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/153516.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 18 Jul 2006 07:18:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Hilfe mein Code ist super lahm on Tue, 18 Jul 2006 07:18:16 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe gerade ein tool geschrieben das sich filminformationen runterlädt ( <a href="http://filmdb.de" rel="nofollow">filmdb.de</a> ) und diese ausgibt. Leider ist mein code super lahm geraten 20secs - über eine minute.</p>
<p>Bitte schaut doch mal drüber und gebt verbesserungsvorschläge insbesondere evtl eine bufferung anstatt der txt files die ich erzeuge.</p>
<p>Leider bin ich kein programmierguru, bitte schreibt ein kurzes codebeispriel zu euren vorschlägen</p>
<p>tia</p>
<p>und hier der code :</p>
<pre><code>#pragma comment(lib,&quot;ws2_32&quot;)
#pragma comment( lib, &quot;psapi.lib&quot; )

#include &lt;winsock2.h&gt;
#include &lt;Windows.h&gt;
#include &lt;Tlhelp32.h&gt;
#include &lt;stdio.h&gt;
#include &quot;psapi.h&quot;

void main(int argc, char *argv[]){
	if(argv[1]==NULL) return;

	//doppelstart checken

	HANDLE hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
	if (hSnapshot==NULL){
		return;
	}

	HANDLE hProcess;
	PROCESSENTRY32 pex;
	char szModName[MAX_PATH];
	char *test;
	short malzwei=0;

	pex.dwSize=sizeof(PROCESSENTRY32);

	BOOL retval=Process32First(hSnapshot,&amp;pex);
	while(retval){
		hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, pex.th32ProcessID );
        GetModuleFileNameEx( hProcess, NULL, szModName, sizeof(szModName));
		test=strstr(pex.szExeFile,&quot;filmdb&quot;);
		if(test!=NULL) malzwei++;
		if(malzwei==2) return; //falls doppelt gestartet exit
		pex.dwSize=sizeof(PROCESSENTRY32);
		retval=Process32Next(hSnapshot,&amp;pex);
	}

	CloseHandle(hSnapshot);

	remove(&quot;Ergebnis.txt&quot;);

    int sock;
    int G_Port = 0;
    struct sockaddr_in host_addr;
    struct hostent *hostinfo;
    char host[10]= &quot;filmdb.de&quot;;
    char command[1024];
    char buf[1024];
    int bytes_sent, bytes_recv, G_zaehl,G_filmid;
    FILE  * G_la;
	WSADATA wsaData;
	char *link,*G_buffer;
	long lSize;
	int G_hit=0;
	char linkX[200];
	int i;

	WSAStartup(MAKEWORD(2,2), &amp;wsaData);

	i=1;
	while(argv[i]!=NULL) i++;
	i--;

	switch(i){
		case 1:
			//sprintf (command, &quot;GET /globalsuche.php?name=%s HTTP/1.1\r\nHost: %s\r\n\r\n&quot;,argv[1], &quot;filmdb.de&quot;);
			sprintf(command, &quot;POST /globalsuche.php  HTTP/1.1\r\nHost: %s \r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %i\r\n\r\nname=%s&quot;,&quot;filmdb.de&quot;,5+strlen(argv[1]),argv[1]);
			break;
		case 2:
			//sprintf (command, &quot;GET /globalsuche.php?name=%s %s HTTP/1.1\r\nHost: %s\r\n\r\n&quot;,argv[1], argv[2], &quot;filmdb.de&quot;);
			sprintf(command, &quot;POST /globalsuche.php  HTTP/1.1\r\nHost: %s \r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %i\r\n\r\nname=%s %s&quot;,&quot;filmdb.de&quot;,5+strlen(argv[1])+strlen(argv[2])+1,argv[1], argv[2]);
			break;
		case 3:
			//sprintf (command, &quot;GET /globalsuche.php?name=%s %s %s HTTP/1.1\r\nHost: %s\r\n\r\n&quot;,argv[1], argv[2], argv[3], &quot;filmdb.de&quot;);
			sprintf(command, &quot;POST /globalsuche.php  HTTP/1.1\r\nHost: %s \r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %i\r\n\r\nname=%s %s %s&quot;,&quot;filmdb.de&quot;,5+strlen(argv[1])+strlen(argv[2])+2+strlen(argv[3]),argv[1], argv[2], argv[3]);
			break;
		case 4:
			//sprintf (command, &quot;GET /globalsuche.php?name=%s %s %s %s HTTP/1.1\r\nHost: %s\r\n\r\n&quot;,argv[1], argv[2], argv[3], argv[4], &quot;filmdb.de&quot;);
			sprintf(command, &quot;POST /globalsuche.php  HTTP/1.1\r\nHost: %s \r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %i\r\n\r\nname=%s %s %s %s&quot;,&quot;filmdb.de&quot;,5+strlen(argv[1])+strlen(argv[2])+3+strlen(argv[3])+strlen(argv[4]),argv[1], argv[2], argv[3], argv[4]);
			break;
		case 5:
			//sprintf (command, &quot;GET /globalsuche.php?name=%s %s %s %s %s HTTP/1.1\r\nHost: %s\r\n\r\n&quot;,argv[1], argv[2], argv[3], argv[4], argv[5], &quot;filmdb.de&quot;);
			sprintf(command, &quot;POST /globalsuche.php  HTTP/1.1\r\nHost: %s \r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %i\r\n\r\nname=%s %s %s %s %s&quot;,&quot;filmdb.de&quot;,5+strlen(argv[1])+strlen(argv[2])+4+strlen(argv[3])+strlen(argv[4])+strlen(argv[5]),argv[1], argv[2], argv[3], argv[4], argv[5]);
			break;
		case 6:
			sprintf(command, &quot;POST /globalsuche.php  HTTP/1.1\r\nHost: %s \r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %i\r\n\r\nname=%s %s %s %s %s %s&quot;,&quot;filmdb.de&quot;,5+strlen(argv[1])+strlen(argv[2])+5+strlen(argv[3])+strlen(argv[4])+strlen(argv[5])+strlen(argv[6]),argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]);
			break;
		default:
			return;
	}
	printf(command);
	i=0;

    // Socket erzeugen
    sock = WSASocket(AF_INET,SOCK_STREAM,0,NULL,NULL,NULL);
    if (sock == -1) {
        perror (&quot;socket()&quot;);
        exit (EXIT_FAILURE);
    }

    // Adresse des Servers festlegen
    memset( &amp;host_addr, 0, sizeof (host_addr));
    host_addr.sin_family = AF_INET;
    host_addr.sin_port = htons (80);;
	host_addr.sin_addr.s_addr = inet_addr (host);

    if (host_addr.sin_addr.s_addr == INADDR_NONE) {
        hostinfo = gethostbyname (host);
        if (hostinfo == NULL) {
            printf(&quot;gethostbyname()&quot;);
            return;
        }
        memcpy((char*) &amp;host_addr.sin_addr.s_addr, hostinfo-&gt;h_addr, hostinfo-&gt;h_length);
    }

    // Verbindung aufbauen
    if (connect(sock, (struct sockaddr *) &amp;host_addr, sizeof(struct sockaddr)) == -1) {
        printf(&quot;connect()&quot;);
        return;
    }

    // HTTP-GET-Befehl erzeugen
    //sprintf (command, &quot;GET /globalsuche.php?name=%s HTTP/1.1\r\nHost: %s\r\n\r\n&quot;,argv[1], &quot;filmdb.de&quot;);

    // Befehl senden
    bytes_sent = send (sock, command, strlen (command), 0);
    if (bytes_sent == -1) {
        printf(&quot;send()&quot;);
        return;
    }
    // Antwort des Servers empfangen und auswerten

	// wichtigen ausschnitt in ein file schreiben
    while ((bytes_recv = recv (sock, buf, sizeof(buf), 0)) &gt; 0) {
		link = strstr(buf,&quot;filmid&quot;);
		if(link!=NULL){
			G_la=fopen(&quot;OUT.2.txt&quot;,&quot;wb&quot;);
			fwrite(buf,1, bytes_recv,G_la);
			fclose(G_la);
			break;
		}
	}
    if (bytes_recv == -1) {
        printf( &quot;recv()&quot;);
        return;
    }
    G_la = fopen ( &quot;OUT.2.txt&quot; , &quot;rb&quot; );

    if (G_la == NULL){
		printf(&quot;Fehler: Keine Daten empfangen&quot;);
		return;
	}

    // Filegroesse ermitteln
    fseek (G_la , 0 , SEEK_END);
    lSize = ftell (G_la);
    rewind (G_la);

    // Speicher reservieren
    G_buffer = (char*) malloc (lSize);
    if (G_buffer == NULL) exit (2);

    // File in den Buffer laden
    fread (G_buffer,1,lSize,G_la);
	fclose(G_la);

    // schlüsselwort filmid wird gesucht ( evtl gibt es hier einen effizienteren algorithmus ? )
    G_zaehl = 0;
    G_filmid = 0;
    while(G_zaehl&lt;lSize){
    	if(!G_filmid){
     		switch (G_buffer[G_zaehl]){
        		case 102:
            		if(G_hit == 0) G_hit++;
					else if(G_hit != 6) G_hit = 0;
                	break;
           		case 105:
                	if(G_hit == 1 || G_hit == 4) G_hit++;
					else if(G_hit != 6) G_hit = 0;
                	break;
        		case 108:
            		if(G_hit == 2) G_hit++;
					else if(G_hit != 6) G_hit = 0;
                	break;
           		case 109:
                	if(G_hit == 3) G_hit++;
					else if(G_hit != 6) G_hit = 0;
                	break;
        		case 100:
            		if(G_hit == 5) G_hit++;
					else if(G_hit != 6) G_hit = 0;
                	break;
            	default:
                	if(G_hit != 6) G_hit = 0;
            }
            if(G_hit == 6){
            	G_filmid = 1;        //filmid gefunden
            }
        }
        else{    //link wird linkX übergeben
			i = 0;
			while(G_buffer[G_zaehl]!=62 &amp;&amp; G_zaehl&lt;(int)strlen(G_buffer)){
				linkX[i]=G_buffer[G_zaehl];
				i++;
				G_zaehl++;
			}
			linkX[i]=0;
			break;
        }
		G_zaehl++;

	}
	closesocket(sock);

//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
    // Socket erzeugen
    sock = WSASocket(AF_INET,SOCK_STREAM,0,NULL,NULL,NULL);
    if (sock == -1) {
        perror (&quot;socket()&quot;);
        exit (EXIT_FAILURE);
    }

    // Adresse des Servers festlegen
    memset( &amp;host_addr, 0, sizeof (host_addr));
    host_addr.sin_family = AF_INET;
    host_addr.sin_port = htons (80);;
	host_addr.sin_addr.s_addr = inet_addr (host);

    if (host_addr.sin_addr.s_addr == INADDR_NONE) {
        // Server wurde nicht mit IP sondern mit dem Namen angegeben
        hostinfo = gethostbyname (host);
        if (hostinfo == NULL) {
            printf(&quot;gethostbyname()&quot;);
            return;
        }
        memcpy((char*) &amp;host_addr.sin_addr.s_addr, hostinfo-&gt;h_addr, hostinfo-&gt;h_length);
    }

	//erneut verbinden
    if (connect(sock, (struct sockaddr *) &amp;host_addr, sizeof(struct sockaddr)) == -1) {
        printf(&quot;connect()&quot;);
        return;
    }

    // HTTP-GET-Befehl erzeugen
    sprintf (command, &quot;GET /filmanzeige.php?filmid%s HTTP/1.1\r\nHost: %s\r\n\r\n&quot;, linkX, &quot;filmdb.de&quot;);

    // Befehl senden
    bytes_sent = send (sock, command, strlen (command), 0);
    if (bytes_sent == -1) {
        printf(&quot;send()&quot;);
        return;
    }

    // Antwort des Servers empfangen und auswerten

	// erstmal alles in ein File schreiben
	G_la = fopen(&quot;OUT.film.txt&quot;,&quot;wb&quot;);
    while ((bytes_recv = recv (sock, buf, sizeof(buf), 0)) &gt; 0) {

		fwrite(buf, 1, bytes_recv, G_la);
	}
    if (bytes_recv == -1) {
        fclose(G_la);
        printf( &quot;recv()22&quot;);
        return;
    }
    fclose(G_la);
//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
	G_la=fopen(&quot;OUT.film.txt&quot;,&quot;r&quot;);

	char bf_destx[1000], titel[1000], desc[1000];
	char *link2;
	int z=0;
	int y=0;
	int chaosfaktor=0;
	short bubu=0;

	link2=strstr(bf_destx, &quot;Filmdatenbank&quot;);

	while(!feof(G_la)){
		fgets(bf_destx, 1000, G_la);
		if(link2==NULL){
			link2=strstr(bf_destx, &quot;Filmdatenbank&quot;);
			if(link2!=NULL){		//titel gefunden wird in variable titel geschrieben
				while(z&lt;(int)strlen(bf_destx)){
					switch(bf_destx[z]){
						case 9:
							y--;
							break;
						case 60:
							chaosfaktor=0;
							while(bf_destx[z] != 62 &amp;&amp; chaosfaktor&lt;25 ){ //entferne html tags
								z++;
								chaosfaktor++;
							}
							y--;
							break;
						default:
							titel[y]=bf_destx[z];
					}
					z++;
					y++;
				}
				titel[y-1]=0;
			}
		}
		else{
			link=strstr(bf_destx,&quot;Inhalt&quot;);	//inhalt gefunden wird in variable desc geschrieben
			if(link!=0){
				link = NULL;
				while(!feof(G_la)){
					fgets(bf_destx, 1000, G_la);
					link=strstr(bf_destx,&quot;cellspacing&quot;);	//erstes cellspacing nach inhalt zeigt den beginn des inhalts an
					if(link!=NULL){
						link = NULL;
						y=0;
						while(!feof(G_la)){
							fgets(bf_destx, 1000, G_la);
							link=strstr(bf_destx,&quot;cellspacing&quot;);
							if(link!=NULL){
								desc[y]=0;
								bubu=1;
								break;
							}
							z=0;
							while(z&lt;(int)strlen(bf_destx)){
								switch(bf_destx[z]){
									case 60:
										chaosfaktor=0;
										while(bf_destx[z] != 62 &amp;&amp; chaosfaktor&lt;25 ){	//entferne html tags
											z++;
											chaosfaktor++;
										}
										y--;
										break;
									default:
										desc[y]=bf_destx[z];
								}
								z++;
								y++;
								if(y % 400 == 0){
									desc[y]=13;
									y++;
									desc[y]=10;
									y++;
								}
							}
						}
					}
					if(bubu==1) break;
				}
			}
		}
	}
	char finaldesc[1000];
	int y1 = 0;
	int y2 = 0;
	//http variablen für umlaute werden durch umlaute ersetzt : ü=&quot;&amp;uuml;&quot; - Ü=&quot;&amp;Uuml; ...
	while(y2&lt;(int)strlen(desc)){
		switch (desc[y2]){
        	case 38:
				switch(desc[y2+1]){
					case 65:
						finaldesc[y1]=(char)142;
						break;
					case 97:
						finaldesc[y1]=(char)132;
						break;
					case 85:
						finaldesc[y1]=(char)154;
						break;
					case 117:
						finaldesc[y1]=(char)129;
						break;
					case 79:
						finaldesc[y1]=(char)153;
						break;
					case 111:
						finaldesc[y1]=(char)148;
						break;
					case 115:
						finaldesc[y1]=(char)225;
					default:
						finaldesc[y1]=(char)38;
						break;
				}
				y2=y2+5;
				break;
			case 9:			//tabulatoren werden entfernt
				y1--;
				break;
           	default:
               	finaldesc[y1]=desc[y2];
		}
		y1++;
		y2++;
	}
	fclose(G_la);
	finaldesc[y1]=0;
	printf(&quot;\r\n\r\n%s&quot;,finaldesc);
	G_la = fopen(&quot;Ergebnis.txt&quot;,&quot;wb&quot;);  //ausgabe in datei ergebnis.txt
	fputs(titel,G_la);
	fputc(13, G_la);
	fputc(10, G_la);
	fputs(&quot;&quot;,G_la);
	fputs(finaldesc,G_la);
	fclose(G_la);
	remove(&quot;OUT.film.txt&quot;);
	remove(&quot;OUT.2.txt&quot;);
    return;
}
</code></pre>
<p>Bin für jede kleine performance verbesserung dankbar und bitte nicht lachen wenn ich einige sachen zu umständlich programmiert habe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /></p>
<p>mfg c°h°</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1099537</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1099537</guid><dc:creator><![CDATA[c°h°]]></dc:creator><pubDate>Tue, 18 Jul 2006 07:18:16 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe mein Code ist super lahm on Tue, 18 Jul 2006 07:26:54 GMT]]></title><description><![CDATA[<p>Wow. Keine einzige Funktion? Respekt, dass du da noch durchblickst ;).</p>
<p>Ich würd das ganze erstmal neu strukturieren. Und dann einfach mal die Ausführungszeit der einzelnen Funktionen messen. So kannst du schnell feststellen, wos hackt. Und falls du dann nicht von alleine draufkommst, kannst du den Abschnitt posten, an dems hängt. Weil ich für meinen Teil hab keine Lust den Code einzeln durchzuschauen, um irgendwelche Performance-Bremsen zu finden. Zumal ich hier im Geschäft nicht die Möglichkeit habe den Code zu compilieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1099544</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1099544</guid><dc:creator><![CDATA[cin]]></dc:creator><pubDate>Tue, 18 Jul 2006 07:26:54 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe mein Code ist super lahm on Tue, 18 Jul 2006 07:39:46 GMT]]></title><description><![CDATA[<p>danke schonmal<br />
könntest du mir noch einen tip geben wie ich zeiten messe?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1099554</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1099554</guid><dc:creator><![CDATA[c°h°]]></dc:creator><pubDate>Tue, 18 Jul 2006 07:39:46 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe mein Code ist super lahm on Tue, 18 Jul 2006 07:44:26 GMT]]></title><description><![CDATA[<p>zb: boost timer<br />
<a href="http://www.boost.org/libs/timer/timer.htm" rel="nofollow">http://www.boost.org/libs/timer/timer.htm</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1099556</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1099556</guid><dc:creator><![CDATA[miller_m]]></dc:creator><pubDate>Tue, 18 Jul 2006 07:44:26 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe mein Code ist super lahm on Tue, 18 Jul 2006 07:45:04 GMT]]></title><description><![CDATA[<p>&lt;windows.h&gt; includen und dann mit GetTickCount().</p>
<p>Das gibt dir die seit dem Rechnerstart vergangenen Millisekunden.</p>
<pre><code class="language-cpp">int start = GetTickCount();

zu_messende_funktion();

int ende = GetTickCount();

int zeit_die_benoetigt_wurde = ende - start;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1099557</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1099557</guid><dc:creator><![CDATA[DarthZiu]]></dc:creator><pubDate>Tue, 18 Jul 2006 07:45:04 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe mein Code ist super lahm on Tue, 18 Jul 2006 08:57:50 GMT]]></title><description><![CDATA[<p>Also dieser Codeteil braucht über 18000 tics. ich vermute mal das sind dann 18 sekunden? ein 2. codeteil ist ähnlich aufgebaut und braucht auch fast so lange.</p>
<pre><code>start=GetTickCount();

    // Socket erzeugen
    sock = WSASocket(AF_INET,SOCK_STREAM,0,NULL,NULL,NULL);
    if (sock == -1) {
        perror (&quot;socket()&quot;);
        exit (EXIT_FAILURE);
    }

    // Adresse des Servers festlegen
    memset( &amp;host_addr, 0, sizeof (host_addr));
    host_addr.sin_family = AF_INET;
    host_addr.sin_port = htons (80);;
	host_addr.sin_addr.s_addr = inet_addr (host);

    if (host_addr.sin_addr.s_addr == INADDR_NONE) {
        // Server wurde nicht mit IP sondern mit dem Namen angegeben
        hostinfo = gethostbyname (host);
        if (hostinfo == NULL) {
            printf(&quot;gethostbyname()&quot;);
            return;
        }
        memcpy((char*) &amp;host_addr.sin_addr.s_addr, hostinfo-&gt;h_addr, hostinfo-&gt;h_length);
    }

	//erneut verbinden
    if (connect(sock, (struct sockaddr *) &amp;host_addr, sizeof(struct sockaddr)) == -1) {
        printf(&quot;connect()&quot;);
        return;
    }

    // HTTP-GET-Befehl erzeugen
    sprintf (command, &quot;GET /filmanzeige.php?filmid%s HTTP/1.1\r\nHost: %s\r\n\r\n&quot;, linkX, &quot;filmdb.de&quot;);

    // Befehl senden
    bytes_sent = send (sock, command, strlen (command), 0);
    if (bytes_sent == -1) {
        printf(&quot;send()&quot;);
        return;
    }

    // Antwort des Servers empfangen und auswerten

	// erstmal alles in ein File schreiben
	G_la = fopen(&quot;OUT.film.txt&quot;,&quot;wb&quot;);
    while ((bytes_recv = recv (sock, buf, sizeof(buf), 0)) &gt; 0) {

		fwrite(buf, 1, bytes_recv, G_la);
	}
    if (bytes_recv == -1) {
        fclose(G_la);
        printf( &quot;recv()22&quot;);
        return;
    }
    fclose(G_la);

	ende = GetTickCount();

	printf(&quot;time4 = %i\n&quot;,ende-start);
</code></pre>
<p>mfg und danke für eure hilfe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1099610</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1099610</guid><dc:creator><![CDATA[c°h°]]></dc:creator><pubDate>Tue, 18 Jul 2006 08:57:50 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe mein Code ist super lahm on Tue, 18 Jul 2006 10:19:25 GMT]]></title><description><![CDATA[<p>Mmh. Also im Code ist IMHO nichts, was irgendwie bremsen könnte. Daher tippe ich, dass die Serverantwort so lange dauert.</p>
<p>Um das weiter zu analysieren rate ich dir in der while-Schleife, welche die Serverantwort in die Datei speichert, einfach mal alles auf der Konsole auszugeben was reinkommt. Dann siehst du ja, ob es daran vielleicht hängt.</p>
<p>Und dazu die Zeitmessung nur um die while-Schleife legen. Und dann poste mal die Ergebnisse.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1099664</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1099664</guid><dc:creator><![CDATA[DarthZiu]]></dc:creator><pubDate>Tue, 18 Jul 2006 10:19:25 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe mein Code ist super lahm on Tue, 18 Jul 2006 10:57:49 GMT]]></title><description><![CDATA[<p>hast recht es is nur diese while schleife. Könnte die performance verbessert werden wenn man anstatt in ein file in einen buffer schreibt ?</p>
<p>Ich glaube fast das liegt an meinem router ist allerdings seltsam das wenn ich die seite manuell ansurfe das ganze um einiges schneller geht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1099701</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1099701</guid><dc:creator><![CDATA[c°h°]]></dc:creator><pubDate>Tue, 18 Jul 2006 10:57:49 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe mein Code ist super lahm on Tue, 18 Jul 2006 11:00:47 GMT]]></title><description><![CDATA[<p>c°h° schrieb:</p>
<blockquote>
<p>Könnte die performance verbessert werden wenn man anstatt in ein file in einen buffer schreibt ?</p>
</blockquote>
<p>Definitiv nicht <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> Bei diesen Datenmengen (werden ja wohl nicht mehr als ein paar KB sein) merkst du die Plattenzugriffe gar nicht. Das spielt sich im Millisekundenbereich ab.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1099704</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1099704</guid><dc:creator><![CDATA[DarthZiu]]></dc:creator><pubDate>Tue, 18 Jul 2006 11:00:47 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe mein Code ist super lahm on Tue, 18 Jul 2006 11:00:52 GMT]]></title><description><![CDATA[<p>Ich vermute, dass der letzte recv-Aufruf, nachdem alles übertragen wurde, so lange dauert. Der wartet wohl darauf, dass die Gegenstelle die Verbindung schließt.</p>
<p>Ich kenne das HTT-Protokoll nicht auswendig, aber sollte es nicht möglich sein, aus dem Header der Antwort zu entnehmen, wie viele Bytes du genau empfangen musst? Dann müsstest du darauf nicht warten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1099705</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1099705</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Tue, 18 Jul 2006 11:00:52 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe mein Code ist super lahm on Tue, 18 Jul 2006 12:46:56 GMT]]></title><description><![CDATA[<p>Das ist der Header</p>
<pre><code>HTTP/1.1 200 OK
Date: Mon, 17 Jul 2006 22:41:06 GMT
Server: Apache/1.3.31 (Unix) PHP/4.3.8
X-Powered-By: PHP/4.3.8
Transfer-Encoding: chunked
Content-Type: text/html
</code></pre>
<p>leider lässt sich da nichts rauslesen.</p>
<p>trotzdem Danke für die Idee <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1099787</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1099787</guid><dc:creator><![CDATA[c°h°]]></dc:creator><pubDate>Tue, 18 Jul 2006 12:46:56 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe mein Code ist super lahm on Tue, 18 Jul 2006 12:52:13 GMT]]></title><description><![CDATA[<p>c°h° schrieb:</p>
<blockquote>
<p>Transfer-Encoding: chunked<br />
...<br />
leider lässt sich da nichts rauslesen.</p>
</blockquote>
<p>Äh, rfc2616 3.6.1 beschreibt doch, wie das bei chunked ist...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1099792</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1099792</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Tue, 18 Jul 2006 12:52:13 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe mein Code ist super lahm on Tue, 18 Jul 2006 13:03:13 GMT]]></title><description><![CDATA[<p>ich würd die WinInet API benutzen. Das selbst zu implementieren ist ein bisschen aufwendig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1099801</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1099801</guid><dc:creator><![CDATA[wininet]]></dc:creator><pubDate>Tue, 18 Jul 2006 13:03:13 GMT</pubDate></item></channel></rss>