3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $context = array('test' => array()); // optionally fill-in the test value with lots of data for ($i = 0; $i < 100000; $i++) { $context['test'][$i] = $i; } // you can also just create a big string // $context = str_repeat(' ', 1000000); // benchmark $time = microtime(true); for ($i = 0; $i < 100; $i++) { // the snippet of code to benchmark $tmp = isset($context['test']) ? $context['test'] : ''; } printf("TERNARY: %0.2d\n", (microtime(true) - $time) * 1000) . PHP_EOL; // benchmark $time = microtime(true); for ($i = 0; $i < 100; $i++) { // the snippet of code to benchmark $tmp = ''; if (isset($context['test'])) { $tmp = $context['test']; } } printf("IF : %0.2d\n", (microtime(true) - $time) * 1000); // benchmark $time = microtime(true); for ($i = 0; $i < 100; $i++) { // the snippet of code to benchmark if (isset($context['test'])) { $tmp = $context['test']; } else { $tmp = ''; } } printf("IF/ELSE: %0.2d\n", (microtime(true) - $time) * 1000);
based on R19R7
Output for 5.4.0 - 7.1.7, 7.2.0
TERNARY: 0 IF : 0 IF/ELSE: 0
Output for 5.2.0, 7.1.10

Process exited with code 137.
Output for 5.3.29
TERNARY: 757 IF : 6 IF/ELSE: 0
Output for 5.3.28
TERNARY: 754 IF : 5 IF/ELSE: 0
Output for 5.3.27
TERNARY: 771 IF : 5 IF/ELSE: 0
Output for 5.3.26
TERNARY: 758 IF : 5 IF/ELSE: 0
Output for 5.3.25
TERNARY: 842 IF : 5 IF/ELSE: 0
Output for 5.3.24
TERNARY: 775 IF : 5 IF/ELSE: 0
Output for 5.2.13, 5.3.23
TERNARY: 759 IF : 4 IF/ELSE: 0
Output for 5.3.4, 5.3.22
TERNARY: 794 IF : 5 IF/ELSE: 0
Output for 5.3.21
TERNARY: 834 IF : 5 IF/ELSE: 0
Output for 5.3.20
TERNARY: 784 IF : 5 IF/ELSE: 0
Output for 5.3.19
TERNARY: 765 IF : 4 IF/ELSE: 0
Output for 5.3.3, 5.3.18
TERNARY: 781 IF : 5 IF/ELSE: 0
Output for 5.3.17
TERNARY: 762 IF : 5 IF/ELSE: 0
Output for 5.3.16
TERNARY: 789 IF : 5 IF/ELSE: 0
Output for 5.3.15
TERNARY: 857 IF : 5 IF/ELSE: 0
Output for 5.3.14
TERNARY: 783 IF : 5 IF/ELSE: 0
Output for 5.3.13
TERNARY: 797 IF : 4 IF/ELSE: 0
Output for 5.3.12
TERNARY: 779 IF : 5 IF/ELSE: 0
Output for 5.3.11
TERNARY: 788 IF : 5 IF/ELSE: 0
Output for 5.3.10
TERNARY: 825 IF : 5 IF/ELSE: 0
Output for 5.3.9
TERNARY: 815 IF : 4 IF/ELSE: 0
Output for 5.3.8
TERNARY: 843 IF : 5 IF/ELSE: 0
Output for 5.3.7
TERNARY: 777 IF : 5 IF/ELSE: 0
Output for 5.3.6
TERNARY: 802 IF : 5 IF/ELSE: 0
Output for 5.3.5
TERNARY: 807 IF : 5 IF/ELSE: 0
Output for 5.3.2
TERNARY: 801 IF : 5 IF/ELSE: 0
Output for 5.3.1
TERNARY: 819 IF : 5 IF/ELSE: 0
Output for 5.3.0
TERNARY: 815 IF : 5 IF/ELSE: 0
Output for 5.2.17
TERNARY: 764 IF : 3 IF/ELSE: 0
Output for 5.2.16
TERNARY: 799 IF : 4 IF/ELSE: 0
Output for 5.2.15
TERNARY: 810 IF : 6 IF/ELSE: 0
Output for 5.2.14
TERNARY: 875 IF : 3 IF/ELSE: 0
Output for 5.2.12
TERNARY: 792 IF : 4 IF/ELSE: 0
Output for 5.2.11
TERNARY: 790 IF : 4 IF/ELSE: 0
Output for 5.2.10
TERNARY: 776 IF : 3 IF/ELSE: 0
Output for 5.2.9
TERNARY: 779 IF : 4 IF/ELSE: 0
Output for 5.2.8
TERNARY: 882 IF : 5 IF/ELSE: 0
Output for 5.2.7
TERNARY: 768 IF : 4 IF/ELSE: 0
Output for 5.2.6
TERNARY: 811 IF : 4 IF/ELSE: 0
Output for 5.2.5
TERNARY: 1156 IF : 5 IF/ELSE: 0
Output for 5.2.4
TERNARY: 1113 IF : 5 IF/ELSE: 0
Output for 5.2.3
TERNARY: 1079 IF : 5 IF/ELSE: 0
Output for 5.2.2
TERNARY: 1099 IF : 5 IF/ELSE: 0
Output for 5.2.1
TERNARY: 570 IF : 3 IF/ELSE: 0
Output for 5.1.6
TERNARY: 1083 IF : 5 IF/ELSE: 0
Output for 5.1.5
TERNARY: 1073 IF : 6 IF/ELSE: 0
Output for 5.1.4
TERNARY: 1142 IF : 5 IF/ELSE: 0
Output for 5.1.3
TERNARY: 1042 IF : 5 IF/ELSE: 0
Output for 5.1.2
TERNARY: 1101 IF : 5 IF/ELSE: 0
Output for 5.1.1
TERNARY: 1169 IF : 5 IF/ELSE: 0
Output for 5.1.0
TERNARY: 1148 IF : 5 IF/ELSE: 0
Output for 5.0.5
TERNARY: 1179 IF : 5 IF/ELSE: 0
Output for 5.0.4
TERNARY: 1111 IF : 6 IF/ELSE: 0
Output for 5.0.3
TERNARY: 1137 IF : 6 IF/ELSE: 0
Output for 5.0.2
TERNARY: 1108 IF : 6 IF/ELSE: 0
Output for 5.0.1
TERNARY: 1125 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/2BuYM on line 18 IF : 4 IF/ELSE: 0
Output for 5.0.0
TERNARY: 1066 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/2BuYM on line 18 IF : 5 IF/ELSE: 0
Output for 4.4.9
TERNARY: 112 IF : 4 IF/ELSE: 0
Output for 4.4.1, 4.4.8
TERNARY: 118 IF : 4 IF/ELSE: 0
Output for 4.4.7
TERNARY: 234 IF : 4 IF/ELSE: 0
Output for 4.4.6
TERNARY: 71 IF : 4 IF/ELSE: 0
Output for 4.4.5
TERNARY: -906 IF : 4 IF/ELSE: 0
Output for 4.4.4
TERNARY: 57 IF : 4 IF/ELSE: 0
Output for 4.4.3
TERNARY: 117 IF : 4 IF/ELSE: 0
Output for 4.4.2
TERNARY: 91 IF : 5 IF/ELSE: 0
Output for 4.4.0
TERNARY: -868 IF : 5 IF/ELSE: 0
Output for 4.3.11
TERNARY: 138 IF : 5 IF/ELSE: 0
Output for 4.3.10
TERNARY: 101 IF : 4 IF/ELSE: 0
Output for 4.3.9
TERNARY: 188 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/2BuYM on line 18 IF : 5 IF/ELSE: 0
Output for 4.3.8
TERNARY: 74 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/2BuYM on line 18 IF : 4 IF/ELSE: 0
Output for 4.3.7
TERNARY: -859 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/2BuYM on line 18 IF : 5 IF/ELSE: 0
Output for 4.3.6
TERNARY: 148 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/2BuYM on line 18 IF : 4 IF/ELSE: 0
Output for 4.3.5
TERNARY: 51 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/2BuYM on line 18 IF : 4 IF/ELSE: 0
Output for 4.3.4
TERNARY: 64 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/2BuYM on line 18 IF : 4 IF/ELSE: 0
Output for 4.3.3
TERNARY: 60 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/2BuYM on line 18 IF : 4 IF/ELSE: 0
Output for 4.3.2
TERNARY: 105 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/2BuYM on line 18 IF : -993 IF/ELSE: 0
Output for 4.3.1
TERNARY: 185 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/2BuYM on line 18 IF : 4 IF/ELSE: 0
Output for 4.3.0
TERNARY: -791 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/2BuYM on line 18 IF : 4 IF/ELSE: 0