Created
September 9, 2013 21:51
-
-
Save olekhy/6502025 to your computer and use it in GitHub Desktop.
perfomance
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 | |
/** | |
* This file is part of me | |
* | |
* @author Oleksandr Khutoretskyy <olekhy@gmail.com> | |
* Date: 9/9/13 | |
* Time: 11:30 PM | |
* @license MIT | |
* | |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
* | |
* This software consists of voluntary contributions made by many individuals | |
* and is licensed under the MIT license. | |
*/ | |
$constants = array('a'=>3,1,2,2,"F" => 3,3, "DF" => 3,4,5,6, 'a','a', 'bbbb', 'f'); | |
$my = function($constants) { | |
if (max(array_count_values($constants)) > 1) { | |
return; | |
//throw new LogicException(sprintf( | |
// 'All possible values needs to be unique. The following are ambiguous: %s', | |
// '"' . implode('","', array_unique(array_diff_assoc($constants, array_unique($constants)))) . '"' | |
//)); | |
} | |
}; | |
// opposite code by Marc Bennewitz | |
// Constant values needs to be unique | |
$their = function($constants) { | |
if (count($constants) > count(array_unique($constants))) { | |
return; | |
//$ambiguous = array(); | |
//foreach (array_count_values($constants) as $constValue => $countValue) { | |
// if ($countValue > 1) { | |
// $ambiguous[] = $constValue; | |
// } | |
//} | |
//throw new LogicException(sprintf( | |
// 'All possible values needs to be unique. The following are ambiguous: %s', | |
// "'" . implode("', '", $ambiguous) . "'" | |
//)); | |
} | |
}; | |
$s = microtime(true); | |
for ($i = 0; $i < 1000000; $i++) { | |
try { | |
$their($constants); // 31.979820013046 and wo code inside 10.044551849365 | |
//$my($constants); // 32.691072940826 and wo code inside 3.4153151512146 | |
} catch (Exception $e) { | |
} | |
} | |
echo microtime(true) - $s; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment