- microtime: documentation ( source)
- range: documentation ( source)
<?php
class inConstruct {
function __construct($array) {
foreach ($array as $key => $value) {
if ($key == 100) {
echo "Done";
}
}
}
}
class inMethod {
function __construct($array) {
$this->doThat($array);
}
function doThat($array){
foreach ($array as $key => $value) {
if ($key == 100) {
echo "Done";
}
}
}
}
$questions = range("a", "z", 1);
for($i=0;$i<10;$i++) {}
$start = microtime();
## For inMethod
for ($i=0; $i < 1000; $i++) {
$m = new inConstruct($questions);
unset($m);
}
echo (microtime() - $start);
echo "\n";
$start = microtime();
## For inConstruct
for ($i=0; $i < 1000; $i++) {
$m = new inMethod($questions);
unset($m);
}
echo (microtime() - $start);