3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Disable garbage collection to avoid interference gc_disable(); // Helper function to calculate execution time function benchmark(callable $function) { $start = microtime(true); $function(); $end = microtime(true); return $end - $start; } // Create a deeply nested array function createNestedArray($depth = 3, $width = 10) { $data = []; for ($i = 0; $i < $width; $i++) { $data["level_$i"] = ($depth > 1) ? createNestedArray($depth - 1, $width) : rand(1, 100); } return $data; } // Create a deeply nested object function createNestedObject($depth = 3, $width = 10) { $obj = new stdClass(); for ($i = 0; $i < $width; $i++) { $propName = "level_$i"; $obj->$propName = ($depth > 1) ? createNestedObject($depth - 1, $width) : rand(1, 100); } return $obj; } // Function to modify data in nested array function modifyArray(&$data, $depth = 3) { foreach ($data as &$value) { if ($depth > 1 && is_array($value)) { modifyArray($value, $depth - 1); } else { $value *= 2; // Data alteration } } } // Function to modify data in nested object function modifyObject(&$obj, $depth = 3) { foreach ($obj as &$value) { if ($depth > 1 && is_object($value)) { modifyObject($value, $depth - 1); } else { $value *= 2; // Data alteration } } } // Initialize nested structures $depth = 3; $width = 10; $nestedArray = createNestedArray($depth, $width); $nestedObject = createNestedObject($depth, $width); // Benchmark for array $arrayTime = benchmark(function() use (&$nestedArray, $depth) { modifyArray($nestedArray, $depth); }); // Benchmark for object $objectTime = benchmark(function() use (&$nestedObject, $depth) { modifyObject($nestedObject, $depth); }); echo "Array Time: " . $arrayTime . " seconds\n"; echo "Object Time: " . $objectTime . " seconds\n"; gc_enable(); // Re-enable garbage collection ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CGe6e
function name:  (null)
number of ops:  37
compiled vars:  !0 = $depth, !1 = $width, !2 = $nestedArray, !3 = $nestedObject, !4 = $arrayTime, !5 = $objectTime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   INIT_FCALL                                               'gc_disable'
          1        DO_ICALL                                                 
   56     2        ASSIGN                                                   !0, 3
   57     3        ASSIGN                                                   !1, 10
   58     4        INIT_FCALL                                               'createnestedarray'
          5        SEND_VAR                                                 !0
          6        SEND_VAR                                                 !1
          7        DO_FCALL                                      0  $9      
          8        ASSIGN                                                   !2, $9
   59     9        INIT_FCALL                                               'createnestedobject'
         10        SEND_VAR                                                 !0
         11        SEND_VAR                                                 !1
         12        DO_FCALL                                      0  $11     
         13        ASSIGN                                                   !3, $11
   62    14        INIT_FCALL                                               'benchmark'
         15        DECLARE_LAMBDA_FUNCTION                          ~13     [0]
         16        BIND_LEXICAL                                             ~13, !2
         17        BIND_LEXICAL                                             ~13, !0
   64    18        SEND_VAL                                                 ~13
   62    19        DO_FCALL                                      0  $14     
         20        ASSIGN                                                   !4, $14
   67    21        INIT_FCALL                                               'benchmark'
         22        DECLARE_LAMBDA_FUNCTION                          ~16     [1]
         23        BIND_LEXICAL                                             ~16, !3
         24        BIND_LEXICAL                                             ~16, !0
   69    25        SEND_VAL                                                 ~16
   67    26        DO_FCALL                                      0  $17     
         27        ASSIGN                                                   !5, $17
   71    28        CONCAT                                           ~19     'Array+Time%3A+', !4
         29        CONCAT                                           ~20     ~19, '+seconds%0A'
         30        ECHO                                                     ~20
   72    31        CONCAT                                           ~21     'Object+Time%3A+', !5
         32        CONCAT                                           ~22     ~21, '+seconds%0A'
         33        ECHO                                                     ~22
   74    34        INIT_FCALL                                               'gc_enable'
         35        DO_ICALL                                                 
   75    36      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CGe6e
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $nestedArray, !1 = $depth
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   BIND_STATIC                                              !0
          1        BIND_STATIC                                              !1
   63     2        INIT_FCALL                                               'modifyarray'
          3        SEND_REF                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0          
   64     6      > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CGe6e
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $nestedObject, !1 = $depth
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   67     0  E >   BIND_STATIC                                              !0
          1        BIND_STATIC                                              !1
   68     2        INIT_FCALL                                               'modifyobject'
          3        SEND_REF                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0          
   69     6      > RETURN                                                   null

End of Dynamic Function 1

Function benchmark:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CGe6e
function name:  benchmark
number of ops:  14
compiled vars:  !0 = $function, !1 = $start, !2 = $end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        INIT_FCALL                                               'microtime'
          2        SEND_VAL                                                 <true>
          3        DO_ICALL                                         $3      
          4        ASSIGN                                                   !1, $3
    9     5        INIT_DYNAMIC_CALL                                        !0
          6        DO_FCALL                                      0          
   10     7        INIT_FCALL                                               'microtime'
          8        SEND_VAL                                                 <true>
          9        DO_ICALL                                         $6      
         10        ASSIGN                                                   !2, $6
   11    11        SUB                                              ~8      !2, !1
         12      > RETURN                                                   ~8
   12    13*     > RETURN                                                   null

End of function benchmark

Function createnestedarray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 5
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 16
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 5
Branch analysis from position: 26
Branch analysis from position: 5
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 5
Branch analysis from position: 26
Branch analysis from position: 5
filename:       /in/CGe6e
function name:  createNestedArray
number of ops:  28
compiled vars:  !0 = $depth, !1 = $width, !2 = $data, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV_INIT                                        !0      3
          1        RECV_INIT                                        !1      10
   16     2        ASSIGN                                                   !2, <array>
   17     3        ASSIGN                                                   !3, 0
          4      > JMP                                                      ->24
   18     5    >   NOP                                                      
          6        FAST_CONCAT                                      ~6      'level_', !3
          7        IS_SMALLER                                               1, !0
          8      > JMPZ                                                     ~8, ->16
          9    >   INIT_FCALL_BY_NAME                                       'createNestedArray'
         10        SUB                                              ~9      !0, 1
         11        SEND_VAL_EX                                              ~9
         12        SEND_VAR_EX                                              !1
         13        DO_FCALL                                      0  $10     
         14        QM_ASSIGN                                        ~11     $10
         15      > JMP                                                      ->21
         16    >   INIT_FCALL                                               'rand'
         17        SEND_VAL                                                 1
         18        SEND_VAL                                                 100
         19        DO_ICALL                                         $12     
         20        QM_ASSIGN                                        ~11     $12
         21    >   ASSIGN_DIM                                               !2, ~6
         22        OP_DATA                                                  ~11
   17    23        PRE_INC                                                  !3
         24    >   IS_SMALLER                                               !3, !1
         25      > JMPNZ                                                    ~14, ->5
   20    26    > > RETURN                                                   !2
   21    27*     > RETURN                                                   null

End of function createnestedarray

Function createnestedobject:
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 = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 19
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
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: 19
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 7
Branch analysis from position: 29
Branch analysis from position: 7
filename:       /in/CGe6e
function name:  createNestedObject
number of ops:  31
compiled vars:  !0 = $depth, !1 = $width, !2 = $obj, !3 = $i, !4 = $propName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV_INIT                                        !0      3
          1        RECV_INIT                                        !1      10
   25     2        NEW                                              $5      'stdClass'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !2, $5
   26     5        ASSIGN                                                   !3, 0
          6      > JMP                                                      ->27
   27     7    >   NOP                                                      
          8        FAST_CONCAT                                      ~9      'level_', !3
          9        ASSIGN                                                   !4, ~9
   28    10        IS_SMALLER                                               1, !0
         11      > JMPZ                                                     ~12, ->19
         12    >   INIT_FCALL_BY_NAME                                       'createNestedObject'
         13        SUB                                              ~13     !0, 1
         14        SEND_VAL_EX                                              ~13
         15        SEND_VAR_EX                                              !1
         16        DO_FCALL                                      0  $14     
         17        QM_ASSIGN                                        ~15     $14
         18      > JMP                                                      ->24
         19    >   INIT_FCALL                                               'rand'
         20        SEND_VAL                                                 1
         21        SEND_VAL                                                 100
         22        DO_ICALL                                         $16     
         23        QM_ASSIGN                                        ~15     $16
         24    >   ASSIGN_OBJ                                               !2, !4
         25        OP_DATA                                                  ~15
   26    26        PRE_INC                                                  !3
         27    >   IS_SMALLER                                               !3, !1
         28      > JMPNZ                                                    ~18, ->7
   30    29    > > RETURN                                                   !2
   31    30*     > RETURN                                                   null

End of function createnestedobject

Function modifyarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 3, Position 2 = 17
Branch analysis from position: 3
2 jumps found. (Code = 126) Position 1 = 4, Position 2 = 17
Branch analysis from position: 4
2 jumps found. (Code = 46) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 8
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/CGe6e
function name:  modifyArray
number of ops:  19
compiled vars:  !0 = $data, !1 = $depth, !2 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      3
   35     2      > FE_RESET_RW                                      $3      !0, ->17
          3    > > FE_FETCH_RW                                              $3, !2, ->17
   36     4    >   IS_SMALLER                                       ~4      1, !1
          5      > JMPZ_EX                                          ~4      ~4, ->8
          6    >   TYPE_CHECK                                  128  ~5      !2
          7        BOOL                                             ~4      ~5
          8    > > JMPZ                                                     ~4, ->15
   37     9    >   INIT_FCALL_BY_NAME                                       'modifyArray'
         10        SEND_VAR_EX                                              !2
         11        SUB                                              ~6      !1, 1
         12        SEND_VAL_EX                                              ~6
         13        DO_FCALL                                      0          
   36    14      > JMP                                                      ->16
   39    15    >   ASSIGN_OP                                     3          !2, 2
   35    16    > > JMP                                                      ->3
         17    >   FE_FREE                                                  $3
   42    18      > RETURN                                                   null

End of function modifyarray

Function modifyobject:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 3, Position 2 = 17
Branch analysis from position: 3
2 jumps found. (Code = 126) Position 1 = 4, Position 2 = 17
Branch analysis from position: 4
2 jumps found. (Code = 46) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 8
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/CGe6e
function name:  modifyObject
number of ops:  19
compiled vars:  !0 = $obj, !1 = $depth, !2 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      3
   46     2      > FE_RESET_RW                                      $3      !0, ->17
          3    > > FE_FETCH_RW                                              $3, !2, ->17
   47     4    >   IS_SMALLER                                       ~4      1, !1
          5      > JMPZ_EX                                          ~4      ~4, ->8
          6    >   TYPE_CHECK                                  256  ~5      !2
          7        BOOL                                             ~4      ~5
          8    > > JMPZ                                                     ~4, ->15
   48     9    >   INIT_FCALL_BY_NAME                                       'modifyObject'
         10        SEND_VAR_EX                                              !2
         11        SUB                                              ~6      !1, 1
         12        SEND_VAL_EX                                              ~6
         13        DO_FCALL                                      0          
   47    14      > JMP                                                      ->16
   50    15    >   ASSIGN_OP                                     3          !2, 2
   46    16    > > JMP                                                      ->3
         17    >   FE_FREE                                                  $3
   53    18      > RETURN                                                   null

End of function modifyobject

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
182.22 ms | 1033 KiB | 23 Q