Skip to content

Instantly share code, notes, and snippets.

@aczietlow
Last active June 23, 2017 16:30
Show Gist options
  • Save aczietlow/39c19c9de4ba6b007d11ec1b16b02010 to your computer and use it in GitHub Desktop.
Save aczietlow/39c19c9de4ba6b007d11ec1b16b02010 to your computer and use it in GitHub Desktop.
<?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