※ 引述《garylee.bbs@bbs.yzu.edu.tw (www.dev.idv.tw)》之銘言:
> 1. 先把while中有關GUI的code全部拿掉。要顯示進度的話,不用每筆都更新吧。
> 一千筆更新一次就行了。我測試過了把progressbar從0跑到610000要花好幾分鐘。
修改過後速度沒變
> 2. while loop中的code越精簡越好。
已經盡量精簡了
> 3. if (atoi(&NC.....) 這裡有bug。你的程式沒crash掉已經是運氣好了。
> 如果只是要判斷一個字元是不是"0",何不寫成下面這樣呢?
> if (tmpStr[0] == '0' && tmpStr[1] == '0')
會crash的理由是??
要判斷兩各字元是否都是數字 因為第一各可能是英文字母或是其他特殊字元
如果第二各式數字則 本行一樣要視為資料寫入struct中
> 4. 那個參數有SrcData[i].Caller與SrcData[i].Callee的strcpy是在幹嘛?
> 感覺有點多餘。
是有點多於 但就是為了怕第一各字元不是數字但第二各是
> 5. 另外,SrcData也許可以在外面用memset一類的function將他全部清成0吧。這樣
> 在迴圈內就不用為每個element設定初值了。
拿掉了
> 6. 你應該沒有在while loop中做任何配置記憶體的行為吧?千萬別這樣做喔。
沒有
上述六項都改了 但仍然速度奇慢無比
另外一各讀cdr的就不會這麼慢 兩千筆只要2秒內...
一樣讀到stringlist中 且用ansistring的func處理
所以不能理解為何兩各速度相異度這麼大.....
ꨊ> ※ 引述《streitleak.bbs@aeug.twbbs.org (亞斯爾‧馮‧修特萊)》之銘言:
> > clock_t start=0,end=0;
> > switch(WhichOne)
> > { case 1:
> > try
> > {
> > if(( fp=fopen(ITP_Main->OtherFILE.c_str(),"r"))== NULL ) return false;
> > while( !feof(fp) )
> > { start=clock();
> > ITP_Main->Label212->Caption=AnsiString(start);
> > SrcData[i].CallerID[0]='\0';
> > SrcData[i].CalleeID[0]='\0';
> > SrcData[i].StartTime=0;
> > SrcData[i].EndTime=0;
> > SrcData[i].Next = NULL;
> > fgets(tmpStr,500,fp);
> > strncpy(&NC,tmpStr,1);
> > strncpy(&NC2,tmpStr+1,1);
> > if( atoi(&NC)== 0 && atoi(&NC2)==0 )
> > { continue;
> > }
> > /* for( int j=0;j<strlen(tmpStr);j++ )
> > { if( tmpStr[j]=='\t' ) tmpStr[j]=' ';
> > }*/
> > sscanf(tmpStr,"%20s %20s %30s %20s %20s %07s",tmpCaller,tmpCallee,tmp,sttime,entime,tmp2);
> > strcpy(SrcData[i].CallerID, tmpCaller);
> > strcpy(SrcData[i].CalleeID, tmpCallee+1);
> > sscanf(sttime,"%04d%02d%02d-%02d%02d%02d", &tmptm.tm_year, &tmptm.tm_mon, &tmptm.tm_mday, &tmptm.tm_hour, &tmptm.tm_min, &tmptm.tm_sec);
> > sscanf(entime,"%04d%02d%02d-%02d%02d%02d", &tmptm2.tm_year, &tmptm2.tm_mon, &tmptm2.tm_mday, &tmptm2.tm_hour, &tmptm2.tm_min, &tmptm2.tm_sec);
> > SrcData[i].StartTime=mktime(&tmptm);
> > SrcData[i].EndTime=mktime(&tmptm2);
> > SrcData[i].Seconds = atoi(tmp2);
> > ITP_Main->ProgressBar1->Position++;
> > ITP_Main->StatusBar1->Panels->Items[3]->Text = AnsiString(i);
> > // Sleep(10);
> > if( i<ITP_Main->OtherCDR->Lines->Count ) i++;
> > end=clock();
> > ITP_Main->Label213->Caption=AnsiString(end);
> > ITP_Main->Label214->Caption=AnsiString(start-end);
> > };
> > fclose(fp);
> > }
> > catch(...)
> > { ShowMessage("Link List Error!");
> > fclose(fp);
> > return false;
> > }
--
◤◥ Origin: 幽谷˙反地球聯邦組織 aeug.twbbs.org
◣◢ Author: streit 從 61-228-81-251.dynamic.hinet.net 發表