3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Trial division 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; } // Sieve of Eratosthenes function generatePrimesB($max) { $primes = array_fill(2, $max - 1, true); for ($i = 2; pow($i, 2) < $max; $i++) { if ($primes[$i]) { for ($j = $i * $i; $j <= $max; $j += $i) { $primes[$j] = false; } } } return array_keys(array_filter($primes)); } // $a = microtime(1); // var_dump(count(generatePrimesA(100000))); // $a = microtime(1) - $a; $b = microtime(1); var_export(count(generatePrimesB(100000))); $b = microtime(1) - $b; // var_dump($a); var_dump($b);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FApHl
function name:  (null)
number of ops:  20
compiled vars:  !0 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   INIT_FCALL                                               'microtime'
          1        SEND_VAL                                                 1
          2        DO_ICALL                                         $1      
          3        ASSIGN                                                   !0, $1
   39     4        INIT_FCALL                                               'var_export'
          5        INIT_FCALL                                               'generateprimesb'
          6        SEND_VAL                                                 100000
          7        DO_FCALL                                      0  $3      
          8        COUNT                                            ~4      $3
          9        SEND_VAL                                                 ~4
         10        DO_ICALL                                                 
   40    11        INIT_FCALL                                               'microtime'
         12        SEND_VAL                                                 1
         13        DO_ICALL                                         $6      
         14        SUB                                              ~7      $6, !0
         15        ASSIGN                                                   !0, ~7
   44    16        INIT_FCALL                                               'var_dump'
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                                 
         19      > 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/FApHl
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
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, <array>
    7     2        ASSIGN                                                   !2, 3
          3      > JMP                                                      ->16
    8     4    > > FE_RESET_R                                       $6      !1, ->12
          5    > > FE_FETCH_R                                               $6, !3, ->12
    9     6    >   MOD                                              ~7      !2, !3
          7        IS_EQUAL                                                 ~7, 0
          8      > JMPZ                                                     ~8, ->11
   10     9    >   FE_FREE                                                  $6
         10      > JMP                                                      ->15
    8    11    > > JMP                                                      ->5
         12    >   FE_FREE                                                  $6
   13    13        ASSIGN_DIM                                               !1
         14        OP_DATA                                                  !2
    7    15    >   ASSIGN_OP                                     1          !2, 2
         16    >   IS_SMALLER                                               !2, !0
         17      > JMPNZ                                                    ~11, ->4
   16    18    > > RETURN                                                   !1
   17    19*     > RETURN                                                   null

End of function generateprimesa

Function generateprimesb:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 10
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 20
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 15
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 10
Branch analysis from position: 27
Branch analysis from position: 10
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 15
Branch analysis from position: 20
Branch analysis from position: 15
Branch analysis from position: 20
filename:       /in/FApHl
function name:  generatePrimesB
number of ops:  35
compiled vars:  !0 = $max, !1 = $primes, !2 = $i, !3 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   21     1        INIT_FCALL                                               'array_fill'
          2        SEND_VAL                                                 2
          3        SUB                                              ~4      !0, 1
          4        SEND_VAL                                                 ~4
          5        SEND_VAL                                                 <true>
          6        DO_ICALL                                         $5      
          7        ASSIGN                                                   !1, $5
   23     8        ASSIGN                                                   !2, 2
          9      > JMP                                                      ->21
   24    10    >   FETCH_DIM_R                                      ~8      !1, !2
         11      > JMPZ                                                     ~8, ->20
   25    12    >   MUL                                              ~9      !2, !2
         13        ASSIGN                                                   !3, ~9
         14      > JMP                                                      ->18
   26    15    >   ASSIGN_DIM                                               !1, !3
         16        OP_DATA                                                  <false>
   25    17        ASSIGN_OP                                     1          !3, !2
         18    >   IS_SMALLER_OR_EQUAL                                      !3, !0
         19      > JMPNZ                                                    ~13, ->15
   23    20    >   PRE_INC                                                  !2
         21    >   INIT_FCALL                                               'pow'
         22        SEND_VAR                                                 !2
         23        SEND_VAL                                                 2
         24        DO_ICALL                                         $15     
         25        IS_SMALLER                                               $15, !0
         26      > JMPNZ                                                    ~16, ->10
   31    27    >   INIT_FCALL                                               'array_keys'
         28        INIT_FCALL                                               'array_filter'
         29        SEND_VAR                                                 !1
         30        DO_ICALL                                         $17     
         31        SEND_VAR                                                 $17
         32        DO_ICALL                                         $18     
         33      > RETURN                                                   $18
   32    34*     > RETURN                                                   null

End of function generateprimesb

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.88 ms | 1407 KiB | 28 Q