3v4l.org

run code in 300+ PHP versions simultaneously
<?php function lap($func) { $t0 = microtime(1); $numbers = range(0, 10000); $ret = $func($numbers); $t1 = microtime(1); return array($t1 - $t0, $ret); } function useArray($numbers) { $result = array(); foreach ($numbers as $number) { $result[] = $number * 10; } return $result; } function useMapClosure($numbers) { return array_map(function($number) { return $number * 10; }, $numbers); } function _tenTimes($number) { return $number * 10; } function useMapNamed($numbers) { return array_map('_tenTimes', $numbers); } foreach (array('Array', 'MapClosure', 'MapNamed') as $callback) { list($delay,) = lap("use$callback"); echo "$callback: $delay\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 1, Position 2 = 16
Branch analysis from position: 1
2 jumps found. (Code = 78) Position 1 = 2, Position 2 = 16
Branch analysis from position: 2
1 jumps found. (Code = 42) Position 1 = 1
Branch analysis from position: 1
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/k2CNN
function name:  (null)
number of ops:  18
compiled vars:  !0 = $callback, !1 = $delay
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E > > FE_RESET_R                                       $2      <array>, ->16
          1    > > FE_FETCH_R                                               $2, !0, ->16
   34     2    >   INIT_FCALL                                               'lap'
          3        NOP                                                      
          4        FAST_CONCAT                                      ~3      'use', !0
          5        SEND_VAL                                                 ~3
          6        DO_FCALL                                      0  $4      
          7        FETCH_LIST_R                                     $5      $4, 0
          8        ASSIGN                                                   !1, $5
          9        FREE                                                     $4
   35    10        ROPE_INIT                                     4  ~8      !0
         11        ROPE_ADD                                      1  ~8      ~8, '%3A+'
         12        ROPE_ADD                                      2  ~8      ~8, !1
         13        ROPE_END                                      3  ~7      ~8, '%0A'
         14        ECHO                                                     ~7
   33    15      > JMP                                                      ->1
         16    >   FE_FREE                                                  $2
   36    17      > RETURN                                                   1

Function lap:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k2CNN
function name:  lap
number of ops:  23
compiled vars:  !0 = $func, !1 = $t0, !2 = $numbers, !3 = $ret, !4 = $t1
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'microtime'
          2        SEND_VAL                                                 1
          3        DO_ICALL                                         $5      
          4        ASSIGN                                                   !1, $5
    5     5        INIT_FCALL                                               'range'
          6        SEND_VAL                                                 0
          7        SEND_VAL                                                 10000
          8        DO_ICALL                                         $7      
          9        ASSIGN                                                   !2, $7
    6    10        INIT_DYNAMIC_CALL                                        !0
         11        SEND_VAR_EX                                              !2
         12        DO_FCALL                                      0  $9      
         13        ASSIGN                                                   !3, $9
    7    14        INIT_FCALL                                               'microtime'
         15        SEND_VAL                                                 1
         16        DO_ICALL                                         $11     
         17        ASSIGN                                                   !4, $11
    8    18        SUB                                              ~13     !4, !1
         19        INIT_ARRAY                                       ~14     ~13
         20        ADD_ARRAY_ELEMENT                                ~14     !3
         21      > RETURN                                                   ~14
    9    22*     > RETURN                                                   null

End of function lap

Function usearray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/k2CNN
function name:  useArray
number of ops:  11
compiled vars:  !0 = $numbers, !1 = $result, !2 = $number
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   12     1        ASSIGN                                                   !1, <array>
   13     2      > FE_RESET_R                                       $4      !0, ->8
          3    > > FE_FETCH_R                                               $4, !2, ->8
   14     4    >   MUL                                              ~6      !2, 10
          5        ASSIGN_DIM                                               !1
          6        OP_DATA                                                  ~6
   13     7      > JMP                                                      ->3
          8    >   FE_FREE                                                  $4
   16     9      > RETURN                                                   !1
   17    10*     > RETURN                                                   null

End of function usearray

Function usemapclosure:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k2CNN
function name:  useMapClosure
number of ops:  8
compiled vars:  !0 = $numbers
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     1        INIT_FCALL                                               'array_map'
          2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fk2CNN%3A20%240'
   22     3        SEND_VAL                                                 ~1
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6      > RETURN                                                   $2
   23     7*     > RETURN                                                   null

End of function usemapclosure

Function %00%7Bclosure%7D%2Fin%2Fk2CNN%3A20%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k2CNN
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $number
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   21     1        MUL                                              ~1      !0, 10
          2      > RETURN                                                   ~1
   22     3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fk2CNN%3A20%240

Function _tentimes:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k2CNN
function name:  _tenTimes
number of ops:  4
compiled vars:  !0 = $number
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   26     1        MUL                                              ~1      !0, 10
          2      > RETURN                                                   ~1
   27     3*     > RETURN                                                   null

End of function _tentimes

Function usemapnamed:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k2CNN
function name:  useMapNamed
number of ops:  7
compiled vars:  !0 = $numbers
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   30     1        INIT_FCALL                                               'array_map'
          2        SEND_VAL                                                 '_tenTimes'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5      > RETURN                                                   $1
   31     6*     > RETURN                                                   null

End of function usemapnamed

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.4 ms | 1406 KiB | 20 Q