Skip to content

Instantly share code, notes, and snippets.

@thr3a
Last active July 13, 2016 02:14
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 thr3a/14fb691359808441b58fc77916069f8d to your computer and use it in GitHub Desktop.
Save thr3a/14fb691359808441b58fc77916069f8d to your computer and use it in GitHub Desktop.
<?php
$diffs = array();
for ($j = 0; $j < 10; $j++) {
  for ($i = 0; $i < 10000; $i++) {
    $array[] = "test". rand(1,10);
  }
  $u_array = array();
  $start = microtime(true);
  // 方法1
  $u_array = array_unique($array);
  
  // 方法2
  // for($i = 0; $i < count($array);$i++){
  //   if(!in_array($array[$i], $u_array)){
  //     $u_array[] = $array[$i];
  //   }
  // }
  $diffs[] = microtime(true) - $start;
}
$ave = array_sum($diffs) / count($diffs); // 平均値を求めて、四捨五入する。
var_dump($ave);



//方法1
float(0.013230538368225)
//方法2
float(0.0072135925292969)
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment