3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Object hashing tests. */ $sos = new SplObjectStorage(); $docs = array(); $iterations = (int) 10000; //100000; for ($i = 0; $i < $iterations; ++$i) { $doc = new DOMDocument(); //$doc = new stdClass(); $docs[] = $doc; } $start = $finis = 0; $mem_empty = memory_get_usage(); // Load the SplObjectStorage $start = microtime(TRUE); foreach ($docs as $d) { $sos->attach($d); } $finis = microtime(TRUE); $time_to_fill = $finis - $start; // Check membership on the object storage $start = microtime(FALSE); foreach ($docs as $d) { $sos->contains($d); } $finis = microtime(FALSE); $time_to_check = $finis - $start; $mem_spl = memory_get_usage(); $mem_used = $mem_spl - $mem_empty; printf("SplObjectStorage:\nTime to fill: %0.12f.\nTime to check: %0.12f.\nMemory: %d\n\n", $time_to_fill, $time_to_check, $mem_used); unset($sos); $mem_empty = memory_get_usage(); // Test arrays: $start = microtime(TRUE); $arr = array(); // Load the array foreach ($docs as $d) { $arr[spl_object_hash($d)] = $d; } $finis = microtime(TRUE); $time_to_fill = $finis - $start; // Check membership on the array $start = microtime(FALSE); foreach ($docs as $d) { //$arr[spl_object_hash($d)]; isset($arr[spl_object_hash($d)]); } $finis = microtime(FALSE); $time_to_check = $finis - $start; $mem_arr = memory_get_usage(); $mem_used = $mem_arr - $mem_empty; printf("Arrays:\nTime to fill: %0.12f.\nTime to check: %0.12f.\nMemory: %d\n\n", $time_to_fill, $time_to_check, $mem_used);
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 = 8
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 31
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 31
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 31
2 jumps found. (Code = 77) Position 1 = 43, Position 2 = 48
Branch analysis from position: 43
2 jumps found. (Code = 78) Position 1 = 44, Position 2 = 48
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
Branch analysis from position: 48
2 jumps found. (Code = 77) Position 1 = 76, Position 2 = 83
Branch analysis from position: 76
2 jumps found. (Code = 78) Position 1 = 77, Position 2 = 83
Branch analysis from position: 77
1 jumps found. (Code = 42) Position 1 = 76
Branch analysis from position: 76
Branch analysis from position: 83
2 jumps found. (Code = 77) Position 1 = 95, Position 2 = 102
Branch analysis from position: 95
2 jumps found. (Code = 78) Position 1 = 96, Position 2 = 102
Branch analysis from position: 96
1 jumps found. (Code = 42) Position 1 = 95
Branch analysis from position: 95
Branch analysis from position: 102
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 102
Branch analysis from position: 83
Branch analysis from position: 48
Branch analysis from position: 31
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 8
Branch analysis from position: 16
Branch analysis from position: 8
filename:       /in/1HEUs
function name:  (null)
number of ops:  121
compiled vars:  !0 = $sos, !1 = $docs, !2 = $iterations, !3 = $i, !4 = $doc, !5 = $start, !6 = $finis, !7 = $mem_empty, !8 = $d, !9 = $time_to_fill, !10 = $time_to_check, !11 = $mem_spl, !12 = $mem_used, !13 = $arr, !14 = $mem_arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   NEW                                              $15     'SplObjectStorage'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $15
    7     3        ASSIGN                                                   !1, <array>
    8     4        CAST                                          4  ~19     10000
          5        ASSIGN                                                   !2, ~19
   10     6        ASSIGN                                                   !3, 0
          7      > JMP                                                      ->14
   11     8    >   NEW                                              $22     'DOMDocument'
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !4, $22
   14    11        ASSIGN_DIM                                               !1
         12        OP_DATA                                                  !4
   10    13        PRE_INC                                                  !3
         14    >   IS_SMALLER                                               !3, !2
         15      > JMPNZ                                                    ~27, ->8
   18    16    >   ASSIGN                                           ~28     !6, 0
         17        ASSIGN                                                   !5, ~28
   20    18        INIT_FCALL                                               'memory_get_usage'
         19        DO_ICALL                                         $30     
         20        ASSIGN                                                   !7, $30
   23    21        INIT_FCALL                                               'microtime'
         22        SEND_VAL                                                 <true>
         23        DO_ICALL                                         $32     
         24        ASSIGN                                                   !5, $32
   24    25      > FE_RESET_R                                       $34     !1, ->31
         26    > > FE_FETCH_R                                               $34, !8, ->31
   25    27    >   INIT_METHOD_CALL                                         !0, 'attach'
         28        SEND_VAR_EX                                              !8
         29        DO_FCALL                                      0          
   24    30      > JMP                                                      ->26
         31    >   FE_FREE                                                  $34
   27    32        INIT_FCALL                                               'microtime'
         33        SEND_VAL                                                 <true>
         34        DO_ICALL                                         $36     
         35        ASSIGN                                                   !6, $36
   29    36        SUB                                              ~38     !6, !5
         37        ASSIGN                                                   !9, ~38
   32    38        INIT_FCALL                                               'microtime'
         39        SEND_VAL                                                 <false>
         40        DO_ICALL                                         $40     
         41        ASSIGN                                                   !5, $40
   33    42      > FE_RESET_R                                       $42     !1, ->48
         43    > > FE_FETCH_R                                               $42, !8, ->48
   34    44    >   INIT_METHOD_CALL                                         !0, 'contains'
         45        SEND_VAR_EX                                              !8
         46        DO_FCALL                                      0          
   33    47      > JMP                                                      ->43
         48    >   FE_FREE                                                  $42
   37    49        INIT_FCALL                                               'microtime'
         50        SEND_VAL                                                 <false>
         51        DO_ICALL                                         $44     
         52        ASSIGN                                                   !6, $44
   39    53        SUB                                              ~46     !6, !5
         54        ASSIGN                                                   !10, ~46
   41    55        INIT_FCALL                                               'memory_get_usage'
         56        DO_ICALL                                         $48     
         57        ASSIGN                                                   !11, $48
   43    58        SUB                                              ~50     !11, !7
         59        ASSIGN                                                   !12, ~50
   45    60        INIT_FCALL                                               'printf'
         61        SEND_VAL                                                 'SplObjectStorage%3A%0ATime+to+fill%3A+%250.12f.%0ATime+to+check%3A+%250.12f.%0AMemory%3A+%25d%0A%0A'
         62        SEND_VAR                                                 !9
         63        SEND_VAR                                                 !10
         64        SEND_VAR                                                 !12
         65        DO_ICALL                                                 
   47    66        UNSET_CV                                                 !0
   48    67        INIT_FCALL                                               'memory_get_usage'
         68        DO_ICALL                                         $53     
         69        ASSIGN                                                   !7, $53
   51    70        INIT_FCALL                                               'microtime'
         71        SEND_VAL                                                 <true>
         72        DO_ICALL                                         $55     
         73        ASSIGN                                                   !5, $55
   52    74        ASSIGN                                                   !13, <array>
   55    75      > FE_RESET_R                                       $58     !1, ->83
         76    > > FE_FETCH_R                                               $58, !8, ->83
   56    77    >   INIT_FCALL                                               'spl_object_hash'
         78        SEND_VAR                                                 !8
         79        DO_ICALL                                         $59     
         80        ASSIGN_DIM                                               !13, $59
         81        OP_DATA                                                  !8
   55    82      > JMP                                                      ->76
         83    >   FE_FREE                                                  $58
   58    84        INIT_FCALL                                               'microtime'
         85        SEND_VAL                                                 <true>
         86        DO_ICALL                                         $61     
         87        ASSIGN                                                   !6, $61
   60    88        SUB                                              ~63     !6, !5
         89        ASSIGN                                                   !9, ~63
   63    90        INIT_FCALL                                               'microtime'
         91        SEND_VAL                                                 <false>
         92        DO_ICALL                                         $65     
         93        ASSIGN                                                   !5, $65
   64    94      > FE_RESET_R                                       $67     !1, ->102
         95    > > FE_FETCH_R                                               $67, !8, ->102
   66    96    >   INIT_FCALL                                               'spl_object_hash'
         97        SEND_VAR                                                 !8
         98        DO_ICALL                                         $68     
         99        ISSET_ISEMPTY_DIM_OBJ                         0  ~69     !13, $68
        100        FREE                                                     ~69
   64   101      > JMP                                                      ->95
        102    >   FE_FREE                                                  $67
   69   103        INIT_FCALL                                               'microtime'
        104        SEND_VAL                                                 <false>
        105        DO_ICALL                                         $70     
        106        ASSIGN                                                   !6, $70
   71   107        SUB                                              ~72     !6, !5
        108        ASSIGN                                                   !10, ~72
   72   109        INIT_FCALL                                               'memory_get_usage'
        110        DO_ICALL                                         $74     
        111        ASSIGN                                                   !14, $74
   74   112        SUB                                              ~76     !14, !7
        113        ASSIGN                                                   !12, ~76
   77   114        INIT_FCALL                                               'printf'
        115        SEND_VAL                                                 'Arrays%3A%0ATime+to+fill%3A+%250.12f.%0ATime+to+check%3A+%250.12f.%0AMemory%3A+%25d%0A%0A'
        116        SEND_VAR                                                 !9
        117        SEND_VAR                                                 !10
        118        SEND_VAR                                                 !12
        119        DO_ICALL                                                 
        120      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.83 ms | 1408 KiB | 21 Q