Welcome Guest, Not a member yet? Register   Sign In
Quick Performance Question
#1

[eluser]obobo[/eluser]
I'm not sure what's going on behind the scenes technically when a view is called,
and I'm wondering if there is any difference in performance between:

Looping through db results within the controller and calling the view multiple times
foreach ($query->result() as $row){
$this->load->view('results_view');
}

vs.

looping through the db results within the view itself and only calling the view once from the controller.
#2

[eluser]m4rw3r[/eluser]
The view() function includes the view every time it is called, so I think it would be faster by looping the results in the view file.
#3

[eluser]xwero[/eluser]
This calls for benchmarks. obobo will you do the honors Smile
#4

[eluser]obobo[/eluser]
Sure i'll do the honors Smile

I'm not sure this counts as benchmarking,
but last night i timed the execution of a simple page returning 10 rows from the db

The average time (calculated from within the controller) was

.0031 seconds when the loop was within the view and the view was only called once
and
.0062 seconds when the loop called the view each time to display the results

I am very wet behind the ears when it comes to issues like performance
so i'm not sure if there are any other variables that could be affecting the results
or if timing from within the controller would be accurate,
(which is why i still posted the question)
but the two pages tested were identical except for the way the db results were displayed.
#5

[eluser]GSV Sleeper Service[/eluser]
I'm not sure why you would want to load the same view x times, it makes much more sense to loop through your results in the view.
#6

[eluser]xwero[/eluser]
obobo could you try 50 and 100 rows this gives a better idea of how fast the site gets slower adding a view in a loop.
#7

[eluser]obobo[/eluser]
@GSV Sleeper Service
... that's what i'm starting to realize.
#8

[eluser]obobo[/eluser]
50 rows:
.021 seconds vs .0043 seconds

100 rows:
.033 seconds vs. .0052 seconds




Theme © iAndrew 2016 - Forum software by © MyBB