I had a theory that Database SQL filtering of results would be faster than using LimitIterator for the same operation. However, my Database Implementation was total crap, but was still faster than LimitIterator for the same task.
SQL: SELECT * FROM table LIMIT 10
LimitIterator:
Code: Select all
$iterator = new DatabaseIterator("SELECT * FROM table");
$limit = new LimitIterator($result, 0, 10);
foreach($limit as $row)
{
}
This is just an example, the mysqli does not implement Iterator, but the sqlite and PDO do. However, 10 rows won't give you anything, but a million rows would. Also, Foreach is slower than while, about two times slower.
However, I believe LimitIterator would be better for native arrays and not database results. SQL should be used instead of PHP for optimization.