3v4l.org

run code in 300+ PHP versions simultaneously
<?php function test_native() { $st = hrtime(true); $h = hash_pbkdf2('sha256', 'password', 'salt', 100000); $et = hrtime(true); return [$h, $et - $st]; } function test_emulated() { $st = hrtime(true); $K = str_pad('password', 64, "\0"); $K ^= str_repeat("\x36", 64); $ictx = hash_init('sha256'); hash_update($ictx, $K); $K ^= str_repeat("\x6a", 64); $octx = hash_init('sha256'); hash_update($octx, $K); $DK = str_repeat("\0", 32); $prev = "salt\0\0\0\1"; for ($j = 0; $j < 100000; ++$j) { $ctx = hash_copy($ictx); hash_update($ctx, $prev); $temp = hash_final($ctx, true); $ctx = hash_copy($octx); hash_update($ctx, $temp); $prev = hash_final($ctx, true); $DK ^= $prev; } $h = bin2hex($DK); $et = hrtime(true); return [$h, $et - $st]; } $nr = test_native(); $er = test_emulated(); var_dump($nr[0]); var_dump($er[0]); var_dump($nr[1] <= $er[1]);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3vKTn
function name:  (null)
number of ops:  21
compiled vars:  !0 = $nr, !1 = $er
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   INIT_FCALL                                               'test_native'
          1        DO_FCALL                                      0  $2      
          2        ASSIGN                                                   !0, $2
   33     3        INIT_FCALL                                               'test_emulated'
          4        DO_FCALL                                      0  $4      
          5        ASSIGN                                                   !1, $4
   34     6        INIT_FCALL                                               'var_dump'
          7        FETCH_DIM_R                                      ~6      !0, 0
          8        SEND_VAL                                                 ~6
          9        DO_ICALL                                                 
   35    10        INIT_FCALL                                               'var_dump'
         11        FETCH_DIM_R                                      ~8      !1, 0
         12        SEND_VAL                                                 ~8
         13        DO_ICALL                                                 
   36    14        INIT_FCALL                                               'var_dump'
         15        FETCH_DIM_R                                      ~10     !0, 1
         16        FETCH_DIM_R                                      ~11     !1, 1
         17        IS_SMALLER_OR_EQUAL                              ~12     ~10, ~11
         18        SEND_VAL                                                 ~12
         19        DO_ICALL                                                 
         20      > RETURN                                                   1

Function test_native:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3vKTn
function name:  test_native
number of ops:  20
compiled vars:  !0 = $st, !1 = $h, !2 = $et
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'hrtime'
          1        SEND_VAL                                                 <true>
          2        DO_ICALL                                         $3      
          3        ASSIGN                                                   !0, $3
    4     4        INIT_FCALL                                               'hash_pbkdf2'
          5        SEND_VAL                                                 'sha256'
          6        SEND_VAL                                                 'password'
          7        SEND_VAL                                                 'salt'
          8        SEND_VAL                                                 100000
          9        DO_ICALL                                         $5      
         10        ASSIGN                                                   !1, $5
    5    11        INIT_FCALL                                               'hrtime'
         12        SEND_VAL                                                 <true>
         13        DO_ICALL                                         $7      
         14        ASSIGN                                                   !2, $7
    6    15        INIT_ARRAY                                       ~9      !1
         16        SUB                                              ~10     !2, !0
         17        ADD_ARRAY_ELEMENT                                ~9      ~10
         18      > RETURN                                                   ~9
    7    19*     > RETURN                                                   null

End of function test_native

Function test_emulated:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 72
Branch analysis from position: 72
2 jumps found. (Code = 44) Position 1 = 74, Position 2 = 44
Branch analysis from position: 74
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 74, Position 2 = 44
Branch analysis from position: 74
Branch analysis from position: 44
filename:       /in/3vKTn
function name:  test_emulated
number of ops:  87
compiled vars:  !0 = $st, !1 = $K, !2 = $ictx, !3 = $octx, !4 = $DK, !5 = $prev, !6 = $j, !7 = $ctx, !8 = $temp, !9 = $h, !10 = $et
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   INIT_FCALL                                               'hrtime'
          1        SEND_VAL                                                 <true>
          2        DO_ICALL                                         $11     
          3        ASSIGN                                                   !0, $11
   10     4        INIT_FCALL                                               'str_pad'
          5        SEND_VAL                                                 'password'
          6        SEND_VAL                                                 64
          7        SEND_VAL                                                 '%00'
          8        DO_ICALL                                         $13     
          9        ASSIGN                                                   !1, $13
   11    10        INIT_FCALL                                               'str_repeat'
         11        SEND_VAL                                                 '6'
         12        SEND_VAL                                                 64
         13        DO_ICALL                                         $15     
         14        ASSIGN_OP                                    11          !1, $15
   12    15        INIT_FCALL                                               'hash_init'
         16        SEND_VAL                                                 'sha256'
         17        DO_ICALL                                         $17     
         18        ASSIGN                                                   !2, $17
   13    19        INIT_FCALL                                               'hash_update'
         20        SEND_VAR                                                 !2
         21        SEND_VAR                                                 !1
         22        DO_ICALL                                                 
   14    23        INIT_FCALL                                               'str_repeat'
         24        SEND_VAL                                                 'j'
         25        SEND_VAL                                                 64
         26        DO_ICALL                                         $20     
         27        ASSIGN_OP                                    11          !1, $20
   15    28        INIT_FCALL                                               'hash_init'
         29        SEND_VAL                                                 'sha256'
         30        DO_ICALL                                         $22     
         31        ASSIGN                                                   !3, $22
   16    32        INIT_FCALL                                               'hash_update'
         33        SEND_VAR                                                 !3
         34        SEND_VAR                                                 !1
         35        DO_ICALL                                                 
   17    36        INIT_FCALL                                               'str_repeat'
         37        SEND_VAL                                                 '%00'
         38        SEND_VAL                                                 32
         39        DO_ICALL                                         $25     
         40        ASSIGN                                                   !4, $25
   18    41        ASSIGN                                                   !5, 'salt%00%00%00%01'
   19    42        ASSIGN                                                   !6, 0
         43      > JMP                                                      ->72
   20    44    >   INIT_FCALL                                               'hash_copy'
         45        SEND_VAR                                                 !2
         46        DO_ICALL                                         $29     
         47        ASSIGN                                                   !7, $29
   21    48        INIT_FCALL                                               'hash_update'
         49        SEND_VAR                                                 !7
         50        SEND_VAR                                                 !5
         51        DO_ICALL                                                 
   22    52        INIT_FCALL                                               'hash_final'
         53        SEND_VAR                                                 !7
         54        SEND_VAL                                                 <true>
         55        DO_ICALL                                         $32     
         56        ASSIGN                                                   !8, $32
   23    57        INIT_FCALL                                               'hash_copy'
         58        SEND_VAR                                                 !3
         59        DO_ICALL                                         $34     
         60        ASSIGN                                                   !7, $34
   24    61        INIT_FCALL                                               'hash_update'
         62        SEND_VAR                                                 !7
         63        SEND_VAR                                                 !8
         64        DO_ICALL                                                 
   25    65        INIT_FCALL                                               'hash_final'
         66        SEND_VAR                                                 !7
         67        SEND_VAL                                                 <true>
         68        DO_ICALL                                         $37     
         69        ASSIGN                                                   !5, $37
   26    70        ASSIGN_OP                                    11          !4, !5
   19    71        PRE_INC                                                  !6
         72    >   IS_SMALLER                                               !6, 100000
         73      > JMPNZ                                                    ~41, ->44
   28    74    >   INIT_FCALL                                               'bin2hex'
         75        SEND_VAR                                                 !4
         76        DO_ICALL                                         $42     
         77        ASSIGN                                                   !9, $42
   29    78        INIT_FCALL                                               'hrtime'
         79        SEND_VAL                                                 <true>
         80        DO_ICALL                                         $44     
         81        ASSIGN                                                   !10, $44
   30    82        INIT_ARRAY                                       ~46     !9
         83        SUB                                              ~47     !10, !0
         84        ADD_ARRAY_ELEMENT                                ~46     ~47
         85      > RETURN                                                   ~46
   31    86*     > RETURN                                                   null

End of function test_emulated

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.95 ms | 1407 KiB | 35 Q