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) { $key = ''.array_column($thing['stuff'], 'id'); $ids[$key] = "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 = 95
Branch analysis from position: 95
2 jumps found. (Code = 44) Position 1 = 97, Position 2 = 80
Branch analysis from position: 97
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 80
2 jumps found. (Code = 77) Position 1 = 82, Position 2 = 93
Branch analysis from position: 82
2 jumps found. (Code = 78) Position 1 = 83, Position 2 = 93
Branch analysis from position: 83
1 jumps found. (Code = 42) Position 1 = 82
Branch analysis from position: 82
Branch analysis from position: 93
2 jumps found. (Code = 44) Position 1 = 97, Position 2 = 80
Branch analysis from position: 97
Branch analysis from position: 80
Branch analysis from position: 93
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/iKZME
function name:  (null)
number of ops:  109
compiled vars:  !0 = $allTheThings, !1 = $t, !2 = $i, !3 = $ids, !4 = $thing, !5 = $allTheIds, !6 = $key
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                                         $8      
          4        ASSIGN                                                   !1, $8
   46     5        ASSIGN                                                   !2, 0
          6      > JMP                                                      ->27
   48     7    >   ASSIGN                                                   !3, <array>
   49     8      > FE_RESET_R                                       $12     !0, ->21
          9    > > FE_FETCH_R                                               $12, !4, ->21
   50    10    >   INIT_FCALL                                               'array_merge'
         11        SEND_VAR                                                 !3
         12        INIT_FCALL                                               'array_column'
         13        FETCH_DIM_R                                      ~13     !4, 'stuff'
         14        SEND_VAL                                                 ~13
         15        SEND_VAL                                                 'id'
         16        DO_ICALL                                         $14     
         17        SEND_VAR                                                 $14
         18        DO_ICALL                                         $15     
         19        ASSIGN                                                   !3, $15
   49    20      > JMP                                                      ->9
         21    >   FE_FREE                                                  $12
   52    22        INIT_FCALL                                               'array_unique'
         23        SEND_VAR                                                 !3
         24        DO_ICALL                                         $17     
         25        ASSIGN                                                   !3, $17
   46    26        PRE_INC                                                  !2
         27    >   IS_SMALLER                                               !2, 10000
         28      > JMPNZ                                                    ~20, ->7
   54    29    >   INIT_FCALL                                               'microtime'
         30        SEND_VAL                                                 <true>
         31        DO_ICALL                                         $21     
         32        SUB                                              ~22     $21, !1
         33        ASSIGN                                                   !1, ~22
   55    34        INIT_FCALL                                               'var_export'
         35        SEND_VAR                                                 !3
         36        DO_ICALL                                                 
   56    37        CONCAT                                           ~25     'original%3A+', !1
         38        CONCAT                                           ~26     ~25, '%0A'
         39        ECHO                                                     ~26
   58    40        INIT_FCALL                                               'microtime'
         41        SEND_VAL                                                 <true>
         42        DO_ICALL                                         $27     
         43        ASSIGN                                                   !1, $27
   59    44        ASSIGN                                                   !2, 0
         45      > JMP                                                      ->61
   61    46    >   INIT_FCALL                                               'array_map'
         47        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FiKZME%3A61%240'
   63    48        SEND_VAL                                                 ~30
         49        SEND_VAR                                                 !0
         50        DO_ICALL                                         $31     
   61    51        ASSIGN                                                   !5, $31
   64    52        INIT_FCALL                                               'array_unique'
         53        INIT_FCALL                                               'array_merge'
         54        SEND_UNPACK                                              !5
         55        CHECK_UNDEF_ARGS                                         
         56        DO_ICALL                                         $33     
         57        SEND_VAR                                                 $33
         58        DO_ICALL                                         $34     
         59        ASSIGN                                                   !3, $34
   59    60        PRE_INC                                                  !2
         61    >   IS_SMALLER                                               !2, 10000
         62      > JMPNZ                                                    ~37, ->46
   66    63    >   INIT_FCALL                                               'microtime'
         64        SEND_VAL                                                 <true>
         65        DO_ICALL                                         $38     
         66        SUB                                              ~39     $38, !1
         67        ASSIGN                                                   !1, ~39
   67    68        INIT_FCALL                                               'var_export'
         69        SEND_VAR                                                 !3
         70        DO_ICALL                                                 
   68    71        CONCAT                                           ~42     'improved%3A+', !1
         72        CONCAT                                           ~43     ~42, '%0A'
         73        ECHO                                                     ~43
   71    74        INIT_FCALL                                               'microtime'
         75        SEND_VAL                                                 <true>
         76        DO_ICALL                                         $44     
         77        ASSIGN                                                   !1, $44
   72    78        ASSIGN                                                   !2, 0
         79      > JMP                                                      ->95
   74    80    >   ASSIGN                                                   !3, <array>
   75    81      > FE_RESET_R                                       $48     !0, ->93
         82    > > FE_FETCH_R                                               $48, !4, ->93
   76    83    >   INIT_FCALL                                               'array_column'
         84        FETCH_DIM_R                                      ~49     !4, 'stuff'
         85        SEND_VAL                                                 ~49
         86        SEND_VAL                                                 'id'
         87        DO_ICALL                                         $50     
         88        CONCAT                                           ~51     '', $50
         89        ASSIGN                                                   !6, ~51
   77    90        ASSIGN_DIM                                               !3, !6
         91        OP_DATA                                                  '1'
   75    92      > JMP                                                      ->82
         93    >   FE_FREE                                                  $48
   72    94        PRE_INC                                                  !2
         95    >   IS_SMALLER                                               !2, 10000
         96      > JMPNZ                                                    ~55, ->80
   80    97    >   INIT_FCALL                                               'microtime'
         98        SEND_VAL                                                 <true>
         99        DO_ICALL                                         $56     
        100        SUB                                              ~57     $56, !1
        101        ASSIGN                                                   !1, ~57
   81   102        INIT_FCALL                                               'var_export'
        103        SEND_VAR                                                 !3
        104        DO_ICALL                                                 
   82   105        CONCAT                                           ~60     'new%3A+', !1
        106        CONCAT                                           ~61     ~60, '%0A'
        107        ECHO                                                     ~61
        108      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FiKZME%3A61%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iKZME
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%2FiKZME%3A61%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.29 ms | 1408 KiB | 25 Q