Jump to content

Increase performance of IFs on my basic slot machine code


brentman

Recommended Posts

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;
}

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.)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.