3v4l.org

run code in 300+ PHP versions simultaneously
<?php function check_unique() { $seen = new ArrayObject(); return function ($value) use ($seen) { if (in_array($value, (array)$seen)) { return false; } $seen[] = $value; return true; }; } const ITEMS = 10000; $array = array_merge(range(1, ITEMS, 3), range(1, ITEMS, 2)); echo "started with ", count($array), " items\n"; $check_unique = check_unique(); $unique = []; echo "memory usage ", memory_get_peak_usage(), "\n"; $time = -microtime(true); foreach ($array as $value) { if ($check_unique($value)) { $unique[] = $value; } } $time += microtime(true); echo "memory usage ", memory_get_peak_usage(), "\n"; echo "took $time sec\n"; echo "finished with ", count($unique), " items\n";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 37, Position 2 = 45
Branch analysis from position: 37
2 jumps found. (Code = 78) Position 1 = 38, Position 2 = 45
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 44
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 44
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
filename:       /in/4pvOJ
function name:  (null)
number of ops:  64
compiled vars:  !0 = $array, !1 = $check_unique, !2 = $unique, !3 = $time, !4 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   DECLARE_CONST                                            'ITEMS', 10000
   15     1        INIT_FCALL                                               'array_merge'
          2        INIT_FCALL                                               'range'
          3        SEND_VAL                                                 1
          4        FETCH_CONSTANT                                   ~5      'ITEMS'
          5        SEND_VAL                                                 ~5
          6        SEND_VAL                                                 3
          7        DO_ICALL                                         $6      
          8        SEND_VAR                                                 $6
          9        INIT_FCALL                                               'range'
         10        SEND_VAL                                                 1
         11        FETCH_CONSTANT                                   ~7      'ITEMS'
         12        SEND_VAL                                                 ~7
         13        SEND_VAL                                                 2
         14        DO_ICALL                                         $8      
         15        SEND_VAR                                                 $8
         16        DO_ICALL                                         $9      
         17        ASSIGN                                                   !0, $9
   16    18        ECHO                                                     'started+with+'
         19        COUNT                                            ~11     !0
         20        ECHO                                                     ~11
         21        ECHO                                                     '+items%0A'
   18    22        INIT_FCALL                                               'check_unique'
         23        DO_FCALL                                      0  $12     
         24        ASSIGN                                                   !1, $12
   19    25        ASSIGN                                                   !2, <array>
   21    26        ECHO                                                     'memory+usage+'
         27        INIT_FCALL                                               'memory_get_peak_usage'
         28        DO_ICALL                                         $15     
         29        ECHO                                                     $15
         30        ECHO                                                     '%0A'
   22    31        INIT_FCALL                                               'microtime'
         32        SEND_VAL                                                 <true>
         33        DO_ICALL                                         $16     
         34        MUL                                              ~17     $16, -1
         35        ASSIGN                                                   !3, ~17
   23    36      > FE_RESET_R                                       $19     !0, ->45
         37    > > FE_FETCH_R                                               $19, !4, ->45
   24    38    >   INIT_DYNAMIC_CALL                                        !1
         39        SEND_VAR_EX                                              !4
         40        DO_FCALL                                      0  $20     
         41      > JMPZ                                                     $20, ->44
   25    42    >   ASSIGN_DIM                                               !2
         43        OP_DATA                                                  !4
   23    44    > > JMP                                                      ->37
         45    >   FE_FREE                                                  $19
   28    46        INIT_FCALL                                               'microtime'
         47        SEND_VAL                                                 <true>
         48        DO_ICALL                                         $22     
         49        ASSIGN_OP                                     1          !3, $22
   29    50        ECHO                                                     'memory+usage+'
         51        INIT_FCALL                                               'memory_get_peak_usage'
         52        DO_ICALL                                         $24     
         53        ECHO                                                     $24
         54        ECHO                                                     '%0A'
   30    55        ROPE_INIT                                     3  ~26     'took+'
         56        ROPE_ADD                                      1  ~26     ~26, !3
         57        ROPE_END                                      2  ~25     ~26, '+sec%0A'
         58        ECHO                                                     ~25
   31    59        ECHO                                                     'finished+with+'
         60        COUNT                                            ~28     !2
         61        ECHO                                                     ~28
         62        ECHO                                                     '+items%0A'
         63      > RETURN                                                   1

Function check_unique:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4pvOJ
function name:  check_unique
number of ops:  7
compiled vars:  !0 = $seen
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   NEW                                              $1      'ArrayObject'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
    5     3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F4pvOJ%3A5%240'
          4        BIND_LEXICAL                                             ~4, !0
   11     5      > RETURN                                                   ~4
   12     6*     > RETURN                                                   null

End of function check_unique

Function %00%7Bclosure%7D%2Fin%2F4pvOJ%3A5%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4pvOJ
function name:  {closure}
number of ops:  13
compiled vars:  !0 = $value, !1 = $seen
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
    6     2        INIT_FCALL                                               'in_array'
          3        SEND_VAR                                                 !0
          4        CAST                                          7  ~2      !1
          5        SEND_VAL                                                 ~2
          6        DO_ICALL                                         $3      
          7      > JMPZ                                                     $3, ->9
    7     8    > > RETURN                                                   <false>
    9     9    >   ASSIGN_DIM                                               !1
         10        OP_DATA                                                  !0
   10    11      > RETURN                                                   <true>
   11    12*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F4pvOJ%3A5%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.05 ms | 1407 KiB | 24 Q