As I'm going over how rails uses the active record pattern I was looking at php on trax's framework which is an interpretation of rails in PHP. One thing that bugged me was when you get a record set of data, like say SELECT * FROM users, which returns a record set of users data, it stores each record as an Object rather than just keeping it as an array from mysql_fetch_array. I wrote it off as just usings objects for the sake of objects and thought that there would be a noticable performance hit when storing an array of user objects compared to a native array of user rows.

I was wrong actually. I basically set up a User class, looped through and created an array of 100 user objects, then created an array with 100 array elements of the same user data. Then I profiled them to see which was faster. To my suprise it almost made no difference. Sometimes the array was faster, sometimes the object was faster when I tried to access all that data in a foreach loop. We're talking 0.0009 seconds on avg on my box. So the lesson is don't feel bad storing objects. I always felt a little guilt when using objects as record set objects, however I can finally relax and enjoy my programming day again :)

Ready for More?

Follow Me @jimplush