<?php $sos = new SplObjectStorage(); $arr = array(); $docs = array(); $iterations = 50000; for ($i = 0; $i < $iterations; ++$i) { $doc = new DOMDocument(); $docs[] = $doc; } $mem_empty = memory_get_usage(); // Load the SplObjectStorage $start = microtime(true); foreach ($docs as $d) { $sos->attach($d); //$sos[$d] = 1; } $finis = microtime(true); $time_to_fill = $finis - $start; // Check membership on the object storage $start = microtime(true); foreach ($docs as $d) { $sos->contains($d); //isset($sos[$d]); } $finis = microtime(true); $time_to_check = $finis - $start; $mem_spl = memory_get_usage(); $mem_used = $mem_spl - $mem_empty; printf("SplObjectStorage:\nTime to fill: %0.12f ms\nTime to check: %0.12f ms\nMemory: %d\n\n", $time_to_fill * 1000, $time_to_check * 1000, $mem_used); unset($sos); $mem_empty = memory_get_usage(); // Load the array $start = microtime(true); foreach ($docs as $d) { $arr[spl_object_id($d)] = $d; } $finis = microtime(true); $time_to_fill = $finis - $start; // Check membership on the array $start = microtime(true); foreach ($docs as $d) { isset($arr[spl_object_id($d)]); } $finis = microtime(true); $time_to_check = $finis - $start; $mem_arr = memory_get_usage(); $mem_used = $mem_arr - $mem_empty; printf("Arrays:\nTime to fill: %0.12f ms\nTime to check: %0.12f ms\nMemory: %d\n\n", $time_to_fill * 1000, $time_to_check * 1000, $mem_used);
You have javascript disabled. You will not be able to edit any code.