3v4l.org

run code in 300+ PHP versions simultaneously
<?php for($i=$x=0; $i<=500000; ++$i){ $limits_and_values[$x+=rand(1,10)]=$i; } $start = microtime(true); print "weighted sum is $x\n"; $pick=mt_rand(1,$x); // pull random integer between 1 and highest limit/key while(!isset($limits_and_values[$pick])){++$pick;} // smallest possible loop to find key $end = microtime(true); print "selected value is: $limits_and_values[$pick]\n"; print "total time is " . ($end - $start) . "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 3
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 27
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 27
Branch analysis from position: 31
Branch analysis from position: 27
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 3
Branch analysis from position: 13
Branch analysis from position: 3
filename:       /in/FnTBj
function name:  (null)
number of ops:  45
compiled vars:  !0 = $i, !1 = $x, !2 = $limits_and_values, !3 = $start, !4 = $pick, !5 = $end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                           ~6      !1, 0
          1        ASSIGN                                                   !0, ~6
          2      > JMP                                                      ->11
    3     3    >   INIT_FCALL                                               'rand'
          4        SEND_VAL                                                 1
          5        SEND_VAL                                                 10
          6        DO_ICALL                                         $8      
          7        ASSIGN_OP                                     1  ~9      !1, $8
          8        ASSIGN_DIM                                               !2, ~9
          9        OP_DATA                                                  !0
    2    10        PRE_INC                                                  !0
         11    >   IS_SMALLER_OR_EQUAL                                      !0, 500000
         12      > JMPNZ                                                    ~12, ->3
    6    13    >   INIT_FCALL                                               'microtime'
         14        SEND_VAL                                                 <true>
         15        DO_ICALL                                         $13     
         16        ASSIGN                                                   !3, $13
    7    17        ROPE_INIT                                     3  ~16     'weighted+sum+is+'
         18        ROPE_ADD                                      1  ~16     ~16, !1
         19        ROPE_END                                      2  ~15     ~16, '%0A'
         20        ECHO                                                     ~15
    9    21        INIT_FCALL                                               'mt_rand'
         22        SEND_VAL                                                 1
         23        SEND_VAR                                                 !1
         24        DO_ICALL                                         $18     
         25        ASSIGN                                                   !4, $18
   10    26      > JMP                                                      ->28
         27    >   PRE_INC                                                  !4
         28    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~21     !2, !4
         29        BOOL_NOT                                         ~22     ~21
         30      > JMPNZ                                                    ~22, ->27
   12    31    >   INIT_FCALL                                               'microtime'
         32        SEND_VAL                                                 <true>
         33        DO_ICALL                                         $23     
         34        ASSIGN                                                   !5, $23
   14    35        ROPE_INIT                                     3  ~27     'selected+value+is%3A+'
         36        FETCH_DIM_R                                      ~25     !2, !4
         37        ROPE_ADD                                      1  ~27     ~27, ~25
         38        ROPE_END                                      2  ~26     ~27, '%0A'
         39        ECHO                                                     ~26
   15    40        SUB                                              ~29     !5, !3
         41        CONCAT                                           ~30     'total+time+is+', ~29
         42        CONCAT                                           ~31     ~30, '%0A'
         43        ECHO                                                     ~31
         44      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.64 ms | 1017 KiB | 16 Q