Last active
October 12, 2015 15:18
-
-
Save davidkryzaniak/4046850 to your computer and use it in GitHub Desktop.
PHP Explode VS Unserialize (Who's Faster?)
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 is the list of elements. There are 500 items in this array. | |
/* From PHP.net */ | |
function convert($size){ | |
$unit=array('b','kb','mb','gb','tb','pb'); | |
return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i]; | |
} | |
$start1 = microtime(true); | |
$start1mem = memory_get_usage(); | |
$explodeThisArray = explode($explodeThis,","); | |
echo "Explode took ".(microtime(true)-$start1)." Seconds<br/>"; | |
echo "Explode used ".convert(memory_get_usage()-$start1mem)." of memory<br/><br/>"; | |
//empty it from memory | |
$explodeThisArray = array(); | |
$start = microtime(true); | |
$startmem = memory_get_usage(); | |
$unserializeThis = unserialize($unserializeThis); | |
echo "Unserialize took ".(microtime(true)-$start)." Seconds<br/>"; | |
echo "Unserialize used ".convert(memory_get_usage()-$startmem)." of memory<br/><br/>"; | |
//empty it from memory | |
$unserializeThis = array(); | |
$start3 = microtime(true); | |
$start3mem = memory_get_usage(); | |
$jsonDecodeThis = json_decode($jsonDecodeThis); | |
echo "JSON Decode took ".(microtime(true)-$start3)." Seconds<br/>"; | |
echo "JSON Decode used ".convert(memory_get_usage()-$start3mem)." of memory<br/><br/>"; | |
//empty it from memory | |
$jsonDecodeThis = array(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
delimiter must be first parameter