Skip to content

Instantly share code, notes, and snippets.

@n0f
Last active November 18, 2016 06:51
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 n0f/5225f7994b593a54499f85e6274bb062 to your computer and use it in GitHub Desktop.
Save n0f/5225f7994b593a54499f85e6274bb062 to your computer and use it in GitHub Desktop.
<?php
$array1 = range(50000, 200000);
$array2 = range(0, 100000);
shuffle($array1);
shuffle($array2);
$timeStart = microtime(true);
array_diff($array1, $array2);
$timeFinish = microtime(true);
echo '処理時間: ' . ($timeFinish - $timeStart) . '秒' . PHP_EOL;
<?php
$array1 = range(50000, 200000);
$array2 = range(0, 100000);
shuffle($array1);
shuffle($array2);
$timeStart = microtime(true);
fast_array_diff($array1, $array2);
$timeFinish = microtime(true);
echo '処理時間: ' . ($timeFinish - $timeStart) . '秒' . PHP_EOL;
function fast_array_diff()
{
return array_flip(call_user_func_array('array_diff_key', array_map('array_flip', func_get_args())));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment