Objects: Why are they useful? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Objects: Why are they useful? (/showthread.php?tid=5464) |
Objects: Why are they useful? - El Forum - 01-22-2008 [eluser]tonanbarbarian[/eluser] Ok i decided to do some benchmarking and i was very surprised. (Yes I am always doing these little benchmarking exercises) here is the code i ran Code: function test() { aaa is running a class with 2 predeclared properties bbb is a class with just 1 predeclared property and the other must be declared at run time stdClass is creating an empty class and assigning both properties at run time Array is creating an empty array and assigning elements Array Object creates the array like Array but then casts to object I run the tests 100,000 times each and record the time. I then got the average of 5 full runs The first results are PHP 4.4.8 CGI mode in Apache aaa: 0.1635 bbb: 0.1615 stdClass: 0.1680 Array: 0.1295 Array Object: 0.1980 The second results are PHP 5.2.3 API mode in Apache aaa: 0.1309 bbb: 0.1233 stdClass: 0.1205 Array: 0.0776 Array Object: 0.1397 So surprisingly what this show is that assigning properties to existing classes at run time is quicker somehow. And in PHP 5 stdClass is quicker yet again. Overall using arrays is significantly quicker than objects just to handle data And if you are using PHP 5 then casting is not too bad if you must use an object. Draw what ever conclusions you want from this... but I will stick with using arrays as the results from the database, and as storage mechanisms for any data I use in views. Objects: Why are they useful? - El Forum - 01-24-2008 [eluser]wiredesignz[/eluser] I can't see how 4/100th's of a second is significantly faster over 100,000 iterations. Even if I mis-read and its for 1 iteration it's really negligable. I'll stick with objects. Objects: Why are they useful? - El Forum - 01-24-2008 [eluser]ejangi[/eluser] It isn't for one page request, but for a box running multiple sites with many many pages requests per second it does make a difference. Objects: Why are they useful? - El Forum - 01-24-2008 [eluser]wiredesignz[/eluser] Isn't that what Output caching is all about? I really don't think any script, procedural or OOP is going to perform well with 1000's of page requests per second. I read somewhere that a simple CI 'hello world' type application was only good for about 50 page requests per second anyway. (which is better than some other frameworks I won't mention) Objects: Why are they useful? - El Forum - 01-25-2008 [eluser]Edemilson Lima[/eluser] Quote:I read somewhere that a simple CI ‘hello world’ type application was only good for about 50 page requests per second anyway. It depends on your web server resources. If you need that much requests, may you need a dedicated server. But in any case, you a well tuned application is essential. |