Last active
June 23, 2017 16:30
-
-
Save aczietlow/39c19c9de4ba6b007d11ec1b16b02010 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
$domains = [ | |
0 => [ | |
'domain_id' => 7, | |
], | |
1 => [ | |
'domain_id' => 7, | |
], | |
2 => [ | |
'domain_id' => 7, | |
], | |
3 => [ | |
'domain_id' => 7, | |
], | |
// ... This but 8189 more times. | |
]; | |
// Method 1. | |
$time = -microtime(TRUE); | |
$correct_domains = array_unique($domains); | |
$time += microtime(TRUE); | |
echo "Deduped to " . count($correct_domains) . " in " . $time . "seconds."; | |
// Deduped to 80 in 160.97429418564 seconds. | |
// Method 2. | |
$time = -microtime(TRUE); | |
$correct_domains2 = []; | |
foreach ($domains as $key => $domain) { | |
$correct_domains2[$domain] = TRUE; | |
} | |
$correct_domains2 = array_keys($correct_domains2); | |
$time += microtime(TRUE); | |
echo "deduped to " . count($correct_domains2) . " in " . $time . "seconds."; | |
// Deduped to 80 in 7.2383348941803 seconds. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment