Skip to content
Jul 4 / markg85

decisions, updates and benchmarks

Hi,

Oke, now i’m kinda getting crazy by my own benchmarks:


Array VS SplFixedArray — SPLFixedArray
Execution time: 0.022745132446289 — Memory: 8801432

Array VS SplFixedArray — Array
Execution time: 0.037898063659668 — Memory: 17849424

Stack VS array_unshift — Stack
Execution time: 0.000594139099121 — Memory: 128952 — banana999

Stack VS array_unshift — Unshift
Execution time: 0.035573005676270 — Memory: 176440 — banana999

Stack VS array_unshift VS array_reverse — array_reverse
Execution time: 0.000366926193237 — Memory: 176440 — banana999

What you see above is very interesting. Lets first look at the Array VS SplFixedArray one. If you look at the execution time you see that the SplFixedArray is roughly 1 third faster then a normal array. Now look at the memory part. SplFixedArray is more then twice as efficient as a normal array in terms of memory and it’s even 1/3 faster then a normal array! So i will use it when available like said in my previous post. And i think i will use it in every place where possible. the performance numbers speak for themself.

Now that SplFixedArray one was already on my list to use because i roughly knew the performance boosts it gives but the real decision part that’s breaking my head is the stack benchmarks. The first stack one is the most memory efficient and, after further benching it, becomes faster then the array_reverse one if you add in 100.000 elements (those 3 stack ones have 1.000 elements). The second stack one (array_unshift) is the one that i was using till just 30 minutes ago. I knew it was slow but i didn’t know how i could fix it. Turns out making a normal array then using array_reverse is exactly what i needed to fix it. Now the issue here is the SplStack (first stack one) is a nice object and doing exactly what i want, but is slower then a normal array followed by array_reverse when filled. So what do i need to choose here? lower memory, not the fastest way and nice object (SplStack) or fastest option, little more memory and no nice object (array followed by array_reverse).. I tend to choose the array + array_reverse option and that’s mainly because the data in this array will probably be never more then 10 elements. In case you want to know. I use this in the category class where i calculate the title array and that is the link part that allows you to go back to the parent category (up until the root category).

Now for the updates
Category class is updated to be a lot faster with bigger arrays (removed the use of array_unshift). The cache abstraction is nearly done. All that’s left to be done in there is the file based caching.

That’s it for todays progress,
Mark.

Leave a Comment