3v4l.org

run code in 300+ PHP versions simultaneously
<?php function generatePrimesA($n) { $primes = [2]; for ($i = 3; $i < $n; $i += 2) { foreach ($primes as $prime) { if ($i % $prime == 0) { continue 2; } } $primes[] = $i; } return $primes; } function generatePrimesB($max) { $primes = range(2, $max); for ($i = 0; pow($primes[$i], 2) < $max; $i++) { $prime = $primes[$i]; $primes = array_filter($primes, function($p) use ($prime) { return $p % $prime == 0; }); } return $primes; } var_dump(count(generatePrimesA(1000))); var_dump(count(generatePrimesB(1000))); var_dump(array_diff(generatePrimesA(1000), generatePrimesB(1000)));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RBGZU
function name:  (null)
number of ops:  28
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'generateprimesa'
          2        SEND_VAL                                                 1000
          3        DO_FCALL                                      0  $0      
          4        COUNT                                            ~1      $0
          5        SEND_VAL                                                 ~1
          6        DO_ICALL                                                 
   31     7        INIT_FCALL                                               'var_dump'
          8        INIT_FCALL                                               'generateprimesb'
          9        SEND_VAL                                                 1000
         10        DO_FCALL                                      0  $3      
         11        COUNT                                            ~4      $3
         12        SEND_VAL                                                 ~4
         13        DO_ICALL                                                 
   33    14        INIT_FCALL                                               'var_dump'
         15        INIT_FCALL                                               'array_diff'
         16        INIT_FCALL                                               'generateprimesa'
         17        SEND_VAL                                                 1000
         18        DO_FCALL                                      0  $6      
         19        SEND_VAR                                                 $6
         20        INIT_FCALL                                               'generateprimesb'
         21        SEND_VAL                                                 1000
         22        DO_FCALL                                      0  $7      
         23        SEND_VAR                                                 $7
         24        DO_ICALL                                         $8      
         25        SEND_VAR                                                 $8
         26        DO_ICALL                                                 
         27      > RETURN                                                   1

Function generateprimesa:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 4
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 4
Branch analysis from position: 18
Branch analysis from position: 4
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 4
Branch analysis from position: 18
Branch analysis from position: 4
Branch analysis from position: 12
filename:       /in/RBGZU
function name:  generatePrimesA
number of ops:  20
compiled vars:  !0 = $n, !1 = $primes, !2 = $i, !3 = $prime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, <array>
    6     2        ASSIGN                                                   !2, 3
          3      > JMP                                                      ->16
    7     4    > > FE_RESET_R                                       $6      !1, ->12
          5    > > FE_FETCH_R                                               $6, !3, ->12
    8     6    >   MOD                                              ~7      !2, !3
          7        IS_EQUAL                                                 ~7, 0
          8      > JMPZ                                                     ~8, ->11
    9     9    >   FE_FREE                                                  $6
         10      > JMP                                                      ->15
    7    11    > > JMP                                                      ->5
         12    >   FE_FREE                                                  $6
   12    13        ASSIGN_DIM                                               !1
         14        OP_DATA                                                  !2
    6    15    >   ASSIGN_OP                                     1          !2, 2
         16    >   IS_SMALLER                                               !2, !0
         17      > JMPNZ                                                    ~11, ->4
   15    18    > > RETURN                                                   !1
   16    19*     > RETURN                                                   null

End of function generateprimesa

Function generateprimesb:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 8
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 8
Branch analysis from position: 25
Branch analysis from position: 8
filename:       /in/RBGZU
function name:  generatePrimesB
number of ops:  27
compiled vars:  !0 = $max, !1 = $primes, !2 = $i, !3 = $prime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   19     1        INIT_FCALL                                               'range'
          2        SEND_VAL                                                 2
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $4      
          5        ASSIGN                                                   !1, $4
   21     6        ASSIGN                                                   !2, 0
          7      > JMP                                                      ->18
   22     8    >   FETCH_DIM_R                                      ~7      !1, !2
          9        ASSIGN                                                   !3, ~7
   24    10        INIT_FCALL                                               'array_filter'
         11        SEND_VAR                                                 !1
         12        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FRBGZU%3A24%240'
         13        BIND_LEXICAL                                             ~9, !3
         14        SEND_VAL                                                 ~9
         15        DO_ICALL                                         $10     
         16        ASSIGN                                                   !1, $10
   21    17        PRE_INC                                                  !2
         18    >   INIT_FCALL                                               'pow'
         19        FETCH_DIM_R                                      ~13     !1, !2
         20        SEND_VAL                                                 ~13
         21        SEND_VAL                                                 2
         22        DO_ICALL                                         $14     
         23        IS_SMALLER                                               $14, !0
         24      > JMPNZ                                                    ~15, ->8
   27    25    > > RETURN                                                   !1
   28    26*     > RETURN                                                   null

End of function generateprimesb

Function %00%7Bclosure%7D%2Fin%2FRBGZU%3A24%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RBGZU
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $p, !1 = $prime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        MOD                                              ~2      !0, !1
          3        IS_EQUAL                                         ~3      ~2, 0
          4      > RETURN                                                   ~3
          5*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FRBGZU%3A24%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.96 ms | 1407 KiB | 27 Q