3v4l.org

run code in 300+ PHP versions simultaneously
<?php function shitty_prng($bytes = 32) { $buf = ''; for ($i = 0; $i < $bytes; ++$i) { $buf .= chr(mt_rand(0, 255)); } } function better_prng($bytes = 32) { return random_bytes($bytes); } function openssl_prng($bytes = 32) { return openssl_random_pseudo_bytes($bytes); } function mcrypt_prng($bytes = 32) { return mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM); } $buf = ''; $tests = []; $start = microtime(true); for ($i = 0; $i < 100000; ++$i) { $buf = shitty_prng(); } $tests['mtrand'] = ( microtime(true) - $start ); $start = microtime(true); for ($i = 0; $i < 100000; ++$i) { $buf = better_prng(); } $tests['csprng'] = ( microtime(true) - $start ); $start = microtime(true); for ($i = 0; $i < 100000; ++$i) { $buf = openssl_prng(); } $tests['openssl'] = ( microtime(true) - $start ); $start = microtime(true); for ($i = 0; $i < 100000; ++$i) { $buf = mcrypt_prng(); } $tests['mcrypt'] = ( microtime(true) - $start ); var_dump($tests);
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 = 8
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 26
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 44
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 66
Branch analysis from position: 66
2 jumps found. (Code = 44) Position 1 = 68, Position 2 = 62
Branch analysis from position: 68
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
2 jumps found. (Code = 44) Position 1 = 68, Position 2 = 62
Branch analysis from position: 68
Branch analysis from position: 62
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 44
Branch analysis from position: 50
Branch analysis from position: 44
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 26
Branch analysis from position: 32
Branch analysis from position: 26
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 8
Branch analysis from position: 14
Branch analysis from position: 8
filename:       /in/j330O
function name:  (null)
number of ops:  78
compiled vars:  !0 = $buf, !1 = $tests, !2 = $start, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   ASSIGN                                                   !0, ''
   26     1        ASSIGN                                                   !1, <array>
   27     2        INIT_FCALL                                               'microtime'
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $6      
          5        ASSIGN                                                   !2, $6
   28     6        ASSIGN                                                   !3, 0
          7      > JMP                                                      ->12
   29     8    >   INIT_FCALL                                               'shitty_prng'
          9        DO_FCALL                                      0  $9      
         10        ASSIGN                                                   !0, $9
   28    11        PRE_INC                                                  !3
         12    >   IS_SMALLER                                               !3, 100000
         13      > JMPNZ                                                    ~12, ->8
   31    14    >   INIT_FCALL                                               'microtime'
         15        SEND_VAL                                                 <true>
         16        DO_ICALL                                         $14     
         17        SUB                                              ~15     $14, !2
         18        ASSIGN_DIM                                               !1, 'mtrand'
         19        OP_DATA                                                  ~15
   32    20        INIT_FCALL                                               'microtime'
         21        SEND_VAL                                                 <true>
         22        DO_ICALL                                         $16     
         23        ASSIGN                                                   !2, $16
   33    24        ASSIGN                                                   !3, 0
         25      > JMP                                                      ->30
   34    26    >   INIT_FCALL                                               'better_prng'
         27        DO_FCALL                                      0  $19     
         28        ASSIGN                                                   !0, $19
   33    29        PRE_INC                                                  !3
         30    >   IS_SMALLER                                               !3, 100000
         31      > JMPNZ                                                    ~22, ->26
   36    32    >   INIT_FCALL                                               'microtime'
         33        SEND_VAL                                                 <true>
         34        DO_ICALL                                         $24     
         35        SUB                                              ~25     $24, !2
         36        ASSIGN_DIM                                               !1, 'csprng'
         37        OP_DATA                                                  ~25
   37    38        INIT_FCALL                                               'microtime'
         39        SEND_VAL                                                 <true>
         40        DO_ICALL                                         $26     
         41        ASSIGN                                                   !2, $26
   38    42        ASSIGN                                                   !3, 0
         43      > JMP                                                      ->48
   39    44    >   INIT_FCALL                                               'openssl_prng'
         45        DO_FCALL                                      0  $29     
         46        ASSIGN                                                   !0, $29
   38    47        PRE_INC                                                  !3
         48    >   IS_SMALLER                                               !3, 100000
         49      > JMPNZ                                                    ~32, ->44
   41    50    >   INIT_FCALL                                               'microtime'
         51        SEND_VAL                                                 <true>
         52        DO_ICALL                                         $34     
         53        SUB                                              ~35     $34, !2
         54        ASSIGN_DIM                                               !1, 'openssl'
         55        OP_DATA                                                  ~35
   42    56        INIT_FCALL                                               'microtime'
         57        SEND_VAL                                                 <true>
         58        DO_ICALL                                         $36     
         59        ASSIGN                                                   !2, $36
   43    60        ASSIGN                                                   !3, 0
         61      > JMP                                                      ->66
   44    62    >   INIT_FCALL                                               'mcrypt_prng'
         63        DO_FCALL                                      0  $39     
         64        ASSIGN                                                   !0, $39
   43    65        PRE_INC                                                  !3
         66    >   IS_SMALLER                                               !3, 100000
         67      > JMPNZ                                                    ~42, ->62
   46    68    >   INIT_FCALL                                               'microtime'
         69        SEND_VAL                                                 <true>
         70        DO_ICALL                                         $44     
         71        SUB                                              ~45     $44, !2
         72        ASSIGN_DIM                                               !1, 'mcrypt'
         73        OP_DATA                                                  ~45
   47    74        INIT_FCALL                                               'var_dump'
         75        SEND_VAR                                                 !1
         76        DO_ICALL                                                 
         77      > RETURN                                                   1

Function shitty_prng:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 4
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 4
Branch analysis from position: 15
Branch analysis from position: 4
filename:       /in/j330O
function name:  shitty_prng
number of ops:  16
compiled vars:  !0 = $bytes, !1 = $buf, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV_INIT                                        !0      32
    4     1        ASSIGN                                                   !1, ''
    5     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->13
    6     4    >   INIT_FCALL                                               'chr'
          5        INIT_FCALL                                               'mt_rand'
          6        SEND_VAL                                                 0
          7        SEND_VAL                                                 255
          8        DO_ICALL                                         $5      
          9        SEND_VAR                                                 $5
         10        DO_ICALL                                         $6      
         11        ASSIGN_OP                                     8          !1, $6
    5    12        PRE_INC                                                  !2
         13    >   IS_SMALLER                                               !2, !0
         14      > JMPNZ                                                    ~9, ->4
    8    15    > > RETURN                                                   null

End of function shitty_prng

Function better_prng:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/j330O
function name:  better_prng
number of ops:  6
compiled vars:  !0 = $bytes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV_INIT                                        !0      32
   11     1        INIT_FCALL                                               'random_bytes'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
   12     5*     > RETURN                                                   null

End of function better_prng

Function openssl_prng:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/j330O
function name:  openssl_prng
number of ops:  6
compiled vars:  !0 = $bytes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV_INIT                                        !0      32
   16     1        INIT_FCALL_BY_NAME                                       'openssl_random_pseudo_bytes'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4      > RETURN                                                   $1
   17     5*     > RETURN                                                   null

End of function openssl_prng

Function mcrypt_prng:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/j330O
function name:  mcrypt_prng
number of ops:  8
compiled vars:  !0 = $bytes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV_INIT                                        !0      32
   21     1        INIT_FCALL_BY_NAME                                       'mcrypt_create_iv'
          2        SEND_VAR_EX                                              !0
          3        FETCH_CONSTANT                                   ~1      'MCRYPT_DEV_URANDOM'
          4        SEND_VAL_EX                                              ~1
          5        DO_FCALL                                      0  $2      
          6      > RETURN                                                   $2
   22     7*     > RETURN                                                   null

End of function mcrypt_prng

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.39 ms | 1025 KiB | 22 Q