3v4l.org

run code in 300+ PHP versions simultaneously
<?php $amount = $qty = $code = $id = range(1, 5000); //dry run to cache function calls $op = '%s executed in %.8f seconds'; microtime(true); $max = count($id); $start = $end = 0; $data = []; for ($i=0; $i<$max; $i++) { $data[] = [ 'id' => $id[$i], 'code' => $code[$i], 'qty' => $qty[$i], 'amount' => $amount[$i] ]; } $data = []; foreach($id as $i => $v) { $data[$i] = [ 'id' => $v, 'code' => $code[$i], 'qty' => $qty[$i], 'amount' => $amount[$i] ]; } $data = array_map(function($a, $b, $c, $d) { return [ 'id' => $a, 'code' => $b, 'qty' => $c, 'amount' => $d ]; }, $id, $code, $qty, $amount); //end dry-run $start = microtime(true); $data = []; foreach($id as $i => $v) { $data[] = [ 'id' => $v, 'code' => $code[$i], 'qty' => $qty[$i], 'amount' => $amount[$i] ]; } $end = microtime(true); printf($op, 'foreach', $end - $start); echo PHP_EOL; //---- $start = microtime(true); $max = count($id); $data = []; for ($i=0; $i<$max; $i++) { $data[] = [ 'id' => $id[$i], 'code' => $code[$i], 'qty' => $qty[$i], 'amount' => $amount[$i] ]; } $end = microtime(true); printf($op, 'for', $end - $start); echo PHP_EOL; $start = microtime(true); $data = array_map(function($a, $b, $c, $d) { return [ 'id' => $a, 'code' => $b, 'qty' => $c, 'amount' => $d ]; }, $id, $code, $qty, $amount); $end = microtime(true); printf($op, 'array_map', $end - $start);
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 = 19
Branch analysis from position: 32
2 jumps found. (Code = 77) Position 1 = 34, Position 2 = 46
Branch analysis from position: 34
2 jumps found. (Code = 78) Position 1 = 35, Position 2 = 46
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
Branch analysis from position: 46
2 jumps found. (Code = 77) Position 1 = 62, Position 2 = 74
Branch analysis from position: 62
2 jumps found. (Code = 78) Position 1 = 63, Position 2 = 74
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 62
Branch analysis from position: 62
Branch analysis from position: 74
1 jumps found. (Code = 42) Position 1 = 106
Branch analysis from position: 106
2 jumps found. (Code = 44) Position 1 = 108, Position 2 = 95
Branch analysis from position: 108
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 95
2 jumps found. (Code = 44) Position 1 = 108, Position 2 = 95
Branch analysis from position: 108
Branch analysis from position: 95
Branch analysis from position: 74
Branch analysis from position: 46
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 19
Branch analysis from position: 32
Branch analysis from position: 19
filename:       /in/IOlAm
function name:  (null)
number of ops:  143
compiled vars:  !0 = $amount, !1 = $qty, !2 = $code, !3 = $id, !4 = $op, !5 = $max, !6 = $start, !7 = $end, !8 = $data, !9 = $i, !10 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'range'
          1        SEND_VAL                                                 1
          2        SEND_VAL                                                 5000
          3        DO_ICALL                                         $11     
          4        ASSIGN                                           ~12     !3, $11
          5        ASSIGN                                           ~13     !2, ~12
          6        ASSIGN                                           ~14     !1, ~13
          7        ASSIGN                                                   !0, ~14
    6     8        ASSIGN                                                   !4, '%25s+executed+in+%25.8f+seconds'
    7     9        INIT_FCALL                                               'microtime'
         10        SEND_VAL                                                 <true>
         11        DO_ICALL                                                 
    8    12        COUNT                                            ~18     !3
         13        ASSIGN                                                   !5, ~18
    9    14        ASSIGN                                           ~20     !7, 0
         15        ASSIGN                                                   !6, ~20
   10    16        ASSIGN                                                   !8, <array>
   11    17        ASSIGN                                                   !9, 0
         18      > JMP                                                      ->30
   13    19    >   FETCH_DIM_R                                      ~25     !3, !9
         20        INIT_ARRAY                                       ~26     ~25, 'id'
   14    21        FETCH_DIM_R                                      ~27     !2, !9
         22        ADD_ARRAY_ELEMENT                                ~26     ~27, 'code'
   15    23        FETCH_DIM_R                                      ~28     !1, !9
         24        ADD_ARRAY_ELEMENT                                ~26     ~28, 'qty'
   16    25        FETCH_DIM_R                                      ~29     !0, !9
         26        ADD_ARRAY_ELEMENT                                ~26     ~29, 'amount'
   12    27        ASSIGN_DIM                                               !8
   16    28        OP_DATA                                                  ~26
   11    29        PRE_INC                                                  !9
         30    >   IS_SMALLER                                               !9, !5
         31      > JMPNZ                                                    ~31, ->19
   19    32    >   ASSIGN                                                   !8, <array>
   20    33      > FE_RESET_R                                       $33     !3, ->46
         34    > > FE_FETCH_R                                       ~34     $33, !10, ->46
         35    >   ASSIGN                                                   !9, ~34
   22    36        INIT_ARRAY                                       ~37     !10, 'id'
   23    37        FETCH_DIM_R                                      ~38     !2, !9
         38        ADD_ARRAY_ELEMENT                                ~37     ~38, 'code'
   24    39        FETCH_DIM_R                                      ~39     !1, !9
         40        ADD_ARRAY_ELEMENT                                ~37     ~39, 'qty'
   25    41        FETCH_DIM_R                                      ~40     !0, !9
         42        ADD_ARRAY_ELEMENT                                ~37     ~40, 'amount'
   21    43        ASSIGN_DIM                                               !8, !9
   25    44        OP_DATA                                                  ~37
   20    45      > JMP                                                      ->34
         46    >   FE_FREE                                                  $33
   28    47        INIT_FCALL                                               'array_map'
         48        DECLARE_LAMBDA_FUNCTION                          ~41     [0]
   35    49        SEND_VAL                                                 ~41
         50        SEND_VAR                                                 !3
         51        SEND_VAR                                                 !2
         52        SEND_VAR                                                 !1
         53        SEND_VAR                                                 !0
   28    54        DO_ICALL                                         $42     
         55        ASSIGN                                                   !8, $42
   39    56        INIT_FCALL                                               'microtime'
         57        SEND_VAL                                                 <true>
         58        DO_ICALL                                         $44     
         59        ASSIGN                                                   !6, $44
   41    60        ASSIGN                                                   !8, <array>
   42    61      > FE_RESET_R                                       $47     !3, ->74
         62    > > FE_FETCH_R                                       ~48     $47, !10, ->74
         63    >   ASSIGN                                                   !9, ~48
   44    64        INIT_ARRAY                                       ~51     !10, 'id'
   45    65        FETCH_DIM_R                                      ~52     !2, !9
         66        ADD_ARRAY_ELEMENT                                ~51     ~52, 'code'
   46    67        FETCH_DIM_R                                      ~53     !1, !9
         68        ADD_ARRAY_ELEMENT                                ~51     ~53, 'qty'
   47    69        FETCH_DIM_R                                      ~54     !0, !9
         70        ADD_ARRAY_ELEMENT                                ~51     ~54, 'amount'
   43    71        ASSIGN_DIM                                               !8
   47    72        OP_DATA                                                  ~51
   42    73      > JMP                                                      ->62
         74    >   FE_FREE                                                  $47
   51    75        INIT_FCALL                                               'microtime'
         76        SEND_VAL                                                 <true>
         77        DO_ICALL                                         $55     
         78        ASSIGN                                                   !7, $55
   52    79        INIT_FCALL                                               'printf'
         80        SEND_VAR                                                 !4
         81        SEND_VAL                                                 'foreach'
         82        SUB                                              ~57     !7, !6
         83        SEND_VAL                                                 ~57
         84        DO_ICALL                                                 
   54    85        ECHO                                                     '%0A'
   57    86        INIT_FCALL                                               'microtime'
         87        SEND_VAL                                                 <true>
         88        DO_ICALL                                         $59     
         89        ASSIGN                                                   !6, $59
   59    90        COUNT                                            ~61     !3
         91        ASSIGN                                                   !5, ~61
   60    92        ASSIGN                                                   !8, <array>
   61    93        ASSIGN                                                   !9, 0
         94      > JMP                                                      ->106
   63    95    >   FETCH_DIM_R                                      ~66     !3, !9
         96        INIT_ARRAY                                       ~67     ~66, 'id'
   64    97        FETCH_DIM_R                                      ~68     !2, !9
         98        ADD_ARRAY_ELEMENT                                ~67     ~68, 'code'
   65    99        FETCH_DIM_R                                      ~69     !1, !9
        100        ADD_ARRAY_ELEMENT                                ~67     ~69, 'qty'
   66   101        FETCH_DIM_R                                      ~70     !0, !9
        102        ADD_ARRAY_ELEMENT                                ~67     ~70, 'amount'
   62   103        ASSIGN_DIM                                               !8
   66   104        OP_DATA                                                  ~67
   61   105        PRE_INC                                                  !9
        106    >   IS_SMALLER                                               !9, !5
        107      > JMPNZ                                                    ~72, ->95
   70   108    >   INIT_FCALL                                               'microtime'
        109        SEND_VAL                                                 <true>
        110        DO_ICALL                                         $73     
        111        ASSIGN                                                   !7, $73
   71   112        INIT_FCALL                                               'printf'
        113        SEND_VAR                                                 !4
        114        SEND_VAL                                                 'for'
        115        SUB                                              ~75     !7, !6
        116        SEND_VAL                                                 ~75
        117        DO_ICALL                                                 
   73   118        ECHO                                                     '%0A'
   75   119        INIT_FCALL                                               'microtime'
        120        SEND_VAL                                                 <true>
        121        DO_ICALL                                         $77     
        122        ASSIGN                                                   !6, $77
   77   123        INIT_FCALL                                               'array_map'
        124        DECLARE_LAMBDA_FUNCTION                          ~79     [1]
   84   125        SEND_VAL                                                 ~79
        126        SEND_VAR                                                 !3
        127        SEND_VAR                                                 !2
        128        SEND_VAR                                                 !1
        129        SEND_VAR                                                 !0
   77   130        DO_ICALL                                         $80     
        131        ASSIGN                                                   !8, $80
   86   132        INIT_FCALL                                               'microtime'
        133        SEND_VAL                                                 <true>
        134        DO_ICALL                                         $82     
        135        ASSIGN                                                   !7, $82
   87   136        INIT_FCALL                                               'printf'
        137        SEND_VAR                                                 !4
        138        SEND_VAL                                                 'array_map'
        139        SUB                                              ~84     !7, !6
        140        SEND_VAL                                                 ~84
        141        DO_ICALL                                                 
        142      > 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/IOlAm
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $a, !1 = $b, !2 = $c, !3 = $d
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   30     4        INIT_ARRAY                                       ~4      !0, 'id'
   31     5        ADD_ARRAY_ELEMENT                                ~4      !1, 'code'
   32     6        ADD_ARRAY_ELEMENT                                ~4      !2, 'qty'
   33     7        ADD_ARRAY_ELEMENT                                ~4      !3, 'amount'
          8      > RETURN                                                   ~4
   35     9*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IOlAm
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $a, !1 = $b, !2 = $c, !3 = $d
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   77     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   79     4        INIT_ARRAY                                       ~4      !0, 'id'
   80     5        ADD_ARRAY_ELEMENT                                ~4      !1, 'code'
   81     6        ADD_ARRAY_ELEMENT                                ~4      !2, 'qty'
   82     7        ADD_ARRAY_ELEMENT                                ~4      !3, 'amount'
          8      > RETURN                                                   ~4
   84     9*     > RETURN                                                   null

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.3 ms | 1014 KiB | 17 Q