Welcome Guest, Not a member yet? Register   Sign In
Which is faster?
#1

[eluser]Dolrich[/eluser]
Is loading of model on per use basis faster than loading all on the constructor of the controller?

This ---



Code:
Class Foo extends controller {

   function Foo() {
       parent::Controller();
       $this->load->model('update');
       $this->load->model('view');
       $this->load->model('delete');
   }

   function update() {
       $this->update->process();
   }

   function view() {
       $this->view->process();
   }

   function delete() {
       $this->delete->process;
   }

}

Or this -----

Code:
Class Foo extends controller {

   function Foo() {
       parent::Controller();
   }

   function update() {
       $this->load->model('update');
       $this->update->process();
   }

   function view() {
       $this->load->model('view');
       $this->view->process();
   }

   function delete() {
       $this->load->model('delete');
       $this->delete->process;
   }

}
#2

[eluser]imn.codeartist[/eluser]
I guess the second one
#3

[eluser]luffy[/eluser]
The second one Smile
#4

[eluser]wiredesignz[/eluser]
The second method is faster if you do not need to load all three models on every request, this will reduce memory usage as well.
#5

[eluser]saidai jagan[/eluser]
Thanks mates Smile
#6

[eluser]Zeeshan Rasool[/eluser]
[quote author="wiredesignz" date="1255620170"]The second method is faster if you do not need to load all three models on every request, this will reduce memory usage as well.[/quote]

Yeah, right , if we need almost all models should be called or we need some of models to be loaded every time then first option is best Otherwise we should avoid controller to load models which are not required.
#7

[eluser]Ki[/eluser]
Keep in mind that you will not be doing all 3 functions on one web page at the same time.
Likely each page of your website will do either delete, update or view and then re-load.
Keeping that in mind, why would you load all 3 models if you actually need one at a time? Its a huge drag on page speed.




Theme © iAndrew 2016 - Forum software by © MyBB