arnico Posted March 15, 2005 Report Share Posted March 15, 2005 nu ja runa iet par vienu divaam mazaam tabulaam, tad piekriitu ka deriigs ir pilnigii jebkursh variants. un par optimizaaciju uz shii pamata vispaar nav jeegas runaat. man vienkaarshi biezhaak sanaak straadaat ar lielaam un daudz tabulaam ar kuraam vajag veikt daudz darbiibu, liidz ar to sho masiivu izmeers ir svariigs. Link to comment Share on other sites More sharing options...
Venom Posted March 15, 2005 Report Share Posted March 15, 2005 pieņemsim, ka dati no mysql plūst kā apmērām: 0:tv, 1:aiwa, 2:120.34, 0:radio, 1:panasonic, 2:12.35 datu plūsma $dataflow (att - tips, firma, cena) kad notiek $result=mysql_fecth_row(), data pointeris ielasa katru rindu līdz nākamam "0" elementam, e.g. $dataflow[0]=tv, $dataflow[1]=aiwa, $dataflow[2]=120.34 pie assoc, tiek no sākuma veikta lauku nosaukumu dabošana no pieprasījuma un sastādīts masīvs: $fields=array( 'tips'=>0, 'firma'=>1, 'cena'=>2 ) un pēc tam blaukts tas pats fetch_row, resp., kad es pieprasu no, piem. $result[{kaut_kas}], tiek pēc būtības paprasīts att. rindas $dataflow[$fields[{kaut_kas}]] tā kā īpaši lielam ātruma ieguvumam nevajadzētu būt, tāpē es pār assoc Link to comment Share on other sites More sharing options...
arnico Posted March 15, 2005 Report Share Posted March 15, 2005 Manc viedoklis balstiits tiiri uz pashiem masiiviem un to aatrdarbiibu :) balstiits uz shiem testiem, (kur lielaakais izpildes laiks ir 100%): 1. {$test[0000]=1;$test[0001]=1;$test[0002]=1;$test[0003]=1;$test[0004]=1; } 2. {$test[1000]=1;$test[1001]=1;$test[1002]=1;$test[1003]=1;$test[1004]=1; } 3. {$test["aa"]=1;$test["bb"]=1;$test["cc"]=1;$test["dd"]=1;$test["ee"]=1; } 4. {$test[aa]=1; $test[bb]=1; $test[cc]=1; $test[dd]=1; $test[ee]=1; } 5. {$test[0][0]=1;$test[0][1]=1;$test[0][2]=1;$test[0][3]=1;$test[0][4]=1; } 6. {$test[2][1]=1;$test[3][8]=1;$test[4][9]=1;$test[33][99]=1;$test[123][99]=1;} 7. {$test[a][b]=1;$test[x][y]=1;$test[d][c]=1;$test[a][s]=1;$test[b][n]=1; } 1. 28.0% 2. 27.7% 3. 29.9% 4. 39.7% 5. 34.6% 6. 34.3% 7. 100.0% Link to comment Share on other sites More sharing options...
Venom Posted March 15, 2005 Report Share Posted March 15, 2005 testi ir kļūdaini Link to comment Share on other sites More sharing options...
arnico Posted March 15, 2005 Report Share Posted March 15, 2005 testi ir kļūdaini 15023[/snapback] padalies kur ir kljuudas? pasham slinkums buutu testeeties tik traki, taadelej panjeemu no itejienes - http://www.codenet.ru/webmast/php/speed/ Link to comment Share on other sites More sharing options...
Delfins Posted March 15, 2005 Report Share Posted March 15, 2005 (edited) padalies kur ir kljuudas? pasham slinkums buutu testeeties tik traki, taadelej panjeemu no itejienes - http://www.codenet.ru/webmast/php/speed/ 15024[/snapback] tāpēc ka mākslīgi un statiski. Ieliec kādu benchmark esošajam projektam vai vienkāršam alogritmam, kas kaut ko rēķina. domāju rezultāti stipri atškirsies (kā arī realizācija šad-tad) :) Edited March 15, 2005 by Delfins Link to comment Share on other sites More sharing options...
Venom Posted March 15, 2005 Report Share Posted March 15, 2005 $test[a]=1 - kļūda tie testi ir ņemti no php.spb.ru un ir no kāda 95-98 gada ar 4.x versiju masīvu pointerēšanas mehānisms stipri mainījies Link to comment Share on other sites More sharing options...
bubu Posted March 15, 2005 Report Share Posted March 15, 2005 (edited) padalies kur ir kljuudas? pasham slinkums buutu testeeties tik traki, taadelej panjeemu no itejienes - http://www.codenet.ru/webmast/php/speed/ 15024[/snapback] esi dzirdējis par tādu lietu, kā - error_reporting(E_ALL); :) Pie tam, starp 1. un 3. testu īpaši lielās atšķirības ātrumā nav. Edited March 15, 2005 by bubu Link to comment Share on other sites More sharing options...
arnico Posted March 15, 2005 Report Share Posted March 15, 2005 esi dzirdējis par tādu lietu, kā - error_reporting(E_ALL); :)Pie tam, starp 1. un 3. testu īpaši lielās atšķirības ātrumā nav. 15029[/snapback] esmu dzirdeejis un aktiivi to izmantoju :) bet kaa jau teicu sho testu es netaisiiju , bet panjeemu no taas adreses rezultaatus :) Link to comment Share on other sites More sharing options...
Delfins Posted March 15, 2005 Report Share Posted March 15, 2005 (edited) esmu dzirdeejis un aktiivi to izmantoju :) bet kaa jau teicu sho testu es netaisiiju , bet panjeemu no taas adreses rezultaatus :) 15031[/snapback] lai nestrīdētos delfins@mandalay:~$ ./bench.php -- With Arrays -- Rows: 85794 DCs: 42439 SIDECARs: 644 MaxSM: 1095703 Time taken: 2.0215020179749 -- With Object -- Rows: 85794 DCs: 42439 SIDECARs: 644 MaxSM: 1095703 Time taken: 1.8180799484253 -- With Rows -- Rows: 85794 DCs: 42439 SIDECARs: 644 MaxSM: 1095703 Time taken: 1.6233339309692 Apgrieztaa seciibaa :) -- With Rows -- Rows: 85794 DCs: 42439 SIDECARs: 644 MaxSM: 1095703 Time taken: 1.6263220310211 -- With Object -- Rows: 85794 DCs: 42439 SIDECARs: 644 MaxSM: 1095703 Time taken: 1.821604013443 -- With Arrays -- Rows: 85794 DCs: 42439 SIDECARs: 644 MaxSM: 1095703 Time taken: 2.0186769962311 Kods ir sekojošs #### With ARRAYS ############################################### function doWithArrays($dbConn,$sql) { print "-- With Arrays --\n"; $res = mysql_query($sql,$dbConn); $dcCount = $sidecarsCount = $maxSM = $rows = 0; $startTime = getmicrotime(); while ( $row = mysql_fetch_array($res) ) { $rows++; if ($row['point_id']==1) $dcCount++; if ($row['sidecar']) $sidecarsCount++; $maxSM = max( $maxSM, $row['sm'] ); } $time = (getmicrotime()-$startTime); print "Rows: $rows DCs: $dcCount SIDECARs: $sidecarsCount MaxSM: $maxSM\n"; print "Time taken: $time\n"; mysql_free_result($res); } #### With ROWS ############################################### function doWithRows($dbConn,$sql) { print "-- With Rows --\n"; $res = mysql_query($sql,$dbConn); $dcCount = $sidecarsCount = $maxSM = $rows = 0; $startTime = getmicrotime(); while ( $row = mysql_fetch_row($res) ) { $rows++; if ($row[0]==1) $dcCount++; if ($row[2]) $sidecarsCount++; $maxSM = max( $maxSM, $row[1] ); } $time = (getmicrotime()-$startTime); print "Rows: $rows DCs: $dcCount SIDECARs: $sidecarsCount MaxSM: $maxSM\n"; print "Time taken: $time\n"; mysql_free_result($res); } #### With OBJECTS ############################################### function doWithObjects($dbConn,$sql) { print "-- With Object --\n"; $res = mysql_query($sql,$dbConn); if (!$res) die('Query failed'); $dcCount = $sidecarsCount = $maxSM = $rows = 0; $startTime = getmicrotime(); while ( $row = mysql_fetch_object($res) ) { $rows++; if ($row->point_id==1) $dcCount++; if ($row->sidecar) $sidecarsCount++; $maxSM = max( $maxSM, $row->sm ); } $time = (getmicrotime()-$startTime); print "Rows: $rows DCs: $dcCount SIDECARs: $sidecarsCount MaxSM: $maxSM\n"; print "Time taken: $time\n"; mysql_free_result($res); } $sql = "SELECT point_id, sm, sidecar FROM rimi_delivers_data"; Secinājums... ja vajag apstrādāt 100k ieraksti on-line, tad gan 200ms vinēt uz fetch_row() ir jēga (nezinu vai kāds vispār on-line fetcho 100k ierakstus :)) bet kaa jau minēju, $row->fieldName (no xxx_fetch_object() ) pieraksts gan stipri palielina koda lasāmību un uz maziem fetch-iem starpības jau nav... nedzīvojam takš Pentium-1 laikos... Edited March 15, 2005 by Delfins Link to comment Share on other sites More sharing options...
Delfins Posted March 15, 2005 Report Share Posted March 15, 2005 un rezultāts ar fetch_assoc() Rows: 85794 DCs: 42439 SIDECARs: 644 MaxSM: 1095703 Time taken: 1.7660069465637 Līdz ar to "ranks" ir sekojošs (100k ieraksti) _row() (0) _assoc() (+100ms) _object() (+50ms) _array() (+200ms) PS: iekavās - nobīde no iepriekšējā Link to comment Share on other sites More sharing options...
Recommended Posts