3v4l.org

run code in 300+ PHP versions simultaneously
<?php function mapCallback1($callback, $array){ $output = []; array_map(function($value) use ($callback, &$output) { $callback($value, function($value) use (&$output) { $output[] = $value; }); }, $array); return $output; } function mapCallback2($callback, $array){ $output = []; $push = function ($value) use (&$output) { $output[] = $value; }; foreach ($array as $value) { $callback($value, $push); } return $output; } $square = function ($x, $push) { $push($x * $x); }; $t = microtime(1); for ($i = 100000; $i--;) mapCallback1($square, [1, 2, 3]); echo 1000 * (microtime(1) - $t) . PHP_EOL; $t = microtime(1); for ($i = 100000; $i--;) mapCallback2($square, [1, 2, 3]); echo 1000 * (microtime(1) - $t) . PHP_EOL; var_dump(mapCallback1($square, [1, 2, 3])); var_dump(mapCallback2($square, [1, 2, 3]));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 8
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 27
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 27
Branch analysis from position: 33
Branch analysis from position: 27
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 8
Branch analysis from position: 14
Branch analysis from position: 8
filename:       /in/WejOs
function name:  (null)
number of ops:  55
compiled vars:  !0 = $square, !1 = $t, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FWejOs%3A28%243'
          1        ASSIGN                                                   !0, ~3
   32     2        INIT_FCALL                                               'microtime'
          3        SEND_VAL                                                 1
          4        DO_ICALL                                         $5      
          5        ASSIGN                                                   !1, $5
   33     6        ASSIGN                                                   !2, 100000
          7      > JMP                                                      ->12
          8    >   INIT_FCALL                                               'mapcallback1'
          9        SEND_VAR                                                 !0
         10        SEND_VAL                                                 <array>
         11        DO_FCALL                                      0          
         12    >   POST_DEC                                         ~9      !2
         13      > JMPNZ                                                    ~9, ->8
   34    14    >   INIT_FCALL                                               'microtime'
         15        SEND_VAL                                                 1
         16        DO_ICALL                                         $10     
         17        SUB                                              ~11     $10, !1
         18        MUL                                              ~12     ~11, 1000
         19        CONCAT                                           ~13     ~12, '%0A'
         20        ECHO                                                     ~13
   36    21        INIT_FCALL                                               'microtime'
         22        SEND_VAL                                                 1
         23        DO_ICALL                                         $14     
         24        ASSIGN                                                   !1, $14
   37    25        ASSIGN                                                   !2, 100000
         26      > JMP                                                      ->31
         27    >   INIT_FCALL                                               'mapcallback2'
         28        SEND_VAR                                                 !0
         29        SEND_VAL                                                 <array>
         30        DO_FCALL                                      0          
         31    >   POST_DEC                                         ~18     !2
         32      > JMPNZ                                                    ~18, ->27
   38    33    >   INIT_FCALL                                               'microtime'
         34        SEND_VAL                                                 1
         35        DO_ICALL                                         $19     
         36        SUB                                              ~20     $19, !1
         37        MUL                                              ~21     ~20, 1000
         38        CONCAT                                           ~22     ~21, '%0A'
         39        ECHO                                                     ~22
   40    40        INIT_FCALL                                               'var_dump'
         41        INIT_FCALL                                               'mapcallback1'
         42        SEND_VAR                                                 !0
         43        SEND_VAL                                                 <array>
         44        DO_FCALL                                      0  $23     
         45        SEND_VAR                                                 $23
         46        DO_ICALL                                                 
   41    47        INIT_FCALL                                               'var_dump'
         48        INIT_FCALL                                               'mapcallback2'
         49        SEND_VAR                                                 !0
         50        SEND_VAL                                                 <array>
         51        DO_FCALL                                      0  $25     
         52        SEND_VAR                                                 $25
         53        DO_ICALL                                                 
         54      > RETURN                                                   1

Function mapcallback1:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WejOs
function name:  mapCallback1
number of ops:  12
compiled vars:  !0 = $callback, !1 = $array, !2 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    3     2        ASSIGN                                                   !2, <array>
    5     3        INIT_FCALL                                               'array_map'
          4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FWejOs%3A5%240'
          5        BIND_LEXICAL                                             ~4, !0
          6        BIND_LEXICAL                                             ~4, !2
    9     7        SEND_VAL                                                 ~4
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                                 
   11    10      > RETURN                                                   !2
   12    11*     > RETURN                                                   null

End of function mapcallback1

Function %00%7Bclosure%7D%2Fin%2FWejOs%3A5%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WejOs
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $value, !1 = $callback, !2 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
    6     3        INIT_DYNAMIC_CALL                                        !1
          4        SEND_VAR_EX                                              !0
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FWejOs%3A6%241'
          6        BIND_LEXICAL                                             ~3, !2
    8     7        SEND_VAL_EX                                              ~3
          8        DO_FCALL                                      0          
    9     9      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FWejOs%3A5%240

Function %00%7Bclosure%7D%2Fin%2FWejOs%3A6%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WejOs
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $value, !1 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
    7     2        ASSIGN_DIM                                               !1
          3        OP_DATA                                                  !0
    8     4      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FWejOs%3A6%241

Function mapcallback2:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 13
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 13
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/WejOs
function name:  mapCallback2
number of ops:  16
compiled vars:  !0 = $callback, !1 = $array, !2 = $output, !3 = $push, !4 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   15     2        ASSIGN                                                   !2, <array>
   17     3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FWejOs%3A17%242'
          4        BIND_LEXICAL                                             ~6, !2
          5        ASSIGN                                                   !3, ~6
   21     6      > FE_RESET_R                                       $8      !1, ->13
          7    > > FE_FETCH_R                                               $8, !4, ->13
   22     8    >   INIT_DYNAMIC_CALL                                        !0
          9        SEND_VAR_EX                                              !4
         10        SEND_VAR_EX                                              !3
         11        DO_FCALL                                      0          
   21    12      > JMP                                                      ->7
         13    >   FE_FREE                                                  $8
   25    14      > RETURN                                                   !2
   26    15*     > RETURN                                                   null

End of function mapcallback2

Function %00%7Bclosure%7D%2Fin%2FWejOs%3A17%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WejOs
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $value, !1 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   18     2        ASSIGN_DIM                                               !1
          3        OP_DATA                                                  !0
   19     4      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FWejOs%3A17%242

Function %00%7Bclosure%7D%2Fin%2FWejOs%3A28%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WejOs
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $x, !1 = $push
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   29     2        INIT_DYNAMIC_CALL                                        !1
          3        MUL                                              ~2      !0, !0
          4        SEND_VAL_EX                                              ~2
          5        DO_FCALL                                      0          
   30     6      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FWejOs%3A28%243

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.65 ms | 1411 KiB | 23 Q