3v4l.org

run code in 300+ PHP versions simultaneously
<?php function elapsed_time(array $start) { $now = explode(' ', microtime()); $deltasec = $now[1] - $start[1]; $deltamsec = (float)$now[0] - (float)$start[0]; return $deltasec + $deltamsec; } $str = 'This thing should output _$this_key$_ and also _$this_one$_ so that I can match it with an array!'; $replacements = [ 'this_key' => 'love', 'this_one' => 'more love' ]; $start = '_$'; $end = '$_'; $new_reps = array(); $starttime = explode(' ', microtime()); for ($i = 0; $i < 10000; $i++) { foreach ($replacements as $key => $value) { $new_reps["_\$$key\$_"] = $value; } $output = strtr($str, $new_reps); } echo "$output\n"; echo "strtr: " . elapsed_time($starttime) . "\n"; $replacements = [ 'this_key' => 'love', 'this_one' => 'more love' ]; $starttime = explode(' ', microtime()); for ($i = 0; $i < 10000; $i++) { $replaced = preg_replace_callback('/_\$([^$]+)\$_/', function($matches) use ($replacements) { return $replacements[$matches[1]]; }, $str); } echo "preg_replace: " . elapsed_time($starttime) . "\n"; echo "$replaced\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 14
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 60
Branch analysis from position: 60
2 jumps found. (Code = 44) Position 1 = 62, Position 2 = 51
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 62, Position 2 = 51
Branch analysis from position: 62
Branch analysis from position: 51
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 23
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 23
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 14
Branch analysis from position: 32
Branch analysis from position: 14
Branch analysis from position: 23
filename:       /in/uP97b
function name:  (null)
number of ops:  72
compiled vars:  !0 = $str, !1 = $replacements, !2 = $start, !3 = $end, !4 = $new_reps, !5 = $starttime, !6 = $i, !7 = $value, !8 = $key, !9 = $output, !10 = $replaced
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   ASSIGN                                                   !0, 'This+thing+should+output+_%24this_key%24_+and+also+_%24this_one%24_+so+that+I+can+match+it+with+an+array%21'
   11     1        ASSIGN                                                   !1, <array>
   15     2        ASSIGN                                                   !2, '_%24'
   16     3        ASSIGN                                                   !3, '%24_'
   17     4        ASSIGN                                                   !4, <array>
   19     5        INIT_FCALL                                               'explode'
          6        SEND_VAL                                                 '+'
          7        INIT_FCALL                                               'microtime'
          8        DO_ICALL                                         $16     
          9        SEND_VAR                                                 $16
         10        DO_ICALL                                         $17     
         11        ASSIGN                                                   !5, $17
   20    12        ASSIGN                                                   !6, 0
         13      > JMP                                                      ->30
   21    14    > > FE_RESET_R                                       $20     !1, ->23
         15    > > FE_FETCH_R                                       ~21     $20, !7, ->23
         16    >   ASSIGN                                                   !8, ~21
   22    17        ROPE_INIT                                     3  ~24     '_%24'
         18        ROPE_ADD                                      1  ~24     ~24, !8
         19        ROPE_END                                      2  ~23     ~24, '%24_'
         20        ASSIGN_DIM                                               !4, ~23
         21        OP_DATA                                                  !7
   21    22      > JMP                                                      ->15
         23    >   FE_FREE                                                  $20
   24    24        INIT_FCALL                                               'strtr'
         25        SEND_VAR                                                 !0
         26        SEND_VAR                                                 !4
         27        DO_ICALL                                         $27     
         28        ASSIGN                                                   !9, $27
   20    29        PRE_INC                                                  !6
         30    >   IS_SMALLER                                               !6, 10000
         31      > JMPNZ                                                    ~30, ->14
   26    32    >   NOP                                                      
         33        FAST_CONCAT                                      ~31     !9, '%0A'
         34        ECHO                                                     ~31
   28    35        INIT_FCALL                                               'elapsed_time'
         36        SEND_VAR                                                 !5
         37        DO_FCALL                                      0  $32     
         38        CONCAT                                           ~33     'strtr%3A+', $32
         39        CONCAT                                           ~34     ~33, '%0A'
         40        ECHO                                                     ~34
   30    41        ASSIGN                                                   !1, <array>
   35    42        INIT_FCALL                                               'explode'
         43        SEND_VAL                                                 '+'
         44        INIT_FCALL                                               'microtime'
         45        DO_ICALL                                         $36     
         46        SEND_VAR                                                 $36
         47        DO_ICALL                                         $37     
         48        ASSIGN                                                   !5, $37
   36    49        ASSIGN                                                   !6, 0
         50      > JMP                                                      ->60
   37    51    >   INIT_FCALL                                               'preg_replace_callback'
         52        SEND_VAL                                                 '%2F_%5C%24%28%5B%5E%24%5D%2B%29%5C%24_%2F'
         53        DECLARE_LAMBDA_FUNCTION                          ~40     [0]
         54        BIND_LEXICAL                                             ~40, !1
   39    55        SEND_VAL                                                 ~40
         56        SEND_VAR                                                 !0
   37    57        DO_ICALL                                         $41     
         58        ASSIGN                                                   !10, $41
   36    59        PRE_INC                                                  !6
         60    >   IS_SMALLER                                               !6, 10000
         61      > JMPNZ                                                    ~44, ->51
   41    62    >   INIT_FCALL                                               'elapsed_time'
         63        SEND_VAR                                                 !5
         64        DO_FCALL                                      0  $45     
         65        CONCAT                                           ~46     'preg_replace%3A+', $45
         66        CONCAT                                           ~47     ~46, '%0A'
         67        ECHO                                                     ~47
   42    68        NOP                                                      
         69        FAST_CONCAT                                      ~48     !10, '%0A'
         70        ECHO                                                     ~48
         71      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uP97b
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $matches, !1 = $replacements
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   38     2        FETCH_DIM_R                                      ~2      !0, 1
          3        FETCH_DIM_R                                      ~3      !1, ~2
          4      > RETURN                                                   ~3
   39     5*     > RETURN                                                   null

End of Dynamic Function 0

Function elapsed_time:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uP97b
function name:  elapsed_time
number of ops:  21
compiled vars:  !0 = $start, !1 = $now, !2 = $deltasec, !3 = $deltamsec
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '+'
          3        INIT_FCALL                                               'microtime'
          4        DO_ICALL                                         $4      
          5        SEND_VAR                                                 $4
          6        DO_ICALL                                         $5      
          7        ASSIGN                                                   !1, $5
    5     8        FETCH_DIM_R                                      ~7      !1, 1
          9        FETCH_DIM_R                                      ~8      !0, 1
         10        SUB                                              ~9      ~7, ~8
         11        ASSIGN                                                   !2, ~9
    6    12        FETCH_DIM_R                                      ~11     !1, 0
         13        CAST                                          5  ~12     ~11
         14        FETCH_DIM_R                                      ~13     !0, 0
         15        CAST                                          5  ~14     ~13
         16        SUB                                              ~15     ~12, ~14
         17        ASSIGN                                                   !3, ~15
    7    18        ADD                                              ~17     !2, !3
         19      > RETURN                                                   ~17
    8    20*     > RETURN                                                   null

End of function elapsed_time

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.91 ms | 1016 KiB | 19 Q