3v4l.org

run code in 500+ PHP versions simultaneously
<?php const COUNT = 1_000_000; $methods = ['getLastName', 'getFirstName', 'getStreet', 'getCity', 'getZipCode', 'getCountry']; $cacheOld = []; $cacheNew = []; $cacheSimplified = []; foreach ($methods as $method) { $cacheOld[$method] = $method; $cacheNew[$method] = $method; $cacheOld[strtolower($method)] = $method; $cacheNew[strtolower($method)] = $method; $cacheSimplified[strtolower($method)] = $method; $name = substr($method, 3); $cacheOld[$name] = $method; $cacheNew[lcfirst($name)] = $method; $cacheOld[strtolower($name)] = $method; $cacheNew[strtolower($name)] = $method; $cacheSimplified[strtolower($name)] = $method; } function run(string $name, callable $callback): void { global $names; $time = microtime(true); for ($i = 0; $i < COUNT; ++$i) { foreach (['lastName', 'firstName', 'street', 'city', 'zipCode', 'country'] as $item) { $callback($item); } } $time = microtime(true) - $time; echo sprintf('%.6f ms: %s', $time, $name), "\n"; } run('old', function ($name) use ($cacheOld) { if (isset($cacheOld[$name])) { return $cacheOld[$name]; } elseif (isset($cacheOld[$lcItem = strtolower($name)])) { return $cacheOld[$lcItem]; } }); run('new', function ($name) use ($cacheNew) { if (isset($cacheNew[$name])) { return $cacheNew[$name]; } elseif (isset($cacheNew[$lcItem = strtolower($name)])) { return $cacheNew[$lcItem]; } }); run('simplified', function ($name) use ($cacheSimplified) { if (isset($cacheSimplified[$lcItem = strtolower($name)])) { return $cacheSimplified[$lcItem]; } }); run('simplified2', function ($name) use ($cacheSimplified) { if (isset($cacheSimplified[$name])) { return $cacheSimplified[$name]; } elseif (isset($cacheSimplified[$lcItem = strtolower($name)])) { return $cacheSimplified[$lcItem]; } });
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 51
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 51
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
filename:       /in/Obpbk
function name:  (null)
number of ops:  77
compiled vars:  !0 = $methods, !1 = $cacheOld, !2 = $cacheNew, !3 = $cacheSimplified, !4 = $method, !5 = $name
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CONST                                                'COUNT', 1000000
    5     1        ASSIGN                                                       !0, <array>
    7     2        ASSIGN                                                       !1, <array>
    8     3        ASSIGN                                                       !2, <array>
    9     4        ASSIGN                                                       !3, <array>
   10     5      > FE_RESET_R                                           $10     !0, ->51
          6    > > FE_FETCH_R                                                   $10, !4, ->51
   11     7    >   ASSIGN_DIM                                                   !1, !4
          8        OP_DATA                                                      !4
   12     9        ASSIGN_DIM                                                   !2, !4
         10        OP_DATA                                                      !4
   14    11        INIT_FCALL                                                   'strtolower'
         12        SEND_VAR                                                     !4
         13        DO_ICALL                                             $13     
         14        ASSIGN_DIM                                                   !1, $13
         15        OP_DATA                                                      !4
   15    16        INIT_FCALL                                                   'strtolower'
         17        SEND_VAR                                                     !4
         18        DO_ICALL                                             $15     
         19        ASSIGN_DIM                                                   !2, $15
         20        OP_DATA                                                      !4
   16    21        INIT_FCALL                                                   'strtolower'
         22        SEND_VAR                                                     !4
         23        DO_ICALL                                             $17     
         24        ASSIGN_DIM                                                   !3, $17
         25        OP_DATA                                                      !4
   18    26        FRAMELESS_ICALL_2                substr              ~19     !4, 3
         27        ASSIGN                                                       !5, ~19
   20    28        ASSIGN_DIM                                                   !1, !5
         29        OP_DATA                                                      !4
   21    30        INIT_FCALL                                                   'lcfirst'
         31        SEND_VAR                                                     !5
         32        DO_ICALL                                             $22     
         33        ASSIGN_DIM                                                   !2, $22
         34        OP_DATA                                                      !4
   23    35        INIT_FCALL                                                   'strtolower'
         36        SEND_VAR                                                     !5
         37        DO_ICALL                                             $24     
         38        ASSIGN_DIM                                                   !1, $24
         39        OP_DATA                                                      !4
   24    40        INIT_FCALL                                                   'strtolower'
         41        SEND_VAR                                                     !5
         42        DO_ICALL                                             $26     
         43        ASSIGN_DIM                                                   !2, $26
         44        OP_DATA                                                      !4
   25    45        INIT_FCALL                                                   'strtolower'
         46        SEND_VAR                                                     !5
         47        DO_ICALL                                             $28     
         48        ASSIGN_DIM                                                   !3, $28
         49        OP_DATA                                                      !4
   10    50      > JMP                                                          ->6
         51    >   FE_FREE                                                      $10
   44    52        INIT_FCALL                                                   'run'
         53        SEND_VAL                                                     'old'
         54        DECLARE_LAMBDA_FUNCTION                              ~30     [0]
         55        BIND_LEXICAL                                                 ~30, !1
   50    56        SEND_VAL                                                     ~30
   44    57        DO_FCALL                                          0          
   51    58        INIT_FCALL                                                   'run'
         59        SEND_VAL                                                     'new'
         60        DECLARE_LAMBDA_FUNCTION                              ~32     [1]
         61        BIND_LEXICAL                                                 ~32, !2
   57    62        SEND_VAL                                                     ~32
   51    63        DO_FCALL                                          0          
   58    64        INIT_FCALL                                                   'run'
         65        SEND_VAL                                                     'simplified'
         66        DECLARE_LAMBDA_FUNCTION                              ~34     [2]
         67        BIND_LEXICAL                                                 ~34, !3
   62    68        SEND_VAL                                                     ~34
   58    69        DO_FCALL                                          0          
   63    70        INIT_FCALL                                                   'run'
         71        SEND_VAL                                                     'simplified2'
         72        DECLARE_LAMBDA_FUNCTION                              ~36     [3]
         73        BIND_LEXICAL                                                 ~36, !3
   69    74        SEND_VAL                                                     ~36
   63    75        DO_FCALL                                          0          
   69    76      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Obpbk
function name:  {closure:/in/Obpbk:44}
number of ops:  16
compiled vars:  !0 = $name, !1 = $cacheOld, !2 = $lcItem
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   44     0  E >   RECV                                                 !0      
          1        BIND_STATIC                                                  !1
   45     2        ISSET_ISEMPTY_DIM_OBJ                             0          !1, !0
          3      > JMPZ                                                         ~3, ->7
   46     4    >   FETCH_DIM_R                                          ~4      !1, !0
          5      > RETURN                                                       ~4
   45     6*       JMP                                                          ->15
   47     7    >   INIT_FCALL                                                   'strtolower'
          8        SEND_VAR                                                     !0
          9        DO_ICALL                                             $5      
         10        ASSIGN                                               ~6      !2, $5
         11        ISSET_ISEMPTY_DIM_OBJ                             0          !1, ~6
         12      > JMPZ                                                         ~7, ->15
   48    13    >   FETCH_DIM_R                                          ~8      !1, !2
         14      > RETURN                                                       ~8
   50    15    > > RETURN                                                       null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Obpbk
function name:  {closure:/in/Obpbk:51}
number of ops:  16
compiled vars:  !0 = $name, !1 = $cacheNew, !2 = $lcItem
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   51     0  E >   RECV                                                 !0      
          1        BIND_STATIC                                                  !1
   52     2        ISSET_ISEMPTY_DIM_OBJ                             0          !1, !0
          3      > JMPZ                                                         ~3, ->7
   53     4    >   FETCH_DIM_R                                          ~4      !1, !0
          5      > RETURN                                                       ~4
   52     6*       JMP                                                          ->15
   54     7    >   INIT_FCALL                                                   'strtolower'
          8        SEND_VAR                                                     !0
          9        DO_ICALL                                             $5      
         10        ASSIGN                                               ~6      !2, $5
         11        ISSET_ISEMPTY_DIM_OBJ                             0          !1, ~6
         12      > JMPZ                                                         ~7, ->15
   55    13    >   FETCH_DIM_R                                          ~8      !1, !2
         14      > RETURN                                                       ~8
   57    15    > > RETURN                                                       null

End of Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Obpbk
function name:  {closure:/in/Obpbk:58}
number of ops:  11
compiled vars:  !0 = $name, !1 = $cacheSimplified, !2 = $lcItem
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   58     0  E >   RECV                                                 !0      
          1        BIND_STATIC                                                  !1
   59     2        INIT_FCALL                                                   'strtolower'
          3        SEND_VAR                                                     !0
          4        DO_ICALL                                             $3      
          5        ASSIGN                                               ~4      !2, $3
          6        ISSET_ISEMPTY_DIM_OBJ                             0          !1, ~4
          7      > JMPZ                                                         ~5, ->10
   60     8    >   FETCH_DIM_R                                          ~6      !1, !2
          9      > RETURN                                                       ~6
   62    10    > > RETURN                                                       null

End of Dynamic Function 2

Dynamic Function 3
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Obpbk
function name:  {closure:/in/Obpbk:63}
number of ops:  16
compiled vars:  !0 = $name, !1 = $cacheSimplified, !2 = $lcItem
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   63     0  E >   RECV                                                 !0      
          1        BIND_STATIC                                                  !1
   64     2        ISSET_ISEMPTY_DIM_OBJ                             0          !1, !0
          3      > JMPZ                                                         ~3, ->7
   65     4    >   FETCH_DIM_R                                          ~4      !1, !0
          5      > RETURN                                                       ~4
   64     6*       JMP                                                          ->15
   66     7    >   INIT_FCALL                                                   'strtolower'
          8        SEND_VAR                                                     !0
          9        DO_ICALL                                             $5      
         10        ASSIGN                                               ~6      !2, $5
         11        ISSET_ISEMPTY_DIM_OBJ                             0          !1, ~6
         12      > JMPZ                                                         ~7, ->15
   67    13    >   FETCH_DIM_R                                          ~8      !1, !2
         14      > RETURN                                                       ~8
   69    15    > > RETURN                                                       null

End of Dynamic Function 3

Function run:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 9
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 15
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 9
Branch analysis from position: 20
Branch analysis from position: 9
Branch analysis from position: 15
filename:       /in/Obpbk
function name:  run
number of ops:  33
compiled vars:  !0 = $name, !1 = $callback, !2 = $names, !3 = $time, !4 = $i, !5 = $item
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   28     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   29     2        BIND_GLOBAL                                                  !2, 'names'
   31     3        INIT_FCALL                                                   'microtime'
          4        SEND_VAL                                                     <true>
          5        DO_ICALL                                             $6      
          6        ASSIGN                                                       !3, $6
   33     7        ASSIGN                                                       !4, 0
          8      > JMP                                                          ->17
   34     9    > > FE_RESET_R                                           $9      <array>, ->15
         10    > > FE_FETCH_R                                                   $9, !5, ->15
   35    11    >   INIT_DYNAMIC_CALL                                            !1
         12        SEND_VAR_EX                                                  !5
         13        DO_FCALL                                          0          
   34    14      > JMP                                                          ->10
         15    >   FE_FREE                                                      $9
   33    16        PRE_INC                                                      !4
         17    >   FETCH_CONSTANT                                       ~12     'COUNT'
         18        IS_SMALLER                                                   !4, ~12
         19      > JMPNZ                                                        ~13, ->9
   39    20    >   INIT_FCALL                                                   'microtime'
         21        SEND_VAL                                                     <true>
         22        DO_ICALL                                             $14     
         23        SUB                                                  ~15     $14, !3
         24        ASSIGN                                                       !3, ~15
   41    25        INIT_FCALL                                                   'sprintf'
         26        SEND_VAL                                                     '%25.6f+ms%3A+%25s'
         27        SEND_VAR                                                     !3
         28        SEND_VAR                                                     !0
         29        DO_ICALL                                             $17     
         30        ECHO                                                         $17
         31        ECHO                                                         '%0A'
   42    32      > RETURN                                                       null

End of function run

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
170.97 ms | 1139 KiB | 22 Q