3v4l.org

run code in 300+ PHP versions simultaneously
<?php //Access every element once using array_filter() $objectArray = []; $objectNames = []; for($i = 0; $i < 1000; $i ++){ $objName = 'object_name_' . ($i + 1); $objectNames[] = $objName; $obj = new stdClass(); $obj->name = $objName; $obj->description = 'test description'; $obj->accessed = 0; $objectArray[] = $obj; } foreach($objectNames as $name){ $iterations = getObjectWithArray_Filter($name, $objectArray); } echo $iterations . " iterations using array_filter()<br/>\n"; //Access every element once using foreach(){} $objectArray = []; $objectNames = []; for($i = 0; $i < 1000; $i ++){ $objName = 'object_name_' . ($i + 1); $objectNames[] = $objName; $obj = new stdClass(); $obj->name = $objName; $obj->description = 'test description'; $obj->accessed = 0; $objectArray[] = $obj; } foreach($objectNames as $name){ $iterations = getObjectWithForeach($name, $objectArray); } echo $iterations . " iterations using foreach(){}<br/>\n"; //Access every element once using Associative array $objectArray = []; $objectNames = []; for($i = 0; $i < 1000; $i ++){ $objName = 'object_name_' . ($i + 1); $objectNames[] = $objName; $obj = new stdClass(); $obj->name = $objName; $obj->description = 'test description'; $obj->accessed = 0; $objectArray[] = $obj; } $associativeArray = []; foreach($objectArray as $object){ $associativeArray[$object->name] = $object; $object->accessed ++; } foreach($objectNames as $name){ $iterations = getObjectFromAssociativeArray($objName, $associativeArray); } echo $iterations . " iterations using associative array{}<br/>\n"; //================================================================= function getObjectWithArray_Filter($objectName, array $objectArray){ $myobjects = array_filter($objectArray, function($e) use($objectName) { $e->accessed ++; return strcmp($e->name, $objectName) == 0; }); $iterations = 0; foreach($objectArray as $object){ $iterations += $object->accessed; } return $iterations; } function getObjectWithForeach($objectName, array $objectArray){ $iterations = 0; $found = false; $count = 0; while(!$found){ $objectArray[$count]->accessed ++; if($objectArray[$count]->name === $objectName){ $found = true; } $count ++; } foreach($objectArray as $object){ $iterations += $object->accessed; } return $iterations; } function getObjectFromAssociativeArray($objectName, array $objectArray){ $iterations = 0; if($objectName === $objectArray[$objectName]->name){ $objectArray[$objectName]->accessed ++; } foreach($objectArray as $object){ $iterations += $object->accessed; } return $iterations; }

Abusive script

This script was stopped while abusing our resources

Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 4
Branch analysis from position: 23
2 jumps found. (Code = 77) Position 1 = 24, Position 2 = 31
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 31
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
2 jumps found. (Code = 44) Position 1 = 57, Position 2 = 38
Branch analysis from position: 57
2 jumps found. (Code = 77) Position 1 = 58, Position 2 = 65
Branch analysis from position: 58
2 jumps found. (Code = 78) Position 1 = 59, Position 2 = 65
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 89
Branch analysis from position: 89
2 jumps found. (Code = 44) Position 1 = 91, Position 2 = 72
Branch analysis from position: 91
2 jumps found. (Code = 77) Position 1 = 93, Position 2 = 99
Branch analysis from position: 93
2 jumps found. (Code = 78) Position 1 = 94, Position 2 = 99
Branch analysis from position: 94
1 jumps found. (Code = 42) Position 1 = 93
Branch analysis from position: 93
Branch analysis from position: 99
2 jumps found. (Code = 77) Position 1 = 101, Position 2 = 108
Branch analysis from position: 101
2 jumps found. (Code = 78) Position 1 = 102, Position 2 = 108
Branch analysis from position: 102
1 jumps found. (Code = 42) Position 1 = 101
Branch analysis from position: 101
Branch analysis from position: 108
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 108
Branch analysis from position: 99
Branch analysis from position: 72
2 jumps found. (Code = 44) Position 1 = 91, Position 2 = 72
Branch analysis from position: 91
Branch analysis from position: 72
Branch analysis from position: 65
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 57, Position 2 = 38
Branch analysis from position: 57
Branch analysis from position: 38
Branch analysis from position: 31
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 4
Branch analysis from position: 23
Branch analysis from position: 4
filename:       /in/IUnA0
function name:  (null)
number of ops:  112
compiled vars:  !0 = $objectArray, !1 = $objectNames, !2 = $i, !3 = $objName, !4 = $obj, !5 = $name, !6 = $iterations, !7 = $associativeArray, !8 = $object
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, <array>
    5     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->21
    6     4    >   ADD                                              ~12     !2, 1
          5        CONCAT                                           ~13     'object_name_', ~12
          6        ASSIGN                                                   !3, ~13
    7     7        ASSIGN_DIM                                               !1
          8        OP_DATA                                                  !3
    8     9        NEW                                              $16     'stdClass'
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !4, $16
    9    12        ASSIGN_OBJ                                               !4, 'name'
         13        OP_DATA                                                  !3
   10    14        ASSIGN_OBJ                                               !4, 'description'
         15        OP_DATA                                                  'test+description'
   11    16        ASSIGN_OBJ                                               !4, 'accessed'
         17        OP_DATA                                                  0
   12    18        ASSIGN_DIM                                               !0
         19        OP_DATA                                                  !4
    5    20        PRE_INC                                                  !2
         21    >   IS_SMALLER                                               !2, 1000
         22      > JMPNZ                                                    ~24, ->4
   14    23    > > FE_RESET_R                                       $25     !1, ->31
         24    > > FE_FETCH_R                                               $25, !5, ->31
   15    25    >   INIT_FCALL_BY_NAME                                       'getObjectWithArray_Filter'
         26        SEND_VAR_EX                                              !5
         27        SEND_VAR_EX                                              !0
         28        DO_FCALL                                      0  $26     
         29        ASSIGN                                                   !6, $26
   14    30      > JMP                                                      ->24
         31    >   FE_FREE                                                  $25
   17    32        CONCAT                                           ~28     !6, '+iterations+using+array_filter%28%29%3Cbr%2F%3E%0A'
         33        ECHO                                                     ~28
   21    34        ASSIGN                                                   !0, <array>
   22    35        ASSIGN                                                   !1, <array>
   23    36        ASSIGN                                                   !2, 0
         37      > JMP                                                      ->55
   24    38    >   ADD                                              ~32     !2, 1
         39        CONCAT                                           ~33     'object_name_', ~32
         40        ASSIGN                                                   !3, ~33
   25    41        ASSIGN_DIM                                               !1
         42        OP_DATA                                                  !3
   26    43        NEW                                              $36     'stdClass'
         44        DO_FCALL                                      0          
         45        ASSIGN                                                   !4, $36
   27    46        ASSIGN_OBJ                                               !4, 'name'
         47        OP_DATA                                                  !3
   28    48        ASSIGN_OBJ                                               !4, 'description'
         49        OP_DATA                                                  'test+description'
   29    50        ASSIGN_OBJ                                               !4, 'accessed'
         51        OP_DATA                                                  0
   30    52        ASSIGN_DIM                                               !0
         53        OP_DATA                                                  !4
   23    54        PRE_INC                                                  !2
         55    >   IS_SMALLER                                               !2, 1000
         56      > JMPNZ                                                    ~44, ->38
   33    57    > > FE_RESET_R                                       $45     !1, ->65
         58    > > FE_FETCH_R                                               $45, !5, ->65
   34    59    >   INIT_FCALL_BY_NAME                                       'getObjectWithForeach'
         60        SEND_VAR_EX                                              !5
         61        SEND_VAR_EX                                              !0
         62        DO_FCALL                                      0  $46     
         63        ASSIGN                                                   !6, $46
   33    64      > JMP                                                      ->58
         65    >   FE_FREE                                                  $45
   36    66        CONCAT                                           ~48     !6, '+iterations+using+foreach%28%29%7B%7D%3Cbr%2F%3E%0A'
         67        ECHO                                                     ~48
   39    68        ASSIGN                                                   !0, <array>
   40    69        ASSIGN                                                   !1, <array>
   41    70        ASSIGN                                                   !2, 0
         71      > JMP                                                      ->89
   42    72    >   ADD                                              ~52     !2, 1
         73        CONCAT                                           ~53     'object_name_', ~52
         74        ASSIGN                                                   !3, ~53
   43    75        ASSIGN_DIM                                               !1
         76        OP_DATA                                                  !3
   44    77        NEW                                              $56     'stdClass'
         78        DO_FCALL                                      0          
         79        ASSIGN                                                   !4, $56
   45    80        ASSIGN_OBJ                                               !4, 'name'
         81        OP_DATA                                                  !3
   46    82        ASSIGN_OBJ                                               !4, 'description'
         83        OP_DATA                                                  'test+description'
   47    84        ASSIGN_OBJ                                               !4, 'accessed'
         85        OP_DATA                                                  0
   48    86        ASSIGN_DIM                                               !0
         87        OP_DATA                                                  !4
   41    88        PRE_INC                                                  !2
         89    >   IS_SMALLER                                               !2, 1000
         90      > JMPNZ                                                    ~64, ->72
   51    91    >   ASSIGN                                                   !7, <array>
   53    92      > FE_RESET_R                                       $66     !0, ->99
         93    > > FE_FETCH_R                                               $66, !8, ->99
   54    94    >   FETCH_OBJ_R                                      ~67     !8, 'name'
         95        ASSIGN_DIM                                               !7, ~67
         96        OP_DATA                                                  !8
   55    97        PRE_INC_OBJ                                              !8, 'accessed'
   53    98      > JMP                                                      ->93
         99    >   FE_FREE                                                  $66
   58   100      > FE_RESET_R                                       $70     !1, ->108
        101    > > FE_FETCH_R                                               $70, !5, ->108
   59   102    >   INIT_FCALL_BY_NAME                                       'getObjectFromAssociativeArray'
        103        SEND_VAR_EX                                              !3
        104        SEND_VAR_EX                                              !7
        105        DO_FCALL                                      0  $71     
        106        ASSIGN                                                   !6, $71
   58   107      > JMP                                                      ->101
        108    >   FE_FREE                                                  $70
   61   109        CONCAT                                           ~73     !6, '+iterations+using+associative+array%7B%7D%3Cbr%2F%3E%0A'
        110        ECHO                                                     ~73
  102   111      > RETURN                                                   1

Function getobjectwitharray_filter:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 15
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/IUnA0
function name:  getObjectWithArray_Filter
number of ops:  18
compiled vars:  !0 = $objectName, !1 = $objectArray, !2 = $myobjects, !3 = $iterations, !4 = $object
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   65     2        INIT_FCALL                                               'array_filter'
          3        SEND_VAR                                                 !1
          4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FIUnA0%3A65%240'
          5        BIND_LEXICAL                                             ~5, !0
   68     6        SEND_VAL                                                 ~5
          7        DO_ICALL                                         $6      
   65     8        ASSIGN                                                   !2, $6
   69     9        ASSIGN                                                   !3, 0
   70    10      > FE_RESET_R                                       $9      !1, ->15
         11    > > FE_FETCH_R                                               $9, !4, ->15
   71    12    >   FETCH_OBJ_R                                      ~10     !4, 'accessed'
         13        ASSIGN_OP                                     1          !3, ~10
   70    14      > JMP                                                      ->11
         15    >   FE_FREE                                                  $9
   73    16      > RETURN                                                   !3
   74    17*     > RETURN                                                   null

End of function getobjectwitharray_filter

Function %00%7Bclosure%7D%2Fin%2FIUnA0%3A65%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IUnA0
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $e, !1 = $objectName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   66     2        PRE_INC_OBJ                                              !0, 'accessed'
   67     3        INIT_FCALL                                               'strcmp'
          4        FETCH_OBJ_R                                      ~3      !0, 'name'
          5        SEND_VAL                                                 ~3
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $4      
          8        IS_EQUAL                                         ~5      $4, 0
          9      > RETURN                                                   ~5
   68    10*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FIUnA0%3A65%240

Function getobjectwithforeach:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 6
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 21
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 21
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 6
Branch analysis from position: 16
Branch analysis from position: 6
Branch analysis from position: 13
filename:       /in/IUnA0
function name:  getObjectWithForeach
number of ops:  24
compiled vars:  !0 = $objectName, !1 = $objectArray, !2 = $iterations, !3 = $found, !4 = $count, !5 = $object
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   76     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   77     2        ASSIGN                                                   !2, 0
   78     3        ASSIGN                                                   !3, <false>
   79     4        ASSIGN                                                   !4, 0
   80     5      > JMP                                                      ->14
   81     6    >   FETCH_DIM_RW                                     $9      !1, !4
          7        PRE_INC_OBJ                                              $9, 'accessed'
   82     8        FETCH_DIM_R                                      ~11     !1, !4
          9        FETCH_OBJ_R                                      ~12     ~11, 'name'
         10        IS_IDENTICAL                                             !0, ~12
         11      > JMPZ                                                     ~13, ->13
   83    12    >   ASSIGN                                                   !3, <true>
   85    13    >   PRE_INC                                                  !4
   80    14    >   BOOL_NOT                                         ~16     !3
         15      > JMPNZ                                                    ~16, ->6
   87    16    > > FE_RESET_R                                       $17     !1, ->21
         17    > > FE_FETCH_R                                               $17, !5, ->21
   88    18    >   FETCH_OBJ_R                                      ~18     !5, 'accessed'
         19        ASSIGN_OP                                     1          !2, ~18
   87    20      > JMP                                                      ->17
         21    >   FE_FREE                                                  $17
   90    22      > RETURN                                                   !2
   91    23*     > RETURN                                                   null

End of function getobjectwithforeach

Function getobjectfromassociativearray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
Branch analysis from position: 9
filename:       /in/IUnA0
function name:  getObjectFromAssociativeArray
number of ops:  17
compiled vars:  !0 = $objectName, !1 = $objectArray, !2 = $iterations, !3 = $object
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   93     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   94     2        ASSIGN                                                   !2, 0
   95     3        FETCH_DIM_R                                      ~5      !1, !0
          4        FETCH_OBJ_R                                      ~6      ~5, 'name'
          5        IS_IDENTICAL                                             !0, ~6
          6      > JMPZ                                                     ~7, ->9
   96     7    >   FETCH_DIM_RW                                     $8      !1, !0
          8        PRE_INC_OBJ                                              $8, 'accessed'
   98     9    > > FE_RESET_R                                       $10     !1, ->14
         10    > > FE_FETCH_R                                               $10, !3, ->14
   99    11    >   FETCH_OBJ_R                                      ~11     !3, 'accessed'
         12        ASSIGN_OP                                     1          !2, ~11
   98    13      > JMP                                                      ->10
         14    >   FE_FREE                                                  $10
  101    15      > RETURN                                                   !2
  102    16*     > RETURN                                                   null

End of function getobjectfromassociativearray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
247.94 ms | 1416 KiB | 18 Q