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;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 7
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 25
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 25
Branch analysis from position: 33
Branch analysis from position: 25
Branch analysis from position: 30
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 9
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 7
Branch analysis from position: 12
Branch analysis from position: 7
Branch analysis from position: 9
filename:       /in/Otio4
function name:  (null)
number of ops:  41
compiled vars:  !0 = $runs, !1 = $t, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   ASSIGN                                                   !0, 1000000
    7     1        INIT_FCALL                                               'microtime'
          2        SEND_VAL                                                 <true>
          3        DO_ICALL                                         $4      
          4        ASSIGN                                                   !1, $4
    8     5        ASSIGN                                                   !2, 0
          6      > JMP                                                      ->10
    9     7    >   IN_ARRAY                                                 'test', <array>
          8      > JMPZ                                                     ~7, ->9
    8     9    >   PRE_INC                                                  !2
         10    >   IS_SMALLER                                               !2, !0
         11      > JMPNZ                                                    ~9, ->7
   11    12    >   INIT_FCALL                                               'microtime'
         13        SEND_VAL                                                 <true>
         14        DO_ICALL                                         $10     
         15        ASSIGN_OP                                     2          !1, $10
   12    16        ECHO                                                     'in_array%3A+'
         17        ECHO                                                     !1
         18        ECHO                                                     '%0A'
   15    19        INIT_FCALL                                               'microtime'
         20        SEND_VAL                                                 <true>
         21        DO_ICALL                                         $12     
         22        ASSIGN                                                   !1, $12
   16    23        ASSIGN                                                   !2, 0
         24      > JMP                                                      ->31
   17    25    >   INIT_FCALL                                               'preg_match'
         26        SEND_VAL                                                 '%2F%5E%28foo%7Cbar%7Cbaz%7Cfooby%7Cbario%7Cxyz%7Cabc%7Cdef%7Cghi%7Cjkl%7Cmno%7Cpqr%7Cstu%7Cvwx%29%24%2F'
         27        SEND_VAL                                                 'test'
         28        DO_ICALL                                         $15     
         29      > JMPZ                                                     $15, ->30
   16    30    >   PRE_INC                                                  !2
         31    >   IS_SMALLER                                               !2, !0
         32      > JMPNZ                                                    ~17, ->25
   19    33    >   INIT_FCALL                                               'microtime'
         34        SEND_VAL                                                 <true>
         35        DO_ICALL                                         $18     
         36        ASSIGN_OP                                     2          !1, $18
   20    37        ECHO                                                     'preg_match%3A+'
         38        ECHO                                                     !1
         39        ECHO                                                     '%0A'
         40      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.15 ms | 1400 KiB | 17 Q