3v4l.org

run code in 300+ PHP versions simultaneously
<?php function check_unique() { $seen = []; return function ($value) use (&$seen) { if (in_array($value, $seen)) { return false; } $seen[] = $value; return true; }; } const ITEMS = 1000; $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/nUgYf
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', 1000
   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/nUgYf
function name:  check_unique
number of ops:  5
compiled vars:  !0 = $seen
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, <array>
    5     1        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FnUgYf%3A5%240'
          2        BIND_LEXICAL                                             ~2, !0
   11     3      > RETURN                                                   ~2
   12     4*     > RETURN                                                   null

End of function check_unique

Function %00%7Bclosure%7D%2Fin%2FnUgYf%3A5%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nUgYf
function name:  {closure}
number of ops:  12
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        SEND_VAR                                                 !1
          5        DO_ICALL                                         $2      
          6      > JMPZ                                                     $2, ->8
    7     7    > > RETURN                                                   <false>
    9     8    >   ASSIGN_DIM                                               !1
          9        OP_DATA                                                  !0
   10    10      > RETURN                                                   <true>
   11    11*     > RETURN                                                   null

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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.57 ms | 1410 KiB | 25 Q