Welcome Guest, Not a member yet? Register   Sign In
CI-based Web Sites Performance
#20

[eluser]Lewis[/eluser]
[quote author="Craig Rodway" date="1202609518"]Do you have any test results from benchmarks for this function?[/quote]

It doesn't take a benchmark to realise that looping database results twice is unnecessary.


[quote author="tonanbarbarian" date="1202615705"]ok i sort of agree with lewis

i am thinking the reason that the db->result type functions were created were for convenience. it makes it easier to use methods to move back and forward amongst the records
[/quote]
I agree with you there, but why not have a function for simply doing fetch_array? Why make the current one private - why not at least advertise it for people who need to loop through large resultsets? Then when someone wants to use one of the functions to move forwards/backwards, perform result_array and cache the results. That way, there's always maximum performance.


[quote author="tonanbarbarian" date="1202615705"]while it does mean you have to parse through a loop twice there are things you can do to improve performance

for example
Code:
foreach ($query->result() as $row) ...
is fairly slow because it has to run the function on each iteration of the loop
use
Code:
$rows = $query->result();
foreach ($rows as $row) ...
instead

[/quote]

Not so. PHP will run the $query->result() once, and then loop through its results. I think you're getting mixed up with 'for' which will run the statement through each iteration.

[quote author="tonanbarbarian" date="1202615705"]
how much slower is it to have to process the loop twice though?
well that does depend on how many records you are processing.
if you are using a paginated list you wall always be limiting the number of records you retrieve.
So if it is 5, 10, 20, 50 or even 100 records in the result set then it is going to be very fast because the loop size is small and I would not worry about this as an issue.

If you are not using limits and you are having to pass 1000's of records then the extra processing may be noticable, but this is not something that happens often, and you could consider breaking your process into batches anyway and refreshing the pages in between.
[/quote]

Unfortunately the databases we work with require creating many different dropdowns with hundreds of options, or doing very complicated real-time processes were ever drop of performance counts. For example, using CI a result-set of 500 is returned, which is looped through by the database class, then my model to apply some formatting, and then the form helper to create a dropdown. That's 3 times, when it can all easily be done in one.

[quote author="tonanbarbarian" date="1202615705"]
having said all of this I have expressed a desire before to have something like
Code:
$this->query->fetch_object();
$this->query->fetch_array();
each of which just gets the next record but does not do any of the other processing that CI normally uses to "cache" the result data[/quote]

You can use $query->_fetch_object(), although technically it's supposed to be a private method. But remember that only returns one row each run, so you'll have to use 'while' instead.


Messages In This Thread
CI-based Web Sites Performance - by El Forum - 02-03-2008, 07:15 AM
CI-based Web Sites Performance - by El Forum - 02-03-2008, 11:22 AM
CI-based Web Sites Performance - by El Forum - 02-03-2008, 02:01 PM
CI-based Web Sites Performance - by El Forum - 02-03-2008, 03:09 PM
CI-based Web Sites Performance - by El Forum - 02-03-2008, 04:54 PM
CI-based Web Sites Performance - by El Forum - 02-03-2008, 06:23 PM
CI-based Web Sites Performance - by El Forum - 02-03-2008, 08:33 PM
CI-based Web Sites Performance - by El Forum - 02-03-2008, 10:27 PM
CI-based Web Sites Performance - by El Forum - 02-04-2008, 02:44 AM
CI-based Web Sites Performance - by El Forum - 02-04-2008, 03:42 AM
CI-based Web Sites Performance - by El Forum - 02-04-2008, 08:43 AM
CI-based Web Sites Performance - by El Forum - 02-04-2008, 04:19 PM
CI-based Web Sites Performance - by El Forum - 02-04-2008, 04:54 PM
CI-based Web Sites Performance - by El Forum - 02-04-2008, 06:42 PM
CI-based Web Sites Performance - by El Forum - 02-04-2008, 09:38 PM
CI-based Web Sites Performance - by El Forum - 02-09-2008, 06:10 AM
CI-based Web Sites Performance - by El Forum - 02-09-2008, 01:51 PM
CI-based Web Sites Performance - by El Forum - 02-09-2008, 02:11 PM
CI-based Web Sites Performance - by El Forum - 02-09-2008, 03:55 PM
CI-based Web Sites Performance - by El Forum - 02-09-2008, 04:28 PM
CI-based Web Sites Performance - by El Forum - 02-09-2008, 08:21 PM
CI-based Web Sites Performance - by El Forum - 02-10-2008, 06:41 AM
CI-based Web Sites Performance - by El Forum - 02-10-2008, 04:44 PM
CI-based Web Sites Performance - by El Forum - 02-10-2008, 10:10 PM
CI-based Web Sites Performance - by El Forum - 02-11-2008, 03:37 PM
CI-based Web Sites Performance - by El Forum - 02-12-2008, 09:16 AM
CI-based Web Sites Performance - by El Forum - 02-12-2008, 09:26 AM
CI-based Web Sites Performance - by El Forum - 02-12-2008, 10:02 AM
CI-based Web Sites Performance - by El Forum - 02-12-2008, 01:51 PM
CI-based Web Sites Performance - by El Forum - 02-12-2008, 02:01 PM
CI-based Web Sites Performance - by El Forum - 02-12-2008, 02:34 PM
CI-based Web Sites Performance - by El Forum - 02-13-2008, 03:35 AM
CI-based Web Sites Performance - by El Forum - 02-13-2008, 05:14 AM
CI-based Web Sites Performance - by El Forum - 02-13-2008, 07:44 AM
CI-based Web Sites Performance - by El Forum - 02-13-2008, 08:53 AM
CI-based Web Sites Performance - by El Forum - 02-13-2008, 09:49 AM
CI-based Web Sites Performance - by El Forum - 02-13-2008, 12:38 PM
CI-based Web Sites Performance - by El Forum - 02-13-2008, 01:21 PM
CI-based Web Sites Performance - by El Forum - 02-13-2008, 01:24 PM
CI-based Web Sites Performance - by El Forum - 02-13-2008, 01:32 PM
CI-based Web Sites Performance - by El Forum - 02-13-2008, 02:57 PM
CI-based Web Sites Performance - by El Forum - 02-13-2008, 08:03 PM
CI-based Web Sites Performance - by El Forum - 03-16-2008, 05:51 PM



Theme © iAndrew 2016 - Forum software by © MyBB