3v4l.org

run code in 300+ PHP versions simultaneously
<?php /*** Results on my machine *** php 7.2 array_filter: 2.5147440433502 foreach: 0.13733291625977 for i: 0.24090600013733 php 7.4 array_filter: 0.057109117507935 foreach: 0.021071910858154 for i: 0.027867078781128 **/ ini_set('memory_limit', '500M'); $data = range(0, 1000000); // ARRAY FILTER $start = microtime(true); $newData = array_filter($data, function ($item) { return $item % 2; }); $end = microtime(true); echo "array_filter: "; echo $end - $start . PHP_EOL; // FOREACH $start = microtime(true); $newData = array(); foreach ($data as $item) { if ($item % 2) { $newData[] = $item; } } $end = microtime(true); echo "foreach: "; echo $end - $start . PHP_EOL; // FOR $start = microtime(true); $newData = array(); $numItems = count($data); for ($i = 0; $i < $numItems; $i++) { if ($data[$i] % 2) { $newData[] = $data[$i]; } } $end = microtime(true); echo "for i: "; echo $end - $start . PHP_EOL;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 33, Position 2 = 39
Branch analysis from position: 33
2 jumps found. (Code = 78) Position 1 = 34, Position 2 = 39
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 38
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 38
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 64
Branch analysis from position: 64
2 jumps found. (Code = 44) Position 1 = 66, Position 2 = 57
Branch analysis from position: 66
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 60, Position 2 = 63
Branch analysis from position: 60
2 jumps found. (Code = 44) Position 1 = 66, Position 2 = 57
Branch analysis from position: 66
Branch analysis from position: 57
Branch analysis from position: 63
Branch analysis from position: 39
filename:       /in/Zit6P
function name:  (null)
number of ops:  75
compiled vars:  !0 = $data, !1 = $start, !2 = $newData, !3 = $end, !4 = $item, !5 = $numItems, !6 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   INIT_FCALL                                               'ini_set'
          1        SEND_VAL                                                 'memory_limit'
          2        SEND_VAL                                                 '500M'
          3        DO_ICALL                                                 
   15     4        INIT_FCALL                                               'range'
          5        SEND_VAL                                                 0
          6        SEND_VAL                                                 1000000
          7        DO_ICALL                                         $8      
          8        ASSIGN                                                   !0, $8
   18     9        INIT_FCALL                                               'microtime'
         10        SEND_VAL                                                 <true>
         11        DO_ICALL                                         $10     
         12        ASSIGN                                                   !1, $10
   19    13        INIT_FCALL                                               'array_filter'
         14        SEND_VAR                                                 !0
         15        DECLARE_LAMBDA_FUNCTION                          ~12     [0]
   21    16        SEND_VAL                                                 ~12
   19    17        DO_ICALL                                         $13     
         18        ASSIGN                                                   !2, $13
   22    19        INIT_FCALL                                               'microtime'
         20        SEND_VAL                                                 <true>
         21        DO_ICALL                                         $15     
         22        ASSIGN                                                   !3, $15
   24    23        ECHO                                                     'array_filter%3A+'
   25    24        SUB                                              ~17     !3, !1
         25        CONCAT                                           ~18     ~17, '%0A'
         26        ECHO                                                     ~18
   28    27        INIT_FCALL                                               'microtime'
         28        SEND_VAL                                                 <true>
         29        DO_ICALL                                         $19     
         30        ASSIGN                                                   !1, $19
   29    31        ASSIGN                                                   !2, <array>
   30    32      > FE_RESET_R                                       $22     !0, ->39
         33    > > FE_FETCH_R                                               $22, !4, ->39
   31    34    >   MOD                                              ~23     !4, 2
         35      > JMPZ                                                     ~23, ->38
   32    36    >   ASSIGN_DIM                                               !2
         37        OP_DATA                                                  !4
   30    38    > > JMP                                                      ->33
         39    >   FE_FREE                                                  $22
   35    40        INIT_FCALL                                               'microtime'
         41        SEND_VAL                                                 <true>
         42        DO_ICALL                                         $25     
         43        ASSIGN                                                   !3, $25
   37    44        ECHO                                                     'foreach%3A+'
   38    45        SUB                                              ~27     !3, !1
         46        CONCAT                                           ~28     ~27, '%0A'
         47        ECHO                                                     ~28
   41    48        INIT_FCALL                                               'microtime'
         49        SEND_VAL                                                 <true>
         50        DO_ICALL                                         $29     
         51        ASSIGN                                                   !1, $29
   42    52        ASSIGN                                                   !2, <array>
   43    53        COUNT                                            ~32     !0
         54        ASSIGN                                                   !5, ~32
   44    55        ASSIGN                                                   !6, 0
         56      > JMP                                                      ->64
   45    57    >   FETCH_DIM_R                                      ~35     !0, !6
         58        MOD                                              ~36     ~35, 2
         59      > JMPZ                                                     ~36, ->63
   46    60    >   FETCH_DIM_R                                      ~38     !0, !6
         61        ASSIGN_DIM                                               !2
         62        OP_DATA                                                  ~38
   44    63    >   PRE_INC                                                  !6
         64    >   IS_SMALLER                                               !6, !5
         65      > JMPNZ                                                    ~40, ->57
   49    66    >   INIT_FCALL                                               'microtime'
         67        SEND_VAL                                                 <true>
         68        DO_ICALL                                         $41     
         69        ASSIGN                                                   !3, $41
   51    70        ECHO                                                     'for+i%3A+'
   52    71        SUB                                              ~43     !3, !1
         72        CONCAT                                           ~44     ~43, '%0A'
         73        ECHO                                                     ~44
   53    74      > 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/Zit6P
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     1        MOD                                              ~1      !0, 2
          2      > RETURN                                                   ~1
   21     3*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.71 ms | 1022 KiB | 17 Q