3v4l.org

run code in 500+ 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) { if (function_exists('mcrypt_create_iv')) { return mcrypt_create_iv(32, MCRYPT_DEV_URANDOM); } return openssl_random_pseudo_bytes(32); } function openssl_prng($bytes = 32) { return openssl_random_pseudo_bytes(32); } function mcrypt_prng($bytes = 32) { return mcrypt_create_iv(32, 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 ); $start = microtime(true); for ($i = 0; $i < 100000; ++$i) { $buf = random_bytes(32); } $tests['php7'] = ( microtime(true) - $start ); var_dump($tests);

Abusive script

This script was stopped while abusing our resources

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 = 42) Position 1 = 85
Branch analysis from position: 85
2 jumps found. (Code = 44) Position 1 = 87, Position 2 = 80
Branch analysis from position: 87
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 80
2 jumps found. (Code = 44) Position 1 = 87, Position 2 = 80
Branch analysis from position: 87
Branch analysis from position: 80
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/LYfu9
function name:  (null)
number of ops:  97
compiled vars:  !0 = $buf, !1 = $tests, !2 = $start, !3 = $i
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   28     0  E >   ASSIGN                                                       !0, ''
   29     1        ASSIGN                                                       !1, <array>
   30     2        INIT_FCALL                                                   'microtime'
          3        SEND_VAL                                                     <true>
          4        DO_ICALL                                             $6      
          5        ASSIGN                                                       !2, $6
   31     6        ASSIGN                                                       !3, 0
          7      > JMP                                                          ->12
   32     8    >   INIT_FCALL                                                   'shitty_prng'
          9        DO_FCALL                                          0  $9      
         10        ASSIGN                                                       !0, $9
   31    11        PRE_INC                                                      !3
         12    >   IS_SMALLER                                                   !3, 100000
         13      > JMPNZ                                                        ~12, ->8
   34    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
   36    20        INIT_FCALL                                                   'microtime'
         21        SEND_VAL                                                     <true>
         22        DO_ICALL                                             $16     
         23        ASSIGN                                                       !2, $16
   37    24        ASSIGN                                                       !3, 0
         25      > JMP                                                          ->30
   38    26    >   INIT_FCALL                                                   'better_prng'
         27        DO_FCALL                                          0  $19     
         28        ASSIGN                                                       !0, $19
   37    29        PRE_INC                                                      !3
         30    >   IS_SMALLER                                                   !3, 100000
         31      > JMPNZ                                                        ~22, ->26
   40    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
   42    38        INIT_FCALL                                                   'microtime'
         39        SEND_VAL                                                     <true>
         40        DO_ICALL                                             $26     
         41        ASSIGN                                                       !2, $26
   43    42        ASSIGN                                                       !3, 0
         43      > JMP                                                          ->48
   44    44    >   INIT_FCALL                                                   'openssl_prng'
         45        DO_FCALL                                          0  $29     
         46        ASSIGN                                                       !0, $29
   43    47        PRE_INC                                                      !3
         48    >   IS_SMALLER                                                   !3, 100000
         49      > JMPNZ                                                        ~32, ->44
   46    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
   48    56        INIT_FCALL                                                   'microtime'
         57        SEND_VAL                                                     <true>
         58        DO_ICALL                                             $36     
         59        ASSIGN                                                       !2, $36
   49    60        ASSIGN                                                       !3, 0
         61      > JMP                                                          ->66
   50    62    >   INIT_FCALL                                                   'mcrypt_prng'
         63        DO_FCALL                                          0  $39     
         64        ASSIGN                                                       !0, $39
   49    65        PRE_INC                                                      !3
         66    >   IS_SMALLER                                                   !3, 100000
         67      > JMPNZ                                                        ~42, ->62
   52    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
   54    74        INIT_FCALL                                                   'microtime'
         75        SEND_VAL                                                     <true>
         76        DO_ICALL                                             $46     
         77        ASSIGN                                                       !2, $46
   55    78        ASSIGN                                                       !3, 0
         79      > JMP                                                          ->85
   56    80    >   INIT_FCALL                                                   'random_bytes'
         81        SEND_VAL                                                     32
         82        DO_ICALL                                             $49     
         83        ASSIGN                                                       !0, $49
   55    84        PRE_INC                                                      !3
         85    >   IS_SMALLER                                                   !3, 100000
         86      > JMPNZ                                                        ~52, ->80
   58    87    >   INIT_FCALL                                                   'microtime'
         88        SEND_VAL                                                     <true>
         89        DO_ICALL                                             $54     
         90        SUB                                                  ~55     $54, !2
         91        ASSIGN_DIM                                                   !1, 'php7'
         92        OP_DATA                                                      ~55
   61    93        INIT_FCALL                                                   'var_dump'
         94        SEND_VAR                                                     !1
         95        DO_ICALL                                                     
         96      > 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/LYfu9
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
-----------------------------------------------------------------------------------------
    3     0  E >   RECV_INIT                                            !0      32
    5     1        ASSIGN                                                       !1, ''
    6     2        ASSIGN                                                       !2, 0
          3      > JMP                                                          ->13
    7     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
    6    12        PRE_INC                                                      !2
         13    >   IS_SMALLER                                                   !2, !0
         14      > JMPNZ                                                        ~9, ->4
    9    15    > > RETURN                                                       null

End of function shitty_prng

Function better_prng:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LYfu9
function name:  better_prng
number of ops:  16
compiled vars:  !0 = $bytes
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   11     0  E >   RECV_INIT                                            !0      32
   13     1        INIT_FCALL                                                   'function_exists'
          2        SEND_VAL                                                     'mcrypt_create_iv'
          3        DO_ICALL                                             $1      
          4      > JMPZ                                                         $1, ->11
   14     5    >   INIT_FCALL_BY_NAME                                           'mcrypt_create_iv'
          6        SEND_VAL_EX                                                  32
          7        FETCH_CONSTANT                                       ~2      'MCRYPT_DEV_URANDOM'
          8        SEND_VAL_EX                                                  ~2
          9        DO_FCALL                                          0  $3      
         10      > RETURN                                                       $3
   16    11    >   INIT_FCALL_BY_NAME                                           'openssl_random_pseudo_bytes'
         12        SEND_VAL_EX                                                  32
         13        DO_FCALL                                          0  $4      
         14      > RETURN                                                       $4
   17    15*     > 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/LYfu9
function name:  openssl_prng
number of ops:  6
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                                           'openssl_random_pseudo_bytes'
          2        SEND_VAL_EX                                                  32
          3        DO_FCALL                                          0  $1      
          4      > RETURN                                                       $1
   22     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/LYfu9
function name:  mcrypt_prng
number of ops:  8
compiled vars:  !0 = $bytes
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   23     0  E >   RECV_INIT                                            !0      32
   25     1        INIT_FCALL_BY_NAME                                           'mcrypt_create_iv'
          2        SEND_VAL_EX                                                  32
          3        FETCH_CONSTANT                                       ~1      'MCRYPT_DEV_URANDOM'
          4        SEND_VAL_EX                                                  ~1
          5        DO_FCALL                                          0  $2      
          6      > RETURN                                                       $2
   26     7*     > RETURN                                                       null

End of function mcrypt_prng

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
169.7 ms | 1112 KiB | 23 Q