PHP 8.5.0 Alpha 1 available for testing

Voting

: max(eight, nine)?
(Example: nine)

The Note You're Voting On

krdr dot mft at gmail dot com
11 years ago
I've been introduced with range() function not so long ago, and I found that examples about it is somewhat wrong, even inefficient:

<?php
$o
= "";
$time_start = microtime(true);
foreach(
range(1, 10000) as $val) {
$o .= $val;
}
$time_end = microtime(true);
$time = $time_end - $time_start;
echo
'rangein: '.$time.'<br />';

$o = "";
$time_start = microtime(true);
$a = range(1, 10000);
foreach(
$a as $val) {
$o .= $val;
}
$time_end = microtime(true);
$time = $time_end - $time_start;
echo
'rangeout: '.$time.'<br />';

?>

Which gives results:

rangein: 0.0025348663330078
rangeout: 0.0019199848175049

In some cases difference is even bigger and proportional to the range generated. I suppose that results of range() are cached/hashed.

Note: execution order does affects execution times, but difference still exists

<< Back to user notes page

To Top