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/68b822dd8a953dd91a77240492729321 to your computer and use it in GitHub Desktop.
Save n0f/68b822dd8a953dd91a77240492729321 to your computer and use it in GitHub Desktop.
<?php
$array1 = range(50000, 200000);
$array2 = range(0, 100000);
$array3 = range(150000, 250000);
shuffle($array1);
shuffle($array2);
shuffle($array3);
$timeStart = microtime(true);
array_diff($array1, $array2, $array3);
$timeFinish = microtime(true);
echo '処理時間: ' . ($timeFinish - $timeStart) . '秒' . PHP_EOL;
<?php
$array1 = range(50000, 200000);
$array2 = range(0, 100000);
$array3 = range(150000, 250000);
shuffle($array1);
shuffle($array2);
shuffle($array3);
$timeStart = microtime(true);
fast_array_diff($array1, $array2, $array3);
$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