3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php define('ITERATIONS', 1000 * 1000); function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } function keywordsWithoutMatch() { return "value1|value2|cat|dog|Plan du scénario|Plan du Scénario"; } function keywordsWithMatch() { return "test|Lëtzebuergesch|Forgatókönyv|Pirate"; } $native = "Pirate"; function benchmarkInArray($native) { for ($i = 0; $i < ITERATIONS; $i++) { $keywordTypes = array( 'Given' => explode('|', keywordsWithoutMatch()), 'When' => explode('|', keywordsWithoutMatch()), 'Then' => explode('|', keywordsWithoutMatch()), 'And' => explode('|', keywordsWithoutMatch()), 'But' => explode('|', keywordsWithMatch()) ); foreach ($keywordTypes as $type => $keywords) { if (in_array($native, $keywords) || in_array($native . '<', $keywords)) { if ($type != 'But') throw new Exception(); break; } } } } function benchmarkInArrayWithCache($native) { $keywordTypes = array( 'Given' => explode('|', keywordsWithoutMatch()), 'When' => explode('|', keywordsWithoutMatch()), 'Then' => explode('|', keywordsWithoutMatch()), 'And' => explode('|', keywordsWithoutMatch()), 'But' => explode('|', keywordsWithMatch()) ); for ($i = 0; $i < ITERATIONS; $i++) { foreach ($keywordTypes as $type => $keywords) { if (in_array($native, $keywords) || in_array($native . '<', $keywords)) { if ($type != 'But') throw new Exception(); break; } } } } function benchmarkMbStrpos($native) { for ($i = 0; $i < ITERATIONS; $i++) { $keywordTypes = array( 'Given' => keywordsWithoutMatch(), 'When' => keywordsWithoutMatch(), 'Then' => keywordsWithoutMatch(), 'And' => keywordsWithoutMatch(), 'But' => keywordsWithMatch() ); foreach ($keywordTypes as $type => $keywords) { if (false !== mb_strpos($keywords, $native)) { if ($type != 'But') throw new Exception(); break; } } } } function benchmarkMbStrposWithCache($native) { $keywordTypes = array( 'Given' => keywordsWithoutMatch(), 'When' => keywordsWithoutMatch(), 'Then' => keywordsWithoutMatch(), 'And' => keywordsWithoutMatch(), 'But' => keywordsWithMatch() ); for ($i = 0; $i < ITERATIONS; $i++) { foreach ($keywordTypes as $type => $keywords) { if (false !== mb_strpos($keywords, $native)) { if ($type != 'But') throw new Exception(); break; } } } } $time_start = microtime_float(); benchmarkInArray($native); echo "benchmark in_array: " . (microtime_float() - $time_start) . "\n"; $time_start = microtime_float(); benchmarkInArrayWithCache($native); echo "benchmark in_array with cache: " . (microtime_float() - $time_start) . "\n"; $time_start = microtime_float(); benchmarkMbStrpos($native); echo "benchmark mb_strpos: " . (microtime_float() - $time_start) . "\n"; $time_start = microtime_float(); benchmarkMbStrposWithCache($native); echo "benchmark mb_strpos with cache: " . (microtime_float() - $time_start) . "\n";
Output for 7.1.0
benchmark in_array: 1.5154449939728 benchmark in_array with cache: 0.12790584564209
Process exited with code 137.
Output for 7.0.14
benchmark in_array: 1.2593200206757 benchmark in_array with cache: 0.85756802558899
Process exited with code 137.
Output for 7.0.6
benchmark in_array: 1.5208270549774 benchmark in_array with cache: 0.4356050491333
Process exited with code 137.
Output for 7.0.5
benchmark in_array: 1.5088338851929 benchmark in_array with cache: 0.43057203292847
Process exited with code 137.
Output for 7.0.4
benchmark in_array: 1.4954302310944 benchmark in_array with cache: 0.40983605384827
Process exited with code 137.
Output for 7.0.3
benchmark in_array: 1.8754210472107 benchmark in_array with cache: 0.42122197151184
Process exited with code 137.
Output for 7.0.2
benchmark in_array: 1.9067859649658 benchmark in_array with cache: 0.439297914505
Process exited with code 137.
Output for 7.0.1
benchmark in_array: 1.9054110050201 benchmark in_array with cache: 0.42436599731445
Process exited with code 137.
Output for 7.0.0
benchmark in_array: 1.9694669246674 benchmark in_array with cache: 0.41355991363525
Process exited with code 137.
Output for 5.0.0 - 5.6.28, hhvm-3.10.0 - 3.12.0

Process exited with code 137.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_NEW in /in/4QWHv on line 36
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_NEW in /in/4QWHv on line 36
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/4QWHv on line 36
Process exited with code 255.