3v4l.org

run code in 300+ PHP versions simultaneously
<?php $elements = array(); //// // An array of 10,000 elements with random string values //// for($i = 0; $i < 10000; $i++) { $elements[] = [(string)rand(10000000, 99999999)]; } $time_start = microtime(true); //// // for test //// $numb = count($elements); for($i = 0; $i < $numb; $i++) { $elements[$i][0] = 1; } $time_end = microtime(true); $for_time = $time_end - $time_start; $time_start = microtime(true); //// // for with count() inside loop test //// for($i = 0; $i < count($elements); $i++) { $elements[$i][0] = 1; } $time_end = microtime(true); $for_count_time = $time_end - $time_start; $time_start = microtime(true); //// // foreach test //// foreach($elements as &$element) { $element[0]= 1; } $time_end = microtime(true); $foreach_time = $time_end - $time_start; echo "For took: " . number_format($for_time * 1000, 3) . "ms\n"; echo "For with count() took: " . number_format($for_count_time * 1000, 3) . "ms\n"; echo "Foreach took: " . number_format($foreach_time * 1000, 3) . "ms\n";
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 = 3
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 22
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 40
Branch analysis from position: 47
2 jumps found. (Code = 125) Position 1 = 58, Position 2 = 62
Branch analysis from position: 58
2 jumps found. (Code = 126) Position 1 = 59, Position 2 = 62
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 40
Branch analysis from position: 47
Branch analysis from position: 40
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 22
Branch analysis from position: 28
Branch analysis from position: 22
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 3
Branch analysis from position: 14
Branch analysis from position: 3
filename:       /in/JKBoQ
function name:  (null)
number of ops:  94
compiled vars:  !0 = $elements, !1 = $i, !2 = $time_start, !3 = $numb, !4 = $time_end, !5 = $for_time, !6 = $for_count_time, !7 = $element, !8 = $foreach_time
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    6     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->12
    7     3    >   INIT_FCALL                                               'rand'
          4        SEND_VAL                                                 10000000
          5        SEND_VAL                                                 99999999
          6        DO_ICALL                                         $12     
          7        CAST                                          6  ~13     $12
          8        INIT_ARRAY                                       ~14     ~13
          9        ASSIGN_DIM                                               !0
         10        OP_DATA                                                  ~14
    6    11        PRE_INC                                                  !1
         12    >   IS_SMALLER                                               !1, 10000
         13      > JMPNZ                                                    ~16, ->3
    9    14    >   INIT_FCALL                                               'microtime'
         15        SEND_VAL                                                 <true>
         16        DO_ICALL                                         $17     
         17        ASSIGN                                                   !2, $17
   13    18        COUNT                                            ~19     !0
         19        ASSIGN                                                   !3, ~19
   14    20        ASSIGN                                                   !1, 0
         21      > JMP                                                      ->26
   15    22    >   FETCH_DIM_W                                      $22     !0, !1
         23        ASSIGN_DIM                                               $22, 0
         24        OP_DATA                                                  1
   14    25        PRE_INC                                                  !1
         26    >   IS_SMALLER                                               !1, !3
         27      > JMPNZ                                                    ~25, ->22
   17    28    >   INIT_FCALL                                               'microtime'
         29        SEND_VAL                                                 <true>
         30        DO_ICALL                                         $26     
         31        ASSIGN                                                   !4, $26
   18    32        SUB                                              ~28     !4, !2
         33        ASSIGN                                                   !5, ~28
   19    34        INIT_FCALL                                               'microtime'
         35        SEND_VAL                                                 <true>
         36        DO_ICALL                                         $30     
         37        ASSIGN                                                   !2, $30
   23    38        ASSIGN                                                   !1, 0
         39      > JMP                                                      ->44
   24    40    >   FETCH_DIM_W                                      $33     !0, !1
         41        ASSIGN_DIM                                               $33, 0
         42        OP_DATA                                                  1
   23    43        PRE_INC                                                  !1
         44    >   COUNT                                            ~36     !0
         45        IS_SMALLER                                               !1, ~36
         46      > JMPNZ                                                    ~37, ->40
   26    47    >   INIT_FCALL                                               'microtime'
         48        SEND_VAL                                                 <true>
         49        DO_ICALL                                         $38     
         50        ASSIGN                                                   !4, $38
   27    51        SUB                                              ~40     !4, !2
         52        ASSIGN                                                   !6, ~40
   28    53        INIT_FCALL                                               'microtime'
         54        SEND_VAL                                                 <true>
         55        DO_ICALL                                         $42     
         56        ASSIGN                                                   !2, $42
   32    57      > FE_RESET_RW                                      $44     !0, ->62
         58    > > FE_FETCH_RW                                              $44, !7, ->62
   33    59    >   ASSIGN_DIM                                               !7, 0
         60        OP_DATA                                                  1
   32    61      > JMP                                                      ->58
         62    >   FE_FREE                                                  $44
   35    63        INIT_FCALL                                               'microtime'
         64        SEND_VAL                                                 <true>
         65        DO_ICALL                                         $46     
         66        ASSIGN                                                   !4, $46
   36    67        SUB                                              ~48     !4, !2
         68        ASSIGN                                                   !8, ~48
   37    69        INIT_FCALL                                               'number_format'
         70        MUL                                              ~50     !5, 1000
         71        SEND_VAL                                                 ~50
         72        SEND_VAL                                                 3
         73        DO_ICALL                                         $51     
         74        CONCAT                                           ~52     'For+took%3A+', $51
         75        CONCAT                                           ~53     ~52, 'ms%0A'
         76        ECHO                                                     ~53
   38    77        INIT_FCALL                                               'number_format'
         78        MUL                                              ~54     !6, 1000
         79        SEND_VAL                                                 ~54
         80        SEND_VAL                                                 3
         81        DO_ICALL                                         $55     
         82        CONCAT                                           ~56     'For+with+count%28%29+took%3A+', $55
         83        CONCAT                                           ~57     ~56, 'ms%0A'
         84        ECHO                                                     ~57
   39    85        INIT_FCALL                                               'number_format'
         86        MUL                                              ~58     !8, 1000
         87        SEND_VAL                                                 ~58
         88        SEND_VAL                                                 3
         89        DO_ICALL                                         $59     
         90        CONCAT                                           ~60     'Foreach+took%3A+', $59
         91        CONCAT                                           ~61     ~60, 'ms%0A'
         92        ECHO                                                     ~61
         93      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.53 ms | 1404 KiB | 19 Q