Last active
July 30, 2018 08:31
-
-
Save ostark/a7060b48e8d4ebfac9c4240a4bd248fd to your computer and use it in GitHub Desktop.
Craft micro optimization
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 | |
/* | |
* Context: | |
* https://github.com/craftcms/cms/blob/3f055237e314362b079cbbf63a9be46b9cdcd7c7/src/helpers/Image.php#L65 | |
*/ | |
class ArrayHelper | |
{ | |
public static function unique($array) | |
{ | |
return array_keys(array_flip($array)); | |
} | |
} | |
$formats = ["3fr","a","aai","ai","art","arw","avi","avs","b","bgr","bgra","bie","bmp","bmp2","bmp3","brf","c","cal","cals","canvas","caption","cin","cip","clip","cmyk","cmyka","cr2","crw","cur","cut","dcm","dcr","dcx","dds","dfont","djvu","dng","dot","dpx","epdf","epi","eps","eps2","eps3","epsf","epsi","ept","ept2","ept3","erf","exr","fax","fits","fractal","fts","g","g3","gif","gif87","gradient","gray","group4","hald","hdr","histogram","hrz","htm","html","icb","ico","icon","info","inline","ipl","isobrl","j2c","j2k","jbg","jbig","jng","jp2","jpc","jpeg","jpg","jpx","k","k25","kdc","label","m","m2v","m4v","mac","map","mat","matte","mef","miff","mng","mono","mov","mp4","mpc","mpeg","mpg","mrw","msl","msvg","mtv","mvg","nef","nrw","null","o","orf","otb","otf","pal","palm","pam","pango","pattern","pbm","pcd","pcds","pcl","pct","pcx","pdb","pdf","pdfa","pef","pes","pfa","pfb","pfm","pgm","pgx","picon","pict","pix","pjpeg","plasma","png","png24","png32","png8","pnm","ppm","preview","ps","ps2","ps3","psb","psd","ptif","pwp","r","radial-gradient","raf","ras","rgb","rgba","rgbo","rla","rle","scr","sct","sfw","sgi","shtml","sr2","srf","stegano","sun","svg","svgz","text","tga","thumbnail","tiff","tiff64","tile","tim","ttc","ttf","txt","ubrl","uil","uyvy","vda","vicar","vid","viff","vst","wbmp","wmf","wmv","wmz","wpg","x","x3f","xbm","xc","xcf","xpm","xps","xv","xwd","y","ycbcr","ycbcra","yuv"]; | |
$time = microtime(true); | |
$formats = array_unique(array_merge($formats, ['svg'])); | |
$time=microtime(true)-$time; | |
echo "\n merge + array_unique() to " . count($formats) . " in " . sprintf('%f', $time); | |
$time = microtime(true); | |
$formats = ArrayHelper::unique(array_merge($formats, ['svg'])); | |
$time=microtime(true)-$time; | |
echo "\n merge + ArrayHelper::unique() to " . count($formats) . " in " . sprintf('%f', $time); | |
$time = microtime(true); | |
array_push($formats, 'svg'); | |
$formats = ArrayHelper::unique($formats); | |
$time=microtime(true)-$time; | |
echo "\n push + ArrayHelper::unique() to " . count($formats) . " in " . sprintf('%f', $time); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result (on macbook pro 2017, similar on AWS EC2 R4)
https://blackfire.io/profiles/compare/189f7d6d-2a7a-4065-bf94-a266be405e2a/graph