3v4l.org

run code in 300+ PHP versions simultaneously
<?php $iterations = 10000; $options = array('apple', 'banana', 'carrot' ,'date', 'endive'); $color = NULL; // Fill an array with random keys. This ensures // that (a) we use the same keys, and (b) // slowness in the randomizer doesn't impact the // loops (which can happen if entropy collection kicks in) $samples = array(); for ($i = 0; $i < $iterations; ++$i) { $samples[] = $options[rand(0, 4)]; } // Test a switch statement. $start_switch = microtime(TRUE); for ($i = 0; $i < $iterations; ++$i) { $option = $samples[$i]; switch ($option) { case 'apple': $color = 'red'; break; case 'banana': $color = 'yellow'; break; case 'carrot': $color = 'orange'; break; case 'date': $color = 'brown'; break; case 'endive': $color = 'green'; break; } } $end_switch = microtime(TRUE); $total_switch = $end_switch - $start_switch; printf("Switch:\t%0.6f sec to process %d" . PHP_EOL, $total_switch, $iterations); // Test an array lookup. $start_map = microtime(TRUE); for ($i = 0; $i < $iterations; ++$i) { $map = array( 'apple' => 'red', 'banana' => 'yellow', 'carrot' => 'orange', 'date' => 'brown', 'endive' => 'green' ); $color = $map[$samples[$i]]; } $end_map = microtime(TRUE); $total_map = $end_map - $start_map; printf("Map:\t%0.6f sec to process %d" . PHP_EOL, $total_map, $iterations);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 6
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 22
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
2 jumps found. (Code = 44) Position 1 = 73, Position 2 = 66
Branch analysis from position: 73
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 66
2 jumps found. (Code = 44) Position 1 = 73, Position 2 = 66
Branch analysis from position: 73
Branch analysis from position: 66
Branch analysis from position: 22
7 jumps found. (Code = 188) Position 1 = 36, Position 2 = 38, Position 3 = 40, Position 4 = 42, Position 5 = 44, Position 6 = 46, Position 7 = 25
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 22
Branch analysis from position: 49
Branch analysis from position: 22
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
Branch analysis from position: 46
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 36
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 38
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 40
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 42
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 44
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
Branch analysis from position: 44
Branch analysis from position: 42
Branch analysis from position: 40
Branch analysis from position: 38
Branch analysis from position: 36
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 6
Branch analysis from position: 16
Branch analysis from position: 6
filename:       /in/Ce3l0
function name:  (null)
number of ops:  85
compiled vars:  !0 = $iterations, !1 = $options, !2 = $color, !3 = $samples, !4 = $i, !5 = $start_switch, !6 = $option, !7 = $end_switch, !8 = $total_switch, !9 = $start_map, !10 = $map, !11 = $end_map, !12 = $total_map
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 10000
    3     1        ASSIGN                                                   !1, <array>
    4     2        ASSIGN                                                   !2, null
   10     3        ASSIGN                                                   !3, <array>
   11     4        ASSIGN                                                   !4, 0
          5      > JMP                                                      ->14
   12     6    >   INIT_FCALL                                               'rand'
          7        SEND_VAL                                                 0
          8        SEND_VAL                                                 4
          9        DO_ICALL                                         $19     
         10        FETCH_DIM_R                                      ~20     !1, $19
         11        ASSIGN_DIM                                               !3
         12        OP_DATA                                                  ~20
   11    13        PRE_INC                                                  !4
         14    >   IS_SMALLER                                               !4, !0
         15      > JMPNZ                                                    ~22, ->6
   16    16    >   INIT_FCALL                                               'microtime'
         17        SEND_VAL                                                 <true>
         18        DO_ICALL                                         $23     
         19        ASSIGN                                                   !5, $23
   18    20        ASSIGN                                                   !4, 0
         21      > JMP                                                      ->47
   19    22    >   FETCH_DIM_R                                      ~26     !3, !4
         23        ASSIGN                                                   !6, ~26
   20    24      > SWITCH_STRING                                            !6, [ 'apple':->36, 'banana':->38, 'carrot':->40, 'date':->42, 'endive':->44, ], ->46
   21    25    >   IS_EQUAL                                                 !6, 'apple'
         26      > JMPNZ                                                    ~28, ->36
   24    27    >   IS_EQUAL                                                 !6, 'banana'
         28      > JMPNZ                                                    ~28, ->38
   27    29    >   IS_EQUAL                                                 !6, 'carrot'
         30      > JMPNZ                                                    ~28, ->40
   30    31    >   IS_EQUAL                                                 !6, 'date'
         32      > JMPNZ                                                    ~28, ->42
   33    33    >   IS_EQUAL                                                 !6, 'endive'
         34      > JMPNZ                                                    ~28, ->44
         35    > > JMP                                                      ->46
   22    36    >   ASSIGN                                                   !2, 'red'
   23    37      > JMP                                                      ->46
   25    38    >   ASSIGN                                                   !2, 'yellow'
   26    39      > JMP                                                      ->46
   28    40    >   ASSIGN                                                   !2, 'orange'
   29    41      > JMP                                                      ->46
   31    42    >   ASSIGN                                                   !2, 'brown'
   32    43      > JMP                                                      ->46
   34    44    >   ASSIGN                                                   !2, 'green'
   35    45      > JMP                                                      ->46
   18    46    >   PRE_INC                                                  !4
         47    >   IS_SMALLER                                               !4, !0
         48      > JMPNZ                                                    ~35, ->22
   38    49    >   INIT_FCALL                                               'microtime'
         50        SEND_VAL                                                 <true>
         51        DO_ICALL                                         $36     
         52        ASSIGN                                                   !7, $36
   40    53        SUB                                              ~38     !7, !5
         54        ASSIGN                                                   !8, ~38
   41    55        INIT_FCALL                                               'printf'
         56        SEND_VAL                                                 'Switch%3A%09%250.6f+sec+to+process+%25d%0A'
         57        SEND_VAR                                                 !8
         58        SEND_VAR                                                 !0
         59        DO_ICALL                                                 
   44    60        INIT_FCALL                                               'microtime'
         61        SEND_VAL                                                 <true>
         62        DO_ICALL                                         $41     
         63        ASSIGN                                                   !9, $41
   46    64        ASSIGN                                                   !4, 0
         65      > JMP                                                      ->71
   47    66    >   ASSIGN                                                   !10, <array>
   54    67        FETCH_DIM_R                                      ~45     !3, !4
         68        FETCH_DIM_R                                      ~46     !10, ~45
         69        ASSIGN                                                   !2, ~46
   46    70        PRE_INC                                                  !4
         71    >   IS_SMALLER                                               !4, !0
         72      > JMPNZ                                                    ~49, ->66
   56    73    >   INIT_FCALL                                               'microtime'
         74        SEND_VAL                                                 <true>
         75        DO_ICALL                                         $50     
         76        ASSIGN                                                   !11, $50
   58    77        SUB                                              ~52     !11, !9
         78        ASSIGN                                                   !12, ~52
   59    79        INIT_FCALL                                               'printf'
         80        SEND_VAL                                                 'Map%3A%09%250.6f+sec+to+process+%25d%0A'
         81        SEND_VAR                                                 !12
         82        SEND_VAR                                                 !0
         83        DO_ICALL                                                 
         84      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.89 ms | 1404 KiB | 19 Q