3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo '<pre>'; // Setup input array $input = []; for ($i = 0; $i < 100000; $i++) { $input[] = rand(~PHP_INT_MAX, PHP_INT_MAX); } $foreach_if_times = []; $array_filter_times = []; for ($i = 0; $i < 100; $i++) { $start = microtime(true); array_filter($input, function ($item) { return ($item > 0); }); $array_filter_times[] = microtime(true) - $start; } for ($i = 0; $i < 100; $i++) { $start = microtime(true); $result = []; foreach ($input as $item) { if ($item > 0) { $result[] = $item; } } $foreach_if_times[] = microtime(true) - $start; } echo sprintf("Avg time: %.8f\n", $array_filter_avg = array_sum($array_filter_times) / count($array_filter_times)); echo sprintf("Avg time: %.8f\n", $foreach_if_avg = array_sum($foreach_if_times) / count($foreach_if_times)); echo sprintf("Difference: %.8f\nRatio: %.8f\n", $array_filter_avg - $foreach_if_avg, $array_filter_avg / $foreach_if_avg);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 4
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 17
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
2 jumps found. (Code = 44) Position 1 = 59, Position 2 = 37
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
2 jumps found. (Code = 77) Position 1 = 43, Position 2 = 49
Branch analysis from position: 43
2 jumps found. (Code = 78) Position 1 = 44, Position 2 = 49
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 48
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
Branch analysis from position: 48
Branch analysis from position: 49
2 jumps found. (Code = 44) Position 1 = 59, Position 2 = 37
Branch analysis from position: 59
Branch analysis from position: 37
Branch analysis from position: 49
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 17
Branch analysis from position: 35
Branch analysis from position: 17
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 4
Branch analysis from position: 13
Branch analysis from position: 4
filename:       /in/lDY2B
function name:  (null)
number of ops:  90
compiled vars:  !0 = $input, !1 = $i, !2 = $foreach_if_times, !3 = $array_filter_times, !4 = $start, !5 = $result, !6 = $item, !7 = $array_filter_avg, !8 = $foreach_if_avg
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ECHO                                                     '%3Cpre%3E'
    6     1        ASSIGN                                                   !0, <array>
    7     2        ASSIGN                                                   !1, 0
          3      > JMP                                                      ->11
    8     4    >   INIT_FCALL                                               'rand'
          5        SEND_VAL                                                 -9223372036854775808
          6        SEND_VAL                                                 9223372036854775807
          7        DO_ICALL                                         $12     
          8        ASSIGN_DIM                                               !0
          9        OP_DATA                                                  $12
    7    10        PRE_INC                                                  !1
         11    >   IS_SMALLER                                               !1, 100000
         12      > JMPNZ                                                    ~14, ->4
   11    13    >   ASSIGN                                                   !2, <array>
   12    14        ASSIGN                                                   !3, <array>
   14    15        ASSIGN                                                   !1, 0
         16      > JMP                                                      ->33
   15    17    >   INIT_FCALL                                               'microtime'
         18        SEND_VAL                                                 <true>
         19        DO_ICALL                                         $18     
         20        ASSIGN                                                   !4, $18
   16    21        INIT_FCALL                                               'array_filter'
         22        SEND_VAR                                                 !0
         23        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FlDY2B%3A16%240'
   18    24        SEND_VAL                                                 ~20
         25        DO_ICALL                                                 
   19    26        INIT_FCALL                                               'microtime'
         27        SEND_VAL                                                 <true>
         28        DO_ICALL                                         $23     
         29        SUB                                              ~24     $23, !4
         30        ASSIGN_DIM                                               !3
         31        OP_DATA                                                  ~24
   14    32        PRE_INC                                                  !1
         33    >   IS_SMALLER                                               !1, 100
         34      > JMPNZ                                                    ~26, ->17
   22    35    >   ASSIGN                                                   !1, 0
         36      > JMP                                                      ->57
   23    37    >   INIT_FCALL                                               'microtime'
         38        SEND_VAL                                                 <true>
         39        DO_ICALL                                         $28     
         40        ASSIGN                                                   !4, $28
   24    41        ASSIGN                                                   !5, <array>
   25    42      > FE_RESET_R                                       $31     !0, ->49
         43    > > FE_FETCH_R                                               $31, !6, ->49
   26    44    >   IS_SMALLER                                               0, !6
         45      > JMPZ                                                     ~32, ->48
   27    46    >   ASSIGN_DIM                                               !5
         47        OP_DATA                                                  !6
   25    48    > > JMP                                                      ->43
         49    >   FE_FREE                                                  $31
   30    50        INIT_FCALL                                               'microtime'
         51        SEND_VAL                                                 <true>
         52        DO_ICALL                                         $35     
         53        SUB                                              ~36     $35, !4
         54        ASSIGN_DIM                                               !2
         55        OP_DATA                                                  ~36
   22    56        PRE_INC                                                  !1
         57    >   IS_SMALLER                                               !1, 100
         58      > JMPNZ                                                    ~38, ->37
   33    59    >   INIT_FCALL                                               'sprintf'
         60        SEND_VAL                                                 'Avg+time%3A+%25.8f%0A'
         61        INIT_FCALL                                               'array_sum'
         62        SEND_VAR                                                 !3
         63        DO_ICALL                                         $39     
         64        COUNT                                            ~40     !3
         65        DIV                                              ~41     $39, ~40
         66        ASSIGN                                           ~42     !7, ~41
         67        SEND_VAL                                                 ~42
         68        DO_ICALL                                         $43     
         69        ECHO                                                     $43
   34    70        INIT_FCALL                                               'sprintf'
         71        SEND_VAL                                                 'Avg+time%3A+%25.8f%0A'
         72        INIT_FCALL                                               'array_sum'
         73        SEND_VAR                                                 !2
         74        DO_ICALL                                         $44     
         75        COUNT                                            ~45     !2
         76        DIV                                              ~46     $44, ~45
         77        ASSIGN                                           ~47     !8, ~46
         78        SEND_VAL                                                 ~47
         79        DO_ICALL                                         $48     
         80        ECHO                                                     $48
   35    81        INIT_FCALL                                               'sprintf'
         82        SEND_VAL                                                 'Difference%3A+%25.8f%0ARatio%3A+%25.8f%0A'
         83        SUB                                              ~49     !7, !8
         84        SEND_VAL                                                 ~49
         85        DIV                                              ~50     !7, !8
         86        SEND_VAL                                                 ~50
         87        DO_ICALL                                         $51     
         88        ECHO                                                     $51
         89      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FlDY2B%3A16%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lDY2B
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        IS_SMALLER                                       ~1      0, !0
          2      > RETURN                                                   ~1
   18     3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FlDY2B%3A16%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.96 ms | 1404 KiB | 23 Q