コード例 #1
0
<?php

ini_set("memory_limit", "-1");
set_time_limit(0);
require_once "src/BinaryTree.class.php";
$tree = new BinaryTree();
$test_values = array();
$limit = 1000000;
for ($i = 0; $i < $limit; $i++) {
    $test_values[] = mt_rand(1, 1000000);
}
$test_values = array_values(array_unique($test_values));
foreach ($test_values as $value) {
    $node = new BTNode($value);
    $tree->add($node);
}
$needle = $test_values[mt_rand(0, count($test_values) - 1)];
$time1 = -microtime(true);
array_search($needle, $test_values);
$time1 += microtime(true);
echo $time1 * 1000;
echo "</br>------------------------</br>";
$time2 = -microtime(true);
$tree->search($needle);
$time2 += microtime(true);
echo $time2 * 1000;
echo "</br>------------------------</br>";
echo $time1 * 100 / $time2 . "%";