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.5d\n", (microtime(true) - $time)) . 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.5d\n", (microtime(true) - $time)); // 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.5d\n", (microtime(true) - $time));
based on 2BuYM
Output for 4.3.10 - 4.4.9, 5.2.1, 5.2.6 - 5.2.8, 5.2.10 - 5.3.10, 5.3.14, 5.3.17 - 5.3.19, 5.3.26 - 7.2.0
TERNARY: 0 IF : 0 IF/ELSE: 0
Output for 5.0.2 - 5.1.6, 5.2.2 - 5.2.5, 5.2.9, 5.3.11 - 5.3.13, 5.3.15 - 5.3.16, 5.3.20 - 5.3.25
TERNARY: 1 IF : 0 IF/ELSE: 0
Output for 5.2.0
TERNARY: 2 IF : 0 IF/ELSE: 0
Process exited with code 137.
Output for 5.0.0 - 5.0.1
TERNARY: 1 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/M45Ai on line 18 IF : 0 IF/ELSE: 0
Output for 4.3.0 - 4.3.9
TERNARY: 0 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/M45Ai on line 18 IF : 0 IF/ELSE: 0