3v4l.org

run code in 300+ PHP versions simultaneously
<?php function inverse_sqrt( $x) { return 1 / sqrt($x); } function fast_inverse_sqrt( $x) { $i = 0x5f3759df - (unpack('l', pack('f', $x))[1] >> 1); $y = unpack('f', pack('l', $i))[1]; return $y * (1.5 - 0.5 * $x * $y * $y); } $t = microtime(true); for($i = 0.1; $i <= 100; $i = $i + 0.04) { $x = inverse_sqrt($i); } $inverse_sqrt_time = microtime(true) - $t; $t = microtime(true); for($i = 0.1; $i <= 100; $i = $i + 0.04) { $x = fast_inverse_sqrt($i); } $fast_inverse_sqrt_time = microtime(true) - $t; var_dump($inverse_sqrt_time, $fast_inverse_sqrt_time); if ($inverse_sqrt_time < $fast_inverse_sqrt_time) { echo "inverse_sqrt is faster"; } else { echo "fast_inverse_sqrt is faster"; }
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 = 6
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 25
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 46
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 25
Branch analysis from position: 33
Branch analysis from position: 25
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 6
Branch analysis from position: 14
Branch analysis from position: 6
filename:       /in/b0J8V
function name:  (null)
number of ops:  48
compiled vars:  !0 = $t, !1 = $i, !2 = $x, !3 = $inverse_sqrt_time, !4 = $fast_inverse_sqrt_time
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   INIT_FCALL                                               'microtime'
          1        SEND_VAL                                                 <true>
          2        DO_ICALL                                         $5      
          3        ASSIGN                                                   !0, $5
   16     4        ASSIGN                                                   !1, 0.1
          5      > JMP                                                      ->12
   17     6    >   INIT_FCALL                                               'inverse_sqrt'
          7        SEND_VAR                                                 !1
          8        DO_FCALL                                      0  $8      
          9        ASSIGN                                                   !2, $8
   16    10        ADD                                              ~10     !1, 0.04
         11        ASSIGN                                                   !1, ~10
         12    >   IS_SMALLER_OR_EQUAL                                      !1, 100
         13      > JMPNZ                                                    ~12, ->6
   20    14    >   INIT_FCALL                                               'microtime'
         15        SEND_VAL                                                 <true>
         16        DO_ICALL                                         $13     
         17        SUB                                              ~14     $13, !0
         18        ASSIGN                                                   !3, ~14
   23    19        INIT_FCALL                                               'microtime'
         20        SEND_VAL                                                 <true>
         21        DO_ICALL                                         $16     
         22        ASSIGN                                                   !0, $16
   24    23        ASSIGN                                                   !1, 0.1
         24      > JMP                                                      ->31
   25    25    >   INIT_FCALL                                               'fast_inverse_sqrt'
         26        SEND_VAR                                                 !1
         27        DO_FCALL                                      0  $19     
         28        ASSIGN                                                   !2, $19
   24    29        ADD                                              ~21     !1, 0.04
         30        ASSIGN                                                   !1, ~21
         31    >   IS_SMALLER_OR_EQUAL                                      !1, 100
         32      > JMPNZ                                                    ~23, ->25
   28    33    >   INIT_FCALL                                               'microtime'
         34        SEND_VAL                                                 <true>
         35        DO_ICALL                                         $24     
         36        SUB                                              ~25     $24, !0
         37        ASSIGN                                                   !4, ~25
   30    38        INIT_FCALL                                               'var_dump'
         39        SEND_VAR                                                 !3
         40        SEND_VAR                                                 !4
         41        DO_ICALL                                                 
   32    42        IS_SMALLER                                               !3, !4
         43      > JMPZ                                                     ~28, ->46
   33    44    >   ECHO                                                     'inverse_sqrt+is+faster'
         45      > JMP                                                      ->47
   35    46    >   ECHO                                                     'fast_inverse_sqrt+is+faster'
   36    47    > > RETURN                                                   1

Function inverse_sqrt:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/b0J8V
function name:  inverse_sqrt
number of ops:  7
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'sqrt'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4        DIV                                              ~2      1, $1
          5      > RETURN                                                   ~2
    6     6*     > RETURN                                                   null

End of function inverse_sqrt

Function fast_inverse_sqrt:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/b0J8V
function name:  fast_inverse_sqrt
number of ops:  30
compiled vars:  !0 = $x, !1 = $i, !2 = $y
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
   10     1        INIT_FCALL                                               'unpack'
          2        SEND_VAL                                                 'l'
          3        INIT_FCALL                                               'pack'
          4        SEND_VAL                                                 'f'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $3      
          7        SEND_VAR                                                 $3
          8        DO_ICALL                                         $4      
          9        FETCH_DIM_R                                      ~5      $4, 1
         10        SR                                               ~6      ~5, 1
         11        SUB                                              ~7      1597463007, ~6
         12        ASSIGN                                                   !1, ~7
   11    13        INIT_FCALL                                               'unpack'
         14        SEND_VAL                                                 'f'
         15        INIT_FCALL                                               'pack'
         16        SEND_VAL                                                 'l'
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                         $9      
         19        SEND_VAR                                                 $9
         20        DO_ICALL                                         $10     
         21        FETCH_DIM_R                                      ~11     $10, 1
         22        ASSIGN                                                   !2, ~11
   12    23        MUL                                              ~13     !0, 0.5
         24        MUL                                              ~14     !2, ~13
         25        MUL                                              ~15     !2, ~14
         26        SUB                                              ~16     1.5, ~15
         27        MUL                                              ~17     !2, ~16
         28      > RETURN                                                   ~17
   13    29*     > RETURN                                                   null

End of function fast_inverse_sqrt

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.13 ms | 1407 KiB | 25 Q