diff options
author | Arnaud Le Blanc <lbarnaud@php.net> | 2011-10-18 19:42:42 +0000 |
---|---|---|
committer | Arnaud Le Blanc <lbarnaud@php.net> | 2011-10-18 19:42:42 +0000 |
commit | ea5a61e39b729b54a30b39beb45762f5ec10ec36 (patch) | |
tree | 50cc7072dfa5da1bb4442f8c009b947ee2c4faa7 /Zend/micro_bench.php | |
parent | e3c13d7961472ef839e127ce1cca36c9e9d3ec1f (diff) | |
download | php-git-ea5a61e39b729b54a30b39beb45762f5ec10ec36.tar.gz |
Improved ternary operator performance when returning arrays
Diffstat (limited to 'Zend/micro_bench.php')
-rw-r--r-- | Zend/micro_bench.php | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Zend/micro_bench.php b/Zend/micro_bench.php index 87a1b158c2..70525882eb 100644 --- a/Zend/micro_bench.php +++ b/Zend/micro_bench.php @@ -202,6 +202,35 @@ function read_str_offset($n) { } } +function issetor($n) { + $val = array(0,1,2,3,4,5,6,7,8,9); + for ($i = 0; $i < $n; ++$i) { + $x = $val ?: null; + } +} + +function issetor2($n) { + $f = false; $j = 0; + for ($i = 0; $i < $n; ++$i) { + $x = $f ?: $j + 1; + } +} + +function ternary($n) { + $val = array(0,1,2,3,4,5,6,7,8,9); + $f = false; + for ($i = 0; $i < $n; ++$i) { + $x = $f ? null : $val; + } +} + +function ternary2($n) { + $f = false; $j = 0; + for ($i = 0; $i < $n; ++$i) { + $x = $f ? $f : $j + 1; + } +} + /*****/ function empty_loop($n) { @@ -318,4 +347,12 @@ read_hash(N); $t = end_test($t, '$x = $hash[\'v\']', $overhead); read_str_offset(N); $t = end_test($t, '$x = $str[0]', $overhead); +issetor(N); +$t = end_test($t, '$x = $a ?: null', $overhead); +issetor2(N); +$t = end_test($t, '$x = $f ?: tmp', $overhead); +ternary(N); +$t = end_test($t, '$x = $f ? $f : $a', $overhead); +ternary2(N); +$t = end_test($t, '$x = $f ? $f : tmp', $overhead); total($t0, "Total"); |