brentman Posted March 30, 2014 Share Posted March 30, 2014 I am writing a slot machine and have a super basic script at this point, this makes up 90+% of the php in the slot machine file however it loads pretty slow compared to all my other sites and scripts so I think I am doing something wrong in terms of performance. ie I have a dice script that loads almost instantly on the same hosting but this takes like a full second. Logic is right and it works but how to optimize? or am I just crazy and its just variations in hosting and this shouldn't be slow? if ($one == 1 && $one == $two && $two == $three) { $bonus = 10; } elseif ($one == 2 && $one == $two && $two == $three) { $bonus = 20; } elseif ($one == 3 && $one == $two && $two == $three) { $bonus = 30; } elseif ($one == 4 && $one == $two && $two == $three) { $bonus = 40; } elseif ($one == 5 && $one == $two && $two == $three) { $bonus = 50; } elseif ($one == 6 && $one == $two && $two == $three) { $bonus = 60; } elseif ($one == 7 && $one == $two && $two == $three) { $bonus = 80; } elseif ($one == 8 && $one == $two && $two == $three) { $bonus = 90; } elseif ($one == 9 && $one == $two && $two == $three) { $bonus = 100; } elseif ($one == 10 && $one == $two && $two == $three) { $bonus = 250; } elseif (($one == 7 || $one == 8 || $one == 9) && ($two == 7 || $two == 8 || $two == 9) && ($three == 7 || $three == 8 || $three == 9)) { $bonus = 70;} //add scatter pay elseif ($one == 6 || $two == 6 || $three==6) { if ($one == 6) { $scatter = $scatter+2; } if ($two == 6) { $scatter = $scatter+2; } if ($three == 6) { $scatter = $scatter+2; } $bonus = $scatter; } else { $bonus = -1; } Link to comment https://forums.phpfreaks.com/topic/287399-increase-performance-of-ifs-on-my-basic-slot-machine-code/ Share on other sites More sharing options...
mac_gyver Posted March 30, 2014 Share Posted March 30, 2014 any sort of micro-optimization of that section of code wouldn't result in a noticeable page generation/loading difference. have you determined how long that section of code takes to run (calculate the difference between microtime(true) at the start and end.) Link to comment https://forums.phpfreaks.com/topic/287399-increase-performance-of-ifs-on-my-basic-slot-machine-code/#findComment-1474443 Share on other sites More sharing options...
brentman Posted March 30, 2014 Author Share Posted March 30, 2014 No idea how to go about this...? Link to comment https://forums.phpfreaks.com/topic/287399-increase-performance-of-ifs-on-my-basic-slot-machine-code/#findComment-1474445 Share on other sites More sharing options...
mac_gyver Posted March 30, 2014 Share Posted March 30, 2014 see example #2 in the documentation - http://php.net/microtime Link to comment https://forums.phpfreaks.com/topic/287399-increase-performance-of-ifs-on-my-basic-slot-machine-code/#findComment-1474446 Share on other sites More sharing options...
brentman Posted March 30, 2014 Author Share Posted March 30, 2014 Thanks you are right, it was nothing. Must be something else going on with the code or my server. Link to comment https://forums.phpfreaks.com/topic/287399-increase-performance-of-ifs-on-my-basic-slot-machine-code/#findComment-1474447 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.