Part of the EllisLab Network
   
 
cost: base_url() as bottled water
Posted: 16 May 2007 12:12 AM   [ Ignore ]  
Grad Student
Avatar
Rank
Total Posts:  71
Joined  02-16-2007

if this has been done, my apologies. i was bored, and the only content that’s ever here are questions.. boorriinnngg

It occured to me that it was a little ridiculous to have a certain function call all over my app whos sole purpose was to return a string. How silly. The culprit? base_url(). errr. I did a little comparision to see for myself just how much this greedy little bastard was stealing from me.

base_url() vs APP_PATH (as old school constant)

my test - elapsed time of 10,000 iterations through a for loop, 10 seperate executions, then averaged.

base_url()—————-APP_PATH

.1194—————————.0056
.1311—————————.0051
.1200—————————.0097
.1264—————————.0067
.1272—————————.0309
.1306—————————.0214
.1273—————————.0052
.1568—————————.0276
.1262—————————.0064
.1273—————————.0294

avg speed
- base_url() > .1292
- APP_PATH > .0148

APP_PATH faster by 8.7X

It was even worse for concatenations. A typical operation for any CI dev is to concat base_url() with the rest of the desired url. I’m to lazy to make another cheesy graph but APP_PATH was faster through 10,000 iterations by 12.8X

Moral of the story.. don’t be a pig! use static method calls and constants where appropriate.

 Signature 

anyone notice that the smilies look like Rick Ellis?  raspberry

Profile
 
 
Posted: 16 May 2007 12:41 AM   [ Ignore ]   [ # 1 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1747
Joined  06-23-2006

I agree. base_url() isn’t going to change during the execution of a request, so it make sense to have it as a constant. Good call.

 Signature 

Mac OS X 10.4.10, Apache 1.3.3, PHP 5.2.3, CodeIgniter 1.5.x., baby!

Profile
 
 
Posted: 19 May 2007 07:11 PM   [ Ignore ]   [ # 2 ]  
Summer Student
Avatar
Total Posts:  26
Joined  04-23-2007
eurosause - 16 May 2007 12:12 AM

if this has been done, my apologies. i was bored, and the only content that’s ever here are questions.. boorriinnngg

It occured to me that it was a little ridiculous to have a certain function call all over my app whos sole purpose was to return a string. How silly. The culprit? base_url(). errr. I did a little comparision to see for myself just how much this greedy little bastard was stealing from me.

base_url() vs APP_PATH (as old school constant)

my test - elapsed time of 10,000 iterations through a for loop, 10 seperate executions, then averaged.

base_url()—————-APP_PATH

.1194—————————.0056
.1311—————————.0051
.1200—————————.0097
.1264—————————.0067
.1272—————————.0309
.1306—————————.0214
.1273—————————.0052
.1568—————————.0276
.1262—————————.0064
.1273—————————.0294

avg speed
- base_url() > .1292
- APP_PATH > .0148

APP_PATH faster by 8.7X

It was even worse for concatenations. A typical operation for any CI dev is to concat base_url() with the rest of the desired url. I’m to lazy to make another cheesy graph but APP_PATH was faster through 10,000 iterations by 12.8X

Moral of the story.. don’t be a pig! use static method calls and constants where appropriate.

Nice stuff you posted here!

Thanks!

 Signature 

$solution = $Apache + $PHP + $CI;

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 721, on January 06, 2010 09:38 AM
Total Registered Members: 115012 Total Logged-in Users: 69
Total Topics: 122446 Total Anonymous Users: 5
Total Replies: 647326 Total Guests: 549
Total Posts: 769772    
Members ( View Memberlist )