note 63440 modified in function.odbc-fetch-row by danbrown

From: Date: Fri, 25 Jun 2010 13:44:21 +0000
Subject: note 63440 modified in function.odbc-fetch-row by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-170424@lists.php.net to get a copy of this message
I see many here try to iterate to emulate tis missing functionality. I benchmarked the performance on my PentiumM 1.6G on Excel table with 1100 rows and 2 field records and got 82ms time to retrieve number of rows using iteration through all of them, but only 7ms to execute the SQL statement. In this case of thousadn(s) of rows, it is probably faster to have the database calculate rows. Here is different algorithm for calculating the number of rows, which does not iterate through all of them, just uses interval splitting algorithm, and number of iterations is log2(n), where n is total number of rows in the result. The below algorithm in the case above (Excel table, 1100 rows 2 fields) took 10ms to calculate: <?php for($lo=0,$hi=1000000; $lo<$hi; ) { $num = (int)(($hi+$lo) / 2); if(odbc_fetch_row($this->Result, $num)) $lo = $num + 1; else $hi = $num - 1; } ?> --was-- I see many here try to iterate to emulate tis missing functionality. I benchmarked the performance on my PentiumM 1.6G on Excel table with 1100 rows and 2 field records and got 82ms time to retrieve number of rows using iteration through all of them, but only 7ms to execute the SQL statement. In this case of thousadn(s) of rows, it is probably faster to have the database calculate rows. Here is different algorithm for calculating the number of rows, which does not iterate through all of them, just uses interval splitting algorithm, and number of iterations is log2(n), where n is total number of rows in the result. The below algorithm in the case above (Excel table, 1100 rows 2 fields) took 10ms to calculate: for($lo=0,$hi=1000000; $lo<$hi; ) { $num = (int)(($hi+$lo) / 2); if(odbc_fetch_row($this->Result, $num)) $lo = $num + 1; else $hi = $num - 1; } http://php.net/manual/en/function.odbc-fetch-row.php

« previous php.notes (#170424) next »