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($n) { $primes = [2]; $lastPrime = 2; for ($i = 3; $i < $n; $i += $lastPrime) { foreach ($primes as $prime) { if ($i % $prime == 0) { continue 2; } } $primes[] = $i; $lastPrime = $i; } return $primes; } var_dump(count(generatePrimesA(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/UQW2e
function name:  (null)
number of ops:  21
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     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                                                 
   38     7        INIT_FCALL                                               'var_dump'
          8        INIT_FCALL                                               'array_diff'
          9        INIT_FCALL                                               'generateprimesa'
         10        SEND_VAL                                                 1000
         11        DO_FCALL                                      0  $3      
         12        SEND_VAR                                                 $3
         13        INIT_FCALL                                               'generateprimesb'
         14        SEND_VAL                                                 1000
         15        DO_FCALL                                      0  $4      
         16        SEND_VAR                                                 $4
         17        DO_ICALL                                         $5      
         18        SEND_VAR                                                 $5
         19        DO_ICALL                                                 
         20      > 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/UQW2e
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 = 20, Position 2 = 5
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 13
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 13
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 5
Branch analysis from position: 20
Branch analysis from position: 5
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 5
Branch analysis from position: 20
Branch analysis from position: 5
Branch analysis from position: 13
filename:       /in/UQW2e
function name:  generatePrimesB
number of ops:  22
compiled vars:  !0 = $n, !1 = $primes, !2 = $lastPrime, !3 = $i, !4 = $prime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   19     1        ASSIGN                                                   !1, <array>
   21     2        ASSIGN                                                   !2, 2
   23     3        ASSIGN                                                   !3, 3
          4      > JMP                                                      ->18
   24     5    > > FE_RESET_R                                       $8      !1, ->13
          6    > > FE_FETCH_R                                               $8, !4, ->13
   25     7    >   MOD                                              ~9      !3, !4
          8        IS_EQUAL                                                 ~9, 0
          9      > JMPZ                                                     ~10, ->12
   26    10    >   FE_FREE                                                  $8
         11      > JMP                                                      ->17
   24    12    > > JMP                                                      ->6
         13    >   FE_FREE                                                  $8
   29    14        ASSIGN_DIM                                               !1
         15        OP_DATA                                                  !3
   30    16        ASSIGN                                                   !2, !3
   23    17    >   ASSIGN_OP                                     1          !3, !2
         18    >   IS_SMALLER                                               !3, !0
         19      > JMPNZ                                                    ~14, ->5
   33    20    > > RETURN                                                   !1
   34    21*     > RETURN                                                   null

End of function generateprimesb

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.41 ms | 1407 KiB | 20 Q