Welcome Guest, Not a member yet? Register   Sign In
result() vs. result_array() - result() costs mucho dinero

I was just curious about any possible difference in performance between $this->db->result() and $this->db->result_array() as I usually prefer my results in an array and wondered if I'm taking a hit because of it. It turns out to be the opposite. While the actual time of code/query execution did not vary, the amount of memory significantly did.

I setup a controller, loaded the model and ran these two queries with the following memory consumption:
2,167,032 bytes

1,398,956 bytes
Note that I have a few libraries auto loading so don't look too much into the base memory consumption, just the difference. Also, this is [obviously] a zip code table which contains about 32k records (it's incomplete).

I'm glad to see that my preference is not costing me performance, but very curious as to why this is. Do any of you smart people have more info on why there's such a gap between the two?

Thanks for reading.

i dont know all of the ins and outs but arrays are always going to use less space than objects
this has to do with their structure

considered one way arrays and objects are similar
they are both structures that can hold data in a similar way. Arrays are made up of keys and values and objects have properties and values.
The big difference is of course that objects can all have methods and you can create instances of them.
That is where I think they extra memory is used, keeping track of the extra structures and abilities of an object as compared to an array

i also prefer my data in arrays rather than in objects
it makes it easier for me to distinguish in general whether im accessing data or object such as models and controllers.

Theme © iAndrew 2016 - Forum software by © MyBB