Question about Strings vs integers (in defines)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
twrofpwr
Forum Newbie
Posts: 17
Joined: Wed Jun 15, 2005 8:46 pm

Question about Strings vs integers (in defines)

Post by twrofpwr »

I thought I could speed up code by using integeres in our $mode variable used in compares instead of a string.

define("MODE_CONST",1);
Ie mode="my_string_that_should_take_longer" being used in "switch" or "if" compares, with mode=MODE_CONST instead, there are several dozen modes, and about maybe 5 switches in every page load...

Howcome using integers doens't seem faster then using strings??? Not even slightly faster... I also tried to make a demo program to test this increasing the intervals to see if I could really determine which is faster, it turns out that php was doing something funny with strings, and eventualy the string comapres were faster then the integer compares even, like it was caching them or something..

Anyone have any suggestions or ideas on this??? I am lost.

Thanks,

Jeff.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's likely due to the extreme type-looseness of php.. It can also vary quite a bit depending on length of the strings being used..
Post Reply