Leeder Posted March 26, 2007 Share Posted March 26, 2007 Which is faster, if ($user['vipage'] > 0) { echo "VIP Days Left: {$user['vipage']}"; } or switch ($user['vipage']) { case "0": break; default: echo "VIP Days Left: {$user['vipage']}"; break; } ? Link to comment https://forums.phpfreaks.com/topic/44341-solved-which-loads-faster/ Share on other sites More sharing options...
trq Posted March 26, 2007 Share Posted March 26, 2007 Which do you think? The one with less redundant code, however, the difference is not worth worrying about. Link to comment https://forums.phpfreaks.com/topic/44341-solved-which-loads-faster/#findComment-215345 Share on other sites More sharing options...
Leeder Posted March 26, 2007 Author Share Posted March 26, 2007 Well I'm sure people didn't worry about the wheel before it was invented. Link to comment https://forums.phpfreaks.com/topic/44341-solved-which-loads-faster/#findComment-215348 Share on other sites More sharing options...
MadTechie Posted March 26, 2007 Share Posted March 26, 2007 if took 0.030161857605 Switch took 0.036612033844 in a loop of 1000 time to took to find someone who cares ..... (still running) Well I'm sure people didn't worry about the wheel before it was invented. You know how dumb thats sounded ? Link to comment https://forums.phpfreaks.com/topic/44341-solved-which-loads-faster/#findComment-215350 Share on other sites More sharing options...
DeathStar Posted March 26, 2007 Share Posted March 26, 2007 Why worry about the speed? The difference in so minute no one would know! Link to comment https://forums.phpfreaks.com/topic/44341-solved-which-loads-faster/#findComment-215353 Share on other sites More sharing options...
Leeder Posted March 26, 2007 Author Share Posted March 26, 2007 Well I'd rather worry about it now compared to in 60 years when I can't tell the difference between applesauce and a potato. (How stupid did THAT sound?) Link to comment https://forums.phpfreaks.com/topic/44341-solved-which-loads-faster/#findComment-215354 Share on other sites More sharing options...
MadTechie Posted March 26, 2007 Share Posted March 26, 2007 As a side note functions work better when used correctly ie <?php switch ($user['vipage']) { case "0": break; case "1": break; case "2": break; case "3": break; default: echo ""; break; } ?> runs quicker than <?php if ($user['vipage'] == 0) { echo ""; }elseif ($user['vipage'] == 1) { echo ""; }elseif ($user['vipage'] == 2) { echo ""; }elseif ($user['vipage'] == 3) { echo ""; } ?> and yep again dumb Link to comment https://forums.phpfreaks.com/topic/44341-solved-which-loads-faster/#findComment-215357 Share on other sites More sharing options...
DeathStar Posted March 26, 2007 Share Posted March 26, 2007 I'm pretty sure php will still exists in 60 years from now but.. You would just get upgrades. Link to comment https://forums.phpfreaks.com/topic/44341-solved-which-loads-faster/#findComment-215359 Share on other sites More sharing options...
Leeder Posted March 26, 2007 Author Share Posted March 26, 2007 <?php if ($user['vipage'] == 0) { echo ""; }elseif ($user['vipage'] == 1) { echo ""; }elseif ($user['vipage'] == 2) { echo ""; }elseif ($user['vipage'] == 3) { echo ""; } ?> That's so ugly lol <?php if ($user['vipage'] == 0) { echo ""; } elseif ($user['vipage'] == 1) { echo ""; } elseif ($user['vipage'] == 2) { echo ""; } elseif ($user['vipage'] == 3) { echo ""; } ?> Much better ^-^ Link to comment https://forums.phpfreaks.com/topic/44341-solved-which-loads-faster/#findComment-215361 Share on other sites More sharing options...
cmgmyr Posted March 26, 2007 Share Posted March 26, 2007 Why worry about the speed? The difference in so minute no one would know! Well when you are making a MASSIVE program/application a half second here and there add up to a lot of time. But for a small application it doesn't matter as much, BUT you should always be aware of speed. Link to comment https://forums.phpfreaks.com/topic/44341-solved-which-loads-faster/#findComment-215365 Share on other sites More sharing options...
DeathStar Posted March 26, 2007 Share Posted March 26, 2007 Why worry about the speed? The difference in so minute no one would know! Well when you are making a MASSIVE program/application a half second here and there add up to a lot of time. But for a small application it doesn't matter as much, BUT you should always be aware of speed. True, but I think he wont be making big scripts for a while... Link to comment https://forums.phpfreaks.com/topic/44341-solved-which-loads-faster/#findComment-215366 Share on other sites More sharing options...
MadTechie Posted March 26, 2007 Share Posted March 26, 2007 LOL true, common problem i face with speed is memory usage, i may add a caching but then i have to watch my memory usage, Link to comment https://forums.phpfreaks.com/topic/44341-solved-which-loads-faster/#findComment-215370 Share on other sites More sharing options...
Leeder Posted March 26, 2007 Author Share Posted March 26, 2007 Why worry about the speed? The difference in so minute no one would know! Well when you are making a MASSIVE program/application a half second here and there add up to a lot of time. But for a small application it doesn't matter as much, BUT you should always be aware of speed. True, but I think he wont be making big scripts for a while... Why, because of my coding style? Link to comment https://forums.phpfreaks.com/topic/44341-solved-which-loads-faster/#findComment-215504 Share on other sites More sharing options...
DeathStar Posted March 26, 2007 Share Posted March 26, 2007 well.. no. but i can tell. Link to comment https://forums.phpfreaks.com/topic/44341-solved-which-loads-faster/#findComment-215579 Share on other sites More sharing options...
per1os Posted March 26, 2007 Share Posted March 26, 2007 On top of that speed question doing this: echo "{$var['1']}"; takes more time to process than this: echo "Variable 1: " . $var['1']; //or even echo "Variable 1: ", $var['1']; If you are concerned about speed. Either or It all depends on your coding style and what you are trying to do. If you have 10 variations switch is better where as if there is only 2, probably if/elseif/else. Either way it is like 1 millionth of a second difference which does not make much of a difference at all. Link to comment https://forums.phpfreaks.com/topic/44341-solved-which-loads-faster/#findComment-215592 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.