3v4l.org

run code in 300+ 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 = 54
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 54
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
filename:       /in/Obpbk
function name:  (null)
number of ops:  80
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, ->54
          6    > > FE_FETCH_R                                               $10, !4, ->54
   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        INIT_FCALL                                               'substr'
         27        SEND_VAR                                                 !4
         28        SEND_VAL                                                 3
         29        DO_ICALL                                         $19     
         30        ASSIGN                                                   !5, $19
   20    31        ASSIGN_DIM                                               !1, !5
         32        OP_DATA                                                  !4
   21    33        INIT_FCALL                                               'lcfirst'
         34        SEND_VAR                                                 !5
         35        DO_ICALL                                         $22     
         36        ASSIGN_DIM                                               !2, $22
         37        OP_DATA                                                  !4
   23    38        INIT_FCALL                                               'strtolower'
         39        SEND_VAR                                                 !5
         40        DO_ICALL                                         $24     
         41        ASSIGN_DIM                                               !1, $24
         42        OP_DATA                                                  !4
   24    43        INIT_FCALL                                               'strtolower'
         44        SEND_VAR                                                 !5
         45        DO_ICALL                                         $26     
         46        ASSIGN_DIM                                               !2, $26
         47        OP_DATA                                                  !4
   25    48        INIT_FCALL                                               'strtolower'
         49        SEND_VAR                                                 !5
         50        DO_ICALL                                         $28     
         51        ASSIGN_DIM                                               !3, $28
         52        OP_DATA                                                  !4
   10    53      > JMP                                                      ->6
         54    >   FE_FREE                                                  $10
   44    55        INIT_FCALL                                               'run'
         56        SEND_VAL                                                 'old'
         57        DECLARE_LAMBDA_FUNCTION                          ~30     [0]
         58        BIND_LEXICAL                                             ~30, !1
   50    59        SEND_VAL                                                 ~30
   44    60        DO_FCALL                                      0          
   51    61        INIT_FCALL                                               'run'
         62        SEND_VAL                                                 'new'
         63        DECLARE_LAMBDA_FUNCTION                          ~32     [1]
         64        BIND_LEXICAL                                             ~32, !2
   57    65        SEND_VAL                                                 ~32
   51    66        DO_FCALL                                      0          
   58    67        INIT_FCALL                                               'run'
         68        SEND_VAL                                                 'simplified'
         69        DECLARE_LAMBDA_FUNCTION                          ~34     [2]
         70        BIND_LEXICAL                                             ~34, !3
   62    71        SEND_VAL                                                 ~34
   58    72        DO_FCALL                                      0          
   63    73        INIT_FCALL                                               'run'
         74        SEND_VAL                                                 'simplified2'
         75        DECLARE_LAMBDA_FUNCTION                          ~36     [3]
         76        BIND_LEXICAL                                             ~36, !3
   69    77        SEND_VAL                                                 ~36
   63    78        DO_FCALL                                      0          
   69    79      > 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}
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}
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}
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}
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.0.0


preferences:
145.77 ms | 1029 KiB | 22 Q