3v4l.org

run code in 300+ PHP versions simultaneously
<?php $allTheThings = [ ['stuff' => [ ['id' => 42], ]], ['stuff' => [ ['id' => 'never'], ]], ['stuff' => [ ['id' => 'gonna'], ]], ['stuff' => [ ['id' => 'give'], ]], ['stuff' => [ ['id' => 'you'], ]], ['stuff' => [ ['id' => 'up'], ]], ['stuff' => [ ['id' => 42], ]], ['stuff' => [ ['id' => 'never'], ]], ['stuff' => [ ['id' => 'gonna'], ]], ['stuff' => [ ['id' => 'let'], ]], ['stuff' => [ ['id' => 'you'], ]], ['stuff' => [ ['id' => 'down'], ]], ['stuff' => [ ['id' => 42], ]], ]; $t = microtime(true); for ($i = 0; $i < 10000; $i++) { // original code $ids = []; foreach ($allTheThings as $thing) { $ids = array_merge($ids, array_column($thing['stuff'], 'id')); } $ids = array_unique($ids); } $t = microtime(true) - $t; var_export($ids); echo 'original: '.$t."\n"; $t = microtime(true); for ($i = 0; $i < 10000; $i++) { // improved code $allTheIds = array_map(function ($thing) { return array_column($thing['stuff'], 'id'); }, $allTheThings); $ids = array_unique(array_merge(...$allTheIds)); } $t = microtime(true) - $t; var_export($ids); echo 'improved: '.$t."\n"; $t = microtime(true); for ($i = 0; $i < 10000; $i++) { // new code $ids = array(); foreach ($allTheThings as $thing) { $idstemp = array_column($thing['stuff'], 'id'); foreach ($idstemp as $id) { $ids[$id] = "1"; } } } $t = microtime(true) - $t; var_export($ids); echo 'new: '.$t."\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 7
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
2 jumps found. (Code = 44) Position 1 = 63, Position 2 = 46
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 98
Branch analysis from position: 98
2 jumps found. (Code = 44) Position 1 = 100, Position 2 = 80
Branch analysis from position: 100
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 80
2 jumps found. (Code = 77) Position 1 = 82, Position 2 = 96
Branch analysis from position: 82
2 jumps found. (Code = 78) Position 1 = 83, Position 2 = 96
Branch analysis from position: 83
2 jumps found. (Code = 77) Position 1 = 90, Position 2 = 94
Branch analysis from position: 90
2 jumps found. (Code = 78) Position 1 = 91, Position 2 = 94
Branch analysis from position: 91
1 jumps found. (Code = 42) Position 1 = 90
Branch analysis from position: 90
Branch analysis from position: 94
1 jumps found. (Code = 42) Position 1 = 82
Branch analysis from position: 82
Branch analysis from position: 94
Branch analysis from position: 96
2 jumps found. (Code = 44) Position 1 = 100, Position 2 = 80
Branch analysis from position: 100
Branch analysis from position: 80
Branch analysis from position: 96
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 63, Position 2 = 46
Branch analysis from position: 63
Branch analysis from position: 46
Branch analysis from position: 7
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 21
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 21
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 7
Branch analysis from position: 29
Branch analysis from position: 7
Branch analysis from position: 21
filename:       /in/LZKBE
function name:  (null)
number of ops:  112
compiled vars:  !0 = $allTheThings, !1 = $t, !2 = $i, !3 = $ids, !4 = $thing, !5 = $allTheIds, !6 = $idstemp, !7 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   45     1        INIT_FCALL                                               'microtime'
          2        SEND_VAL                                                 <true>
          3        DO_ICALL                                         $9      
          4        ASSIGN                                                   !1, $9
   46     5        ASSIGN                                                   !2, 0
          6      > JMP                                                      ->27
   48     7    >   ASSIGN                                                   !3, <array>
   49     8      > FE_RESET_R                                       $13     !0, ->21
          9    > > FE_FETCH_R                                               $13, !4, ->21
   50    10    >   INIT_FCALL                                               'array_merge'
         11        SEND_VAR                                                 !3
         12        INIT_FCALL                                               'array_column'
         13        FETCH_DIM_R                                      ~14     !4, 'stuff'
         14        SEND_VAL                                                 ~14
         15        SEND_VAL                                                 'id'
         16        DO_ICALL                                         $15     
         17        SEND_VAR                                                 $15
         18        DO_ICALL                                         $16     
         19        ASSIGN                                                   !3, $16
   49    20      > JMP                                                      ->9
         21    >   FE_FREE                                                  $13
   52    22        INIT_FCALL                                               'array_unique'
         23        SEND_VAR                                                 !3
         24        DO_ICALL                                         $18     
         25        ASSIGN                                                   !3, $18
   46    26        PRE_INC                                                  !2
         27    >   IS_SMALLER                                               !2, 10000
         28      > JMPNZ                                                    ~21, ->7
   54    29    >   INIT_FCALL                                               'microtime'
         30        SEND_VAL                                                 <true>
         31        DO_ICALL                                         $22     
         32        SUB                                              ~23     $22, !1
         33        ASSIGN                                                   !1, ~23
   55    34        INIT_FCALL                                               'var_export'
         35        SEND_VAR                                                 !3
         36        DO_ICALL                                                 
   56    37        CONCAT                                           ~26     'original%3A+', !1
         38        CONCAT                                           ~27     ~26, '%0A'
         39        ECHO                                                     ~27
   58    40        INIT_FCALL                                               'microtime'
         41        SEND_VAL                                                 <true>
         42        DO_ICALL                                         $28     
         43        ASSIGN                                                   !1, $28
   59    44        ASSIGN                                                   !2, 0
         45      > JMP                                                      ->61
   61    46    >   INIT_FCALL                                               'array_map'
         47        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FLZKBE%3A61%240'
   63    48        SEND_VAL                                                 ~31
         49        SEND_VAR                                                 !0
         50        DO_ICALL                                         $32     
   61    51        ASSIGN                                                   !5, $32
   64    52        INIT_FCALL                                               'array_unique'
         53        INIT_FCALL                                               'array_merge'
         54        SEND_UNPACK                                              !5
         55        CHECK_UNDEF_ARGS                                         
         56        DO_ICALL                                         $34     
         57        SEND_VAR                                                 $34
         58        DO_ICALL                                         $35     
         59        ASSIGN                                                   !3, $35
   59    60        PRE_INC                                                  !2
         61    >   IS_SMALLER                                               !2, 10000
         62      > JMPNZ                                                    ~38, ->46
   66    63    >   INIT_FCALL                                               'microtime'
         64        SEND_VAL                                                 <true>
         65        DO_ICALL                                         $39     
         66        SUB                                              ~40     $39, !1
         67        ASSIGN                                                   !1, ~40
   67    68        INIT_FCALL                                               'var_export'
         69        SEND_VAR                                                 !3
         70        DO_ICALL                                                 
   68    71        CONCAT                                           ~43     'improved%3A+', !1
         72        CONCAT                                           ~44     ~43, '%0A'
         73        ECHO                                                     ~44
   71    74        INIT_FCALL                                               'microtime'
         75        SEND_VAL                                                 <true>
         76        DO_ICALL                                         $45     
         77        ASSIGN                                                   !1, $45
   72    78        ASSIGN                                                   !2, 0
         79      > JMP                                                      ->98
   74    80    >   ASSIGN                                                   !3, <array>
   75    81      > FE_RESET_R                                       $49     !0, ->96
         82    > > FE_FETCH_R                                               $49, !4, ->96
   76    83    >   INIT_FCALL                                               'array_column'
         84        FETCH_DIM_R                                      ~50     !4, 'stuff'
         85        SEND_VAL                                                 ~50
         86        SEND_VAL                                                 'id'
         87        DO_ICALL                                         $51     
         88        ASSIGN                                                   !6, $51
   77    89      > FE_RESET_R                                       $53     !6, ->94
         90    > > FE_FETCH_R                                               $53, !7, ->94
   78    91    >   ASSIGN_DIM                                               !3, !7
         92        OP_DATA                                                  '1'
   77    93      > JMP                                                      ->90
         94    >   FE_FREE                                                  $53
   75    95      > JMP                                                      ->82
         96    >   FE_FREE                                                  $49
   72    97        PRE_INC                                                  !2
         98    >   IS_SMALLER                                               !2, 10000
         99      > JMPNZ                                                    ~56, ->80
   82   100    >   INIT_FCALL                                               'microtime'
        101        SEND_VAL                                                 <true>
        102        DO_ICALL                                         $57     
        103        SUB                                              ~58     $57, !1
        104        ASSIGN                                                   !1, ~58
   83   105        INIT_FCALL                                               'var_export'
        106        SEND_VAR                                                 !3
        107        DO_ICALL                                                 
   84   108        CONCAT                                           ~61     'new%3A+', !1
        109        CONCAT                                           ~62     ~61, '%0A'
        110        ECHO                                                     ~62
        111      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FLZKBE%3A61%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LZKBE
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $thing
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   RECV                                             !0      
   62     1        INIT_FCALL                                               'array_column'
          2        FETCH_DIM_R                                      ~1      !0, 'stuff'
          3        SEND_VAL                                                 ~1
          4        SEND_VAL                                                 'id'
          5        DO_ICALL                                         $2      
          6      > RETURN                                                   $2
   63     7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FLZKBE%3A61%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.44 ms | 1408 KiB | 25 Q