Skip to content

Instantly share code, notes, and snippets.

@thbourlove
Created August 24, 2013 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thbourlove/6325340 to your computer and use it in GitHub Desktop.
Save thbourlove/6325340 to your computer and use it in GitHub Desktop.
<?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