Created
August 24, 2013 00:54
-
-
Save thbourlove/6325340 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace BmTest; | |
use Athletic\AthleticEvent; | |
class IfElse extends AthleticEvent | |
{ | |
private $arr = []; | |
public function SetUp() | |
{ | |
$this->arr = []; | |
for ($i = 0; $i < 100000; $i++) { | |
$this->arr[] = rand(); | |
} | |
} | |
/** | |
* @iterations 100 | |
*/ | |
public function condOp() | |
{ | |
foreach ($this->arr as $value) { | |
$tmp = $value > 1000000000 ? $value : $value - 1000000000; | |
} | |
} | |
/** | |
* @iterations 100 | |
*/ | |
public function ifElse() | |
{ | |
foreach ($this->arr as $value) { | |
if ($value > 1000000000) { | |
$tmp = $value; | |
} else { | |
$tmp = $value - 1000000000; | |
} | |
} | |
} | |
} | |
/* | |
Results: | |
BmTest\IfElse | |
Method Name Iterations Average Time Ops/second | |
------ ------------ -------------- ------------- | |
condOp: [100 ] [0.0095007562637] [105.25478] | |
ifElse: [100 ] [0.0079683446884] [125.49658] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment