3v4l.org

run code in 300+ PHP versions simultaneously
<?php function get_primes7($n) { if ($n < 2) return array(); if ($n == 2) return array(2); $s = range(3, $n, 2); $mroot = sqrt($n); $half = count($s); $i = 0; $m = 3; while ($m <= $mroot) { if ($s[$i]) { $j = (int)(($m*$m - 3) / 2); $s[$j] = 0; while ($j < $half) { $s[$j] = 0; $j += $m; } } $i = $i + 1; $m = 2*$i + 3; } $res = array(2); foreach ($s as $v) { if ($v) { $res[] = $v; } } return $res; } $res = array(); for ($i = 1; $i <= 10; ++$i) { $res = get_primes7(10000); print "Found ".count($res)." prime numbers.\n"; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 3
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 3
Branch analysis from position: 14
Branch analysis from position: 3
filename:       /in/me1Dr
function name:  (null)
number of ops:  15
compiled vars:  !0 = $res, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   ASSIGN                                                   !0, <array>
   33     1        ASSIGN                                                   !1, 1
          2      > JMP                                                      ->12
   34     3    >   INIT_FCALL                                               'get_primes7'
          4        SEND_VAL                                                 10000
          5        DO_FCALL                                      0  $4      
          6        ASSIGN                                                   !0, $4
   35     7        COUNT                                            ~6      !0
          8        CONCAT                                           ~7      'Found+', ~6
          9        CONCAT                                           ~8      ~7, '+prime+numbers.%0A'
         10        ECHO                                                     ~8
   33    11        PRE_INC                                                  !1
         12    >   IS_SMALLER_OR_EQUAL                                      !1, 10
         13      > JMPNZ                                                    ~10, ->3
   36    14    > > RETURN                                                   1

Function get_primes7:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 4
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 22
Branch analysis from position: 44
2 jumps found. (Code = 77) Position 1 = 46, Position 2 = 51
Branch analysis from position: 46
2 jumps found. (Code = 78) Position 1 = 47, Position 2 = 51
Branch analysis from position: 47
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 50
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
Branch analysis from position: 50
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 37
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 32
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 22
Branch analysis from position: 44
Branch analysis from position: 22
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 32
Branch analysis from position: 37
Branch analysis from position: 32
Branch analysis from position: 37
filename:       /in/me1Dr
function name:  get_primes7
number of ops:  54
compiled vars:  !0 = $n, !1 = $s, !2 = $mroot, !3 = $half, !4 = $i, !5 = $m, !6 = $j, !7 = $res, !8 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        IS_SMALLER                                               !0, 2
          2      > JMPZ                                                     ~9, ->4
          3    > > RETURN                                                   <array>
    5     4    >   IS_EQUAL                                                 !0, 2
          5      > JMPZ                                                     ~10, ->7
          6    > > RETURN                                                   <array>
    6     7    >   INIT_FCALL                                               'range'
          8        SEND_VAL                                                 3
          9        SEND_VAR                                                 !0
         10        SEND_VAL                                                 2
         11        DO_ICALL                                         $11     
         12        ASSIGN                                                   !1, $11
    7    13        INIT_FCALL                                               'sqrt'
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                         $13     
         16        ASSIGN                                                   !2, $13
    8    17        COUNT                                            ~15     !1
         18        ASSIGN                                                   !3, ~15
    9    19        ASSIGN                                                   !4, 0
   10    20        ASSIGN                                                   !5, 3
   11    21      > JMP                                                      ->42
   12    22    >   FETCH_DIM_R                                      ~19     !1, !4
         23      > JMPZ                                                     ~19, ->37
   13    24    >   MUL                                              ~20     !5, !5
         25        SUB                                              ~21     ~20, 3
         26        DIV                                              ~22     ~21, 2
         27        CAST                                          4  ~23     ~22
         28        ASSIGN                                                   !6, ~23
   14    29        ASSIGN_DIM                                               !1, !6
         30        OP_DATA                                                  0
   15    31      > JMP                                                      ->35
   16    32    >   ASSIGN_DIM                                               !1, !6
         33        OP_DATA                                                  0
   17    34        ASSIGN_OP                                     1          !6, !5
   15    35    >   IS_SMALLER                                               !6, !3
         36      > JMPNZ                                                    ~28, ->32
   20    37    >   ADD                                              ~29     !4, 1
         38        ASSIGN                                                   !4, ~29
   21    39        MUL                                              ~31     !4, 2
         40        ADD                                              ~32     ~31, 3
         41        ASSIGN                                                   !5, ~32
   11    42    >   IS_SMALLER_OR_EQUAL                                      !5, !2
         43      > JMPNZ                                                    ~34, ->22
   23    44    >   ASSIGN                                                   !7, <array>
   24    45      > FE_RESET_R                                       $36     !1, ->51
         46    > > FE_FETCH_R                                               $36, !8, ->51
   25    47    > > JMPZ                                                     !8, ->50
   26    48    >   ASSIGN_DIM                                               !7
         49        OP_DATA                                                  !8
   24    50    > > JMP                                                      ->46
         51    >   FE_FREE                                                  $36
   29    52      > RETURN                                                   !7
   30    53*     > RETURN                                                   null

End of function get_primes7

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.86 ms | 1407 KiB | 18 Q