3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Compare building an array an in_array()ing it, vs a regex check */ $runs = 1000000; // in_array $t = microtime(true); for ($i = 0; $i < $runs; $i++) { if (in_array('test', ['foo','bar','baz','fooby','bario','xyz','abc','def','ghi','jkl','mno','pqr','stu','vwx'])); } $t -= microtime(true); echo 'in_array: ', $t, PHP_EOL; // preg_match $t = microtime(true); for ($i = 0; $i < $runs; $i++) { if (preg_match('/^(foo|bar|baz|fooby|bario|xyz|abc|def|ghi|jkl|mno|pqr|stu|vwx)$/', 'test')); } $t -= microtime(true); echo 'preg_match: ', $t, PHP_EOL;
Output for 7.2.0
in_array: -0.014294862747192 preg_match: -0.095752000808716
Output for 7.1.7
in_array: -0.05136513710022 preg_match: -0.10431504249573
Output for 7.1.6
in_array: -0.077932834625244 preg_match: -0.11696696281433
Output for 7.1.5
in_array: -0.074207067489624 preg_match: -0.10418295860291
Output for 7.1.0
in_array: -0.074716806411743 preg_match: -0.11993718147278
Output for 7.0.20
in_array: -0.13023519515991 preg_match: -0.10159111022949
Output for 7.0.14
in_array: -0.16079592704773 preg_match: -0.12076902389526
Output for 7.0.6
in_array: -0.12755799293518 preg_match: -0.1504008769989
Output for 7.0.5
in_array: -0.1316089630127 preg_match: -0.15403509140015
Output for 7.0.4
in_array: -0.12917995452881 preg_match: -0.098889112472534
Output for 7.0.3
in_array: -0.12144899368286 preg_match: -0.14871907234192
Output for 7.0.2
in_array: -0.1296010017395 preg_match: -0.15266799926758
Output for 7.0.1
in_array: -0.10826587677002 preg_match: -0.15352010726929
Output for 7.0.0
in_array: -0.1070499420166 preg_match: -0.15339112281799
Output for 5.6.28
in_array: -1.0641541481018 preg_match: 0.52768397331238
Output for 5.6.21
in_array: -1.0280609130859 preg_match: -0.527676820755
Output for 5.6.20
in_array: -1.031368970871 preg_match: -0.53633499145508
Output for 5.6.19
in_array: -1.0384349822998 preg_match: -0.48123216629028
Output for 5.6.18
in_array: -1.0122289657593 preg_match: -0.47649312019348
Output for 5.6.17
in_array: -1.0244262218475 preg_match: -0.54034996032715
Output for 5.6.16
in_array: -1.0110349655151 preg_match: -0.53808188438416
Output for 5.6.15
in_array: -1.0395019054413 preg_match: -0.53460288047791
Output for 5.6.14
in_array: -1.2369389533997 preg_match: -0.63125801086426
Output for 5.6.13
in_array: -1.0530149936676 preg_match: -0.52678298950195
Output for 5.6.12
in_array: -1.04944896698 preg_match: -0.5408399105072
Output for 5.6.11
in_array: -1.046324968338 preg_match: -0.52812194824219
Output for 5.6.10
in_array: -1.0354878902435 preg_match: -0.53575301170349
Output for 5.6.9
in_array: -1.0725588798523 preg_match: -0.54158401489258
Output for 5.6.8
in_array: -1.0504188537598 preg_match: -0.54069185256958
Output for 5.6.7
in_array: -1.0848639011383 preg_match: -0.47170805931091
Output for 5.5.35
in_array: -1.0305027961731 preg_match: -0.46408104896545
Output for 5.5.34
in_array: -1.0439269542694 preg_match: -0.54554295539856
Output for 5.5.33
in_array: -1.062716960907 preg_match: -0.48586988449097
Output for 5.5.32
in_array: -1.0461828708649 preg_match: -0.54784607887268
Output for 5.5.31
in_array: -1.0602428913116 preg_match: -0.54479813575745
Output for 5.5.30
in_array: -1.0393669605255 preg_match: -0.54981207847595
Output for 5.5.29
in_array: -1.0957601070404 preg_match: -0.54979801177979
Output for 5.5.28
in_array: -1.0777850151062 preg_match: -0.54485201835632
Output for 5.5.27
in_array: -1.073853969574 preg_match: -0.54305505752563
Output for 5.5.26
in_array: -1.1393339633942 preg_match: -0.57292795181274
Output for 5.5.25
in_array: -1.0566110610962 preg_match: -0.55765581130981
Output for 5.5.24
in_array: -0.8777539730072 preg_match: -0.46493792533875
Output for 5.4.45
in_array: -1.7948729991913
Process exited with code 137.
Output for 5.4.44
in_array: -1.6754100322723 preg_match: -0.66508913040161
Output for 5.4.43
in_array: -1.5605227947235 preg_match: -0.67873287200928
Output for 5.4.42
in_array: -1.7660980224609
Process exited with code 137.
Output for 5.4.41
in_array: -1.7560632228851
Process exited with code 137.
Output for 5.4.40
in_array: -1.5154449939728 preg_match: -0.63688182830811
Output for 5.4.39
in_array: -1.4673111438751 preg_match: -0.63295316696167
Output for 5.4.38
in_array: -1.5229279994965 preg_match: -0.66193890571594
Output for 5.4.37
in_array: -1.2686259746552 preg_match: -0.62600016593933
Output for 5.4.36
in_array: -1.3647611141205 preg_match: -0.5985279083252
Output for 5.4.35
in_array: -1.739825963974
Process exited with code 137.
Output for 5.4.34
in_array: -1.6023969650269
Process exited with code 137.
Output for 5.4.32
in_array: -1.1558439731598 preg_match: -0.48345112800598
Output for 5.4.31
in_array: -1.4228229522705
Process exited with code 137.
Output for 5.4.30
in_array: -1.2436909675598 preg_match: -0.54377603530884
Output for 5.4.29
in_array: -1.2365510463715 preg_match: -0.51516890525818
Output for 5.4.28
in_array: -1.2614347934723 preg_match: -0.67202806472778
Output for 5.4.27
in_array: -1.2080919742584 preg_match: -0.65146803855896
Output for 5.4.26
in_array: -1.1846249103546 preg_match: -0.53298497200012
Output for 5.4.25
in_array: -1.1483190059662 preg_match: -0.52936697006226
Output for 5.4.24
in_array: -1.1529700756073 preg_match: -0.56140613555908
Output for 5.4.23
in_array: -1.1653881072998 preg_match: -0.60493993759155
Output for 5.4.22
in_array: -1.171159029007 preg_match: -0.5149450302124
Output for 5.4.21
in_array: -1.1429779529572 preg_match: -0.51177716255188
Output for 5.4.20
in_array: -1.2507948875427
Process exited with code 137.
Output for 5.4.19
in_array: -1.7227261066437
Process exited with code 137.
Output for 5.4.18
in_array: -1.2527680397034 preg_match: -0.5889630317688
Output for 5.4.17
in_array: -1.1962831020355 preg_match: -0.56001400947571
Output for 5.4.16
in_array: -1.3025560379028 preg_match: -0.64549994468689
Output for 5.4.15
in_array: -1.1495358943939 preg_match: -0.63463306427002
Output for 5.4.14
in_array: -1.2034809589386 preg_match: -0.52116703987122
Output for 5.4.13
in_array: -1.1687269210815 preg_match: -0.52021598815918
Output for 5.4.12
in_array: -1.2238121032715 preg_match: -0.55267214775085
Output for 5.4.11
in_array: -1.2597148418427 preg_match: -0.56256198883057
Output for 5.4.10
in_array: -1.2724471092224 preg_match: -0.56321096420288
Output for 5.4.9
in_array: -1.2501571178436 preg_match: -0.55561399459839
Output for 5.4.8
in_array: -1.2404410839081 preg_match: -0.66085720062256
Output for 5.4.7
in_array: -1.2607510089874 preg_match: -0.57742500305176
Output for 5.4.6
in_array: -1.3159210681915 preg_match: -0.54588007926941
Output for 5.4.5
in_array: -1.2464880943298 preg_match: -0.56720280647278
Output for 5.4.4
in_array: -1.2550909519196 preg_match: -0.55962419509888
Output for 5.4.3
in_array: -1.2800369262695 preg_match: -0.54946088790894
Output for 5.4.2
in_array: -1.4271371364594
Process exited with code 137.
Output for 5.4.1
in_array: -1.2561738491058 preg_match: -0.56412291526794
Output for 5.4.0
in_array: -1.2614090442657 preg_match: -0.5766749382019
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/Otio4 on line 9
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/Otio4 on line 9
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/Otio4 on line 9
Process exited with code 255.

preferences:
152.7 ms | 401 KiB | 175 Q