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 - 5.6.38, hhvm-3.10.1 - 3.22.0, 7.0.0 - 7.2.0, 7.2.2 - 7.2.9, 7.2.11 - 7.3.1
TERNARY: 0 IF : 0 IF/ELSE: 0
Output for 7.2.10
TERNARY: 19 IF : 0 IF/ELSE: 0
Output for 7.2.1
TERNARY: 16 IF : 0 IF/ELSE: 0
Output for 5.3.29
TERNARY: 737 IF : 6 IF/ELSE: 0
Output for 5.3.28
TERNARY: 734 IF : 5 IF/ELSE: 0
Output for 5.3.27
TERNARY: 765 IF : 5 IF/ELSE: 0
Output for 5.3.26
TERNARY: 757 IF : 5 IF/ELSE: 0
Output for 5.3.25
TERNARY: 836 IF : 5 IF/ELSE: 0
Output for 5.3.0, 5.3.17, 5.3.24
TERNARY: 766 IF : 5 IF/ELSE: 0
Output for 5.3.23
TERNARY: 794 IF : 4 IF/ELSE: 0
Output for 5.3.22
TERNARY: 780 IF : 4 IF/ELSE: 0
Output for 5.3.21
TERNARY: 811 IF : 5 IF/ELSE: 0
Output for 5.3.20
TERNARY: 792 IF : 5 IF/ELSE: 0
Output for 5.3.19
TERNARY: 846 IF : 5 IF/ELSE: 0
Output for 5.3.18
TERNARY: 785 IF : 6 IF/ELSE: 0
Output for 5.3.16
TERNARY: 789 IF : 5 IF/ELSE: 0
Output for 5.3.15
TERNARY: 793 IF : 7 IF/ELSE: 0
Output for 5.3.14
TERNARY: 868 IF : 7 IF/ELSE: 0
Output for 5.3.13
TERNARY: 776 IF : 4 IF/ELSE: 0
Output for 5.3.12
TERNARY: 797 IF : 4 IF/ELSE: 0
Output for 5.3.6, 5.3.11
TERNARY: 797 IF : 5 IF/ELSE: 0
Output for 5.3.10
TERNARY: 788 IF : 4 IF/ELSE: 0
Output for 5.3.9
TERNARY: 808 IF : 5 IF/ELSE: 0
Output for 5.3.8
TERNARY: 860 IF : 5 IF/ELSE: 0
Output for 5.3.7
TERNARY: 795 IF : 5 IF/ELSE: 0
Output for 5.3.5
TERNARY: 787 IF : 5 IF/ELSE: 0
Output for 5.3.4
TERNARY: 754 IF : 5 IF/ELSE: 0
Output for 5.3.3
TERNARY: 753 IF : 4 IF/ELSE: 0
Output for 5.3.2
TERNARY: 834 IF : 5 IF/ELSE: 0
Output for 5.3.1
TERNARY: 751 IF : 5 IF/ELSE: 0
Output for 5.2.17
TERNARY: 806 IF : 3 IF/ELSE: 0
Output for 5.2.16
TERNARY: 869 IF : 4 IF/ELSE: 0
Output for 5.2.15
TERNARY: 850 IF : 5 IF/ELSE: 0
Output for 5.2.14
TERNARY: 759 IF : 3 IF/ELSE: 0
Output for 5.2.13
TERNARY: 761 IF : 3 IF/ELSE: 0
Output for 5.2.12
TERNARY: 785 IF : 4 IF/ELSE: 0
Output for 5.2.11
TERNARY: 774 IF : 3 IF/ELSE: 0
Output for 5.2.10
TERNARY: 793 IF : 4 IF/ELSE: 0
Output for 5.2.7, 5.2.9
TERNARY: 765 IF : 4 IF/ELSE: 0
Output for 5.2.8
TERNARY: 766 IF : 4 IF/ELSE: 0
Output for 5.2.6
TERNARY: 768 IF : 4 IF/ELSE: 0
Output for 5.2.5
TERNARY: 1023 IF : 5 IF/ELSE: 0
Output for 5.2.4
TERNARY: 943 IF : 4 IF/ELSE: 0
Output for 5.2.3
TERNARY: 900 IF : 5 IF/ELSE: 0
Output for 5.2.2
TERNARY: 900 IF : 4 IF/ELSE: 0
Output for 5.2.1
TERNARY: 544 IF : 2 IF/ELSE: 0
Output for 5.2.0
TERNARY: 1706 IF : 3 IF/ELSE: 0
Output for 5.1.6
TERNARY: 1066 IF : 5 IF/ELSE: 0
Output for 5.1.5
TERNARY: 1068 IF : 5 IF/ELSE: 0
Output for 5.1.4
TERNARY: 1120 IF : 5 IF/ELSE: 0
Output for 5.1.3
TERNARY: 1095 IF : 5 IF/ELSE: 0
Output for 5.1.2
TERNARY: 1251 IF : 5 IF/ELSE: 0
Output for 5.1.1
TERNARY: 1229 IF : 5 IF/ELSE: 0
Output for 5.1.0
TERNARY: 1175 IF : 5 IF/ELSE: 0
Output for 5.0.5
TERNARY: 1140 IF : 6 IF/ELSE: 0
Output for 5.0.4
TERNARY: 1148 IF : 8 IF/ELSE: 0
Output for 5.0.3
TERNARY: 1137 IF : 6 IF/ELSE: 0
Output for 5.0.2
TERNARY: 1220 IF : 7 IF/ELSE: 0
Output for 5.0.1
TERNARY: 1161 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/2BuYM on line 18 IF : 6 IF/ELSE: 0
Output for 5.0.0
TERNARY: 1165 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: 223 IF : 4 IF/ELSE: 0
Output for 4.4.8
TERNARY: 108 IF : 4 IF/ELSE: 0
Output for 4.4.7
TERNARY: 235 IF : 4 IF/ELSE: 0
Output for 4.4.6
TERNARY: 161 IF : 4 IF/ELSE: 0
Output for 4.4.5
TERNARY: 380 IF : 4 IF/ELSE: 0
Output for 4.4.4
TERNARY: 131 IF : 4 IF/ELSE: 0
Output for 4.4.3
TERNARY: 148 IF : 4 IF/ELSE: 0
Output for 4.4.2
TERNARY: 134 IF : 4 IF/ELSE: 0
Output for 4.4.1
TERNARY: 244 IF : 5 IF/ELSE: 0
Output for 4.4.0
TERNARY: 265 IF : 4 IF/ELSE: 0
Output for 4.3.11
TERNARY: 124 IF : 4 IF/ELSE: 0
Output for 4.3.10
TERNARY: 147 IF : 4 IF/ELSE: 0
Output for 4.3.9
TERNARY: 124 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.8
TERNARY: 138 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: 262 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.6
TERNARY: 241 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: 118 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.4
TERNARY: 150 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: 156 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: 245 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/2BuYM on line 18 IF : 6 IF/ELSE: 0
Output for 4.3.1
TERNARY: 252 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: 53 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/2BuYM on line 18 IF : 4 IF/ELSE: 0