3v4l.org

run code in 300+ PHP versions simultaneously
<?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));
Output for 4.3.10 - 4.3.11, 4.4.0 - 4.4.9, 5.2.1, 5.2.6 - 5.2.8, 5.2.10 - 5.2.17, 5.3.0 - 5.3.10, 5.3.14, 5.3.17 - 5.3.19, 5.3.26 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0
TERNARY: 0 IF : 0 IF/ELSE: 0
Output for 5.0.2 - 5.0.5, 5.1.0 - 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

preferences:
133.45 ms | 401 KiB | 175 Q