精華區beta Programming 關於我們 聯絡資訊
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') 4. 那個參數有SrcData[i].Caller與SrcData[i].Callee的strcpy是在幹嘛? 感覺有點多餘。 5. 另外,SrcData也許可以在外面用memset一類的function將他全部清成0吧。這樣 在迴圈內就不用為每個element設定初值了。 6. 你應該沒有在while loop中做任何配置記憶體的行為吧?千萬別這樣做喔。 ※ 引述《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; > } -- Gary W. Lee URL: http://www.dev.idv.tw/ A web site about C/C++, Tcl, Python, wxWidgets, UNIX/Linux, Windows ..., etc. -- ※ Origin: 元智大學 風之塔 <bbs.yzu.edu.tw> ※ From : 59-112-232-40.dynamic.hinet.net ※ X-Info: Re: 檔案分析問題 如何提升資料解析速度 ※ X-Sign: 11SEUTQciIzTRa5FRmsw (06/01/13 18:06:50 )
MassHouse:好奇他是如何大學畢業並找到工作的或者只是個光華工程師 01/13 18:45
drkkimo:2 01/13 19:39
yoco315:如果字串拷貝跟函數呼叫不用成本,那他的程式應該蠻快的 01/14 14:34