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); $map = array( 'apple' => 'red', 'banana' => 'yellow', 'carrot' => 'orange', 'date' => 'brown', 'endive' => 'green' ); for ($i = 0; $i < $iterations; ++$i) { $option = $samples[$i]; $color = $map[$option]; } $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 = 72
Branch analysis from position: 72
2 jumps found. (Code = 44) Position 1 = 74, Position 2 = 67
Branch analysis from position: 74
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 67
2 jumps found. (Code = 44) Position 1 = 74, Position 2 = 67
Branch analysis from position: 74
Branch analysis from position: 67
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/ipXlT
function name:  (null)
number of ops:  86
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
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 10000
    4     1        ASSIGN                                                   !1, <array>
    5     2        ASSIGN                                                   !2, null
   11     3        ASSIGN                                                   !3, <array>
   12     4        ASSIGN                                                   !4, 0
          5      > JMP                                                      ->14
   13     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
   12    13        PRE_INC                                                  !4
         14    >   IS_SMALLER                                               !4, !0
         15      > JMPNZ                                                    ~22, ->6
   17    16    >   INIT_FCALL                                               'microtime'
         17        SEND_VAL                                                 <true>
         18        DO_ICALL                                         $23     
         19        ASSIGN                                                   !5, $23
   19    20        ASSIGN                                                   !4, 0
         21      > JMP                                                      ->47
   20    22    >   FETCH_DIM_R                                      ~26     !3, !4
         23        ASSIGN                                                   !6, ~26
   21    24      > SWITCH_STRING                                            !6, [ 'apple':->36, 'banana':->38, 'carrot':->40, 'date':->42, 'endive':->44, ], ->46
   22    25    >   IS_EQUAL                                                 !6, 'apple'
         26      > JMPNZ                                                    ~28, ->36
   25    27    >   IS_EQUAL                                                 !6, 'banana'
         28      > JMPNZ                                                    ~28, ->38
   28    29    >   IS_EQUAL                                                 !6, 'carrot'
         30      > JMPNZ                                                    ~28, ->40
   31    31    >   IS_EQUAL                                                 !6, 'date'
         32      > JMPNZ                                                    ~28, ->42
   34    33    >   IS_EQUAL                                                 !6, 'endive'
         34      > JMPNZ                                                    ~28, ->44
         35    > > JMP                                                      ->46
   23    36    >   ASSIGN                                                   !2, 'red'
   24    37      > JMP                                                      ->46
   26    38    >   ASSIGN                                                   !2, 'yellow'
   27    39      > JMP                                                      ->46
   29    40    >   ASSIGN                                                   !2, 'orange'
   30    41      > JMP                                                      ->46
   32    42    >   ASSIGN                                                   !2, 'brown'
   33    43      > JMP                                                      ->46
   35    44    >   ASSIGN                                                   !2, 'green'
   36    45      > JMP                                                      ->46
   19    46    >   PRE_INC                                                  !4
         47    >   IS_SMALLER                                               !4, !0
         48      > JMPNZ                                                    ~35, ->22
   39    49    >   INIT_FCALL                                               'microtime'
         50        SEND_VAL                                                 <true>
         51        DO_ICALL                                         $36     
         52        ASSIGN                                                   !7, $36
   41    53        SUB                                              ~38     !7, !5
         54        ASSIGN                                                   !8, ~38
   42    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                                                 
   45    60        INIT_FCALL                                               'microtime'
         61        SEND_VAL                                                 <true>
         62        DO_ICALL                                         $41     
         63        ASSIGN                                                   !9, $41
   46    64        ASSIGN                                                   !10, <array>
   53    65        ASSIGN                                                   !4, 0
         66      > JMP                                                      ->72
   54    67    >   FETCH_DIM_R                                      ~45     !3, !4
         68        ASSIGN                                                   !6, ~45
   55    69        FETCH_DIM_R                                      ~47     !10, !6
         70        ASSIGN                                                   !2, ~47
   53    71        PRE_INC                                                  !4
         72    >   IS_SMALLER                                               !4, !0
         73      > JMPNZ                                                    ~50, ->67
   57    74    >   INIT_FCALL                                               'microtime'
         75        SEND_VAL                                                 <true>
         76        DO_ICALL                                         $51     
         77        ASSIGN                                                   !11, $51
   59    78        SUB                                              ~53     !11, !9
         79        ASSIGN                                                   !12, ~53
   60    80        INIT_FCALL                                               'printf'
         81        SEND_VAL                                                 'Map%3A%09%250.6f+sec+to+process+%25d%0A'
         82        SEND_VAR                                                 !12
         83        SEND_VAR                                                 !0
         84        DO_ICALL                                                 
         85      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.29 ms | 1404 KiB | 19 Q