3v4l.org

run code in 300+ PHP versions simultaneously
<?php function benchmark($n) { $iterations = intval(1000000 / $n); print "$iterations iterations, $n range\n"; $a = range(0, $n); $start = microtime(TRUE); for ($i = 1; $i < $iterations; $i++) (array) $a !== $a; $trick = microtime(TRUE) - $start; $start = microtime(TRUE); for ($i = 1; $i < $iterations; $i++) !is_array($a); $is_array = microtime(TRUE) - $start; print '(array) !== is ' . ($trick < $is_array ? 'faster' : 'slower') ." than !is_array() for arrays and $n\n"; $a = range(0, $n); $start = microtime(TRUE); for ($i = 1; $i < $iterations; $i++) (array) $a === $a; $trick = microtime(TRUE) - $start; $start = microtime(TRUE); for ($i = 1; $i < $iterations; $i++) is_array($a); $is_array = microtime(TRUE) - $start; print '(array) === is ' . ($trick < $is_array ? 'faster' : 'slower') ." than is_array() for arrays and $n\n"; $a = (object) range(0, $n); $start = microtime(TRUE); for ($i = 1; $i < $iterations; $i++) (array) $a !== $a; $trick = microtime(TRUE) - $start; $start = microtime(TRUE); for ($i = 1; $i < $iterations; $i++) !is_array($a); $is_array = microtime(TRUE) - $start; print '(array) !== is ' . ($trick < $is_array ? 'faster' : 'slower') ." than !is_array() for object and $n\n"; $a = (object) range(0, $n); $start = microtime(TRUE); for ($i = 1; $i < $iterations; $i++) (array) $a === $a; $trick = microtime(TRUE) - $start; $start = microtime(TRUE); for ($i = 1; $i < $iterations; $i++) is_array($a); $is_array = microtime(TRUE) - $start; print '(array) === is ' . ($trick < $is_array ? 'faster' : 'slower') ." than is_array() for objects and $n\n"; } benchmark(10); print "\n"; benchmark(140); print "\n"; benchmark(150); print "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/b28M0
function name:  (null)
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   INIT_FCALL                                               'benchmark'
          1        SEND_VAL                                                 10
          2        DO_FCALL                                      0          
   45     3        ECHO                                                     '%0A'
   46     4        INIT_FCALL                                               'benchmark'
          5        SEND_VAL                                                 140
          6        DO_FCALL                                      0          
   47     7        ECHO                                                     '%0A'
   48     8        INIT_FCALL                                               'benchmark'
          9        SEND_VAL                                                 150
         10        DO_FCALL                                      0          
   49    11        ECHO                                                     '%0A'
         12      > RETURN                                                   1

Function benchmark:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 20
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 37
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 51
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
2 jumps found. (Code = 44) Position 1 = 75, Position 2 = 69
Branch analysis from position: 75
1 jumps found. (Code = 42) Position 1 = 89
Branch analysis from position: 89
2 jumps found. (Code = 44) Position 1 = 91, Position 2 = 86
Branch analysis from position: 91
2 jumps found. (Code = 43) Position 1 = 98, Position 2 = 100
Branch analysis from position: 98
1 jumps found. (Code = 42) Position 1 = 101
Branch analysis from position: 101
1 jumps found. (Code = 42) Position 1 = 123
Branch analysis from position: 123
2 jumps found. (Code = 44) Position 1 = 125, Position 2 = 119
Branch analysis from position: 125
1 jumps found. (Code = 42) Position 1 = 139
Branch analysis from position: 139
2 jumps found. (Code = 44) Position 1 = 141, Position 2 = 136
Branch analysis from position: 141
2 jumps found. (Code = 43) Position 1 = 148, Position 2 = 150
Branch analysis from position: 148
1 jumps found. (Code = 42) Position 1 = 151
Branch analysis from position: 151
1 jumps found. (Code = 42) Position 1 = 173
Branch analysis from position: 173
2 jumps found. (Code = 44) Position 1 = 175, Position 2 = 169
Branch analysis from position: 175
1 jumps found. (Code = 42) Position 1 = 189
Branch analysis from position: 189
2 jumps found. (Code = 44) Position 1 = 191, Position 2 = 186
Branch analysis from position: 191
2 jumps found. (Code = 43) Position 1 = 198, Position 2 = 200
Branch analysis from position: 198
1 jumps found. (Code = 42) Position 1 = 201
Branch analysis from position: 201
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 200
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 186
2 jumps found. (Code = 44) Position 1 = 191, Position 2 = 186
Branch analysis from position: 191
Branch analysis from position: 186
Branch analysis from position: 169
2 jumps found. (Code = 44) Position 1 = 175, Position 2 = 169
Branch analysis from position: 175
Branch analysis from position: 169
Branch analysis from position: 150
1 jumps found. (Code = 42) Position 1 = 173
Branch analysis from position: 173
Branch analysis from position: 136
2 jumps found. (Code = 44) Position 1 = 141, Position 2 = 136
Branch analysis from position: 141
Branch analysis from position: 136
Branch analysis from position: 119
2 jumps found. (Code = 44) Position 1 = 125, Position 2 = 119
Branch analysis from position: 125
Branch analysis from position: 119
Branch analysis from position: 100
1 jumps found. (Code = 42) Position 1 = 123
Branch analysis from position: 123
Branch analysis from position: 86
2 jumps found. (Code = 44) Position 1 = 91, Position 2 = 86
Branch analysis from position: 91
Branch analysis from position: 86
Branch analysis from position: 69
2 jumps found. (Code = 44) Position 1 = 75, Position 2 = 69
Branch analysis from position: 75
Branch analysis from position: 69
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 37
Branch analysis from position: 42
Branch analysis from position: 37
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 20
Branch analysis from position: 26
Branch analysis from position: 20
filename:       /in/b28M0
function name:  benchmark
number of ops:  208
compiled vars:  !0 = $n, !1 = $iterations, !2 = $a, !3 = $start, !4 = $i, !5 = $trick, !6 = $is_array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        DIV                                              ~7      1000000, !0
          2        CAST                                          4  ~8      ~7
          3        ASSIGN                                                   !1, ~8
    6     4        ROPE_INIT                                     4  ~11     !1
          5        ROPE_ADD                                      1  ~11     ~11, '+iterations%2C+'
          6        ROPE_ADD                                      2  ~11     ~11, !0
          7        ROPE_END                                      3  ~10     ~11, '+range%0A'
          8        ECHO                                                     ~10
    7     9        INIT_FCALL                                               'range'
         10        SEND_VAL                                                 0
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $13     
         13        ASSIGN                                                   !2, $13
    8    14        INIT_FCALL                                               'microtime'
         15        SEND_VAL                                                 <true>
         16        DO_ICALL                                         $15     
         17        ASSIGN                                                   !3, $15
    9    18        ASSIGN                                                   !4, 1
         19      > JMP                                                      ->24
         20    >   CAST                                          7  ~18     !2
         21        IS_NOT_IDENTICAL                                 ~19     !2, ~18
         22        FREE                                                     ~19
         23        PRE_INC                                                  !4
         24    >   IS_SMALLER                                               !4, !1
         25      > JMPNZ                                                    ~21, ->20
   10    26    >   INIT_FCALL                                               'microtime'
         27        SEND_VAL                                                 <true>
         28        DO_ICALL                                         $22     
         29        SUB                                              ~23     $22, !3
         30        ASSIGN                                                   !5, ~23
   11    31        INIT_FCALL                                               'microtime'
         32        SEND_VAL                                                 <true>
         33        DO_ICALL                                         $25     
         34        ASSIGN                                                   !3, $25
   12    35        ASSIGN                                                   !4, 1
         36      > JMP                                                      ->40
         37    >   TYPE_CHECK                                  128  ~28     !2
         38        BOOL_NOT                                         ~29     ~28
         39        PRE_INC                                                  !4
         40    >   IS_SMALLER                                               !4, !1
         41      > JMPNZ                                                    ~31, ->37
   13    42    >   INIT_FCALL                                               'microtime'
         43        SEND_VAL                                                 <true>
         44        DO_ICALL                                         $32     
         45        SUB                                              ~33     $32, !3
         46        ASSIGN                                                   !6, ~33
   14    47        IS_SMALLER                                               !5, !6
         48      > JMPZ                                                     ~35, ->51
         49    >   QM_ASSIGN                                        ~36     'faster'
         50      > JMP                                                      ->52
         51    >   QM_ASSIGN                                        ~36     'slower'
         52    >   CONCAT                                           ~37     '%28array%29+%21%3D%3D+is+', ~36
         53        ROPE_INIT                                     3  ~39     '+than+%21is_array%28%29+for+arrays+and+'
         54        ROPE_ADD                                      1  ~39     ~39, !0
         55        ROPE_END                                      2  ~38     ~39, '%0A'
         56        CONCAT                                           ~41     ~37, ~38
         57        ECHO                                                     ~41
   16    58        INIT_FCALL                                               'range'
         59        SEND_VAL                                                 0
         60        SEND_VAR                                                 !0
         61        DO_ICALL                                         $42     
         62        ASSIGN                                                   !2, $42
   17    63        INIT_FCALL                                               'microtime'
         64        SEND_VAL                                                 <true>
         65        DO_ICALL                                         $44     
         66        ASSIGN                                                   !3, $44
   18    67        ASSIGN                                                   !4, 1
         68      > JMP                                                      ->73
         69    >   CAST                                          7  ~47     !2
         70        IS_IDENTICAL                                     ~48     !2, ~47
         71        FREE                                                     ~48
         72        PRE_INC                                                  !4
         73    >   IS_SMALLER                                               !4, !1
         74      > JMPNZ                                                    ~50, ->69
   19    75    >   INIT_FCALL                                               'microtime'
         76        SEND_VAL                                                 <true>
         77        DO_ICALL                                         $51     
         78        SUB                                              ~52     $51, !3
         79        ASSIGN                                                   !5, ~52
   20    80        INIT_FCALL                                               'microtime'
         81        SEND_VAL                                                 <true>
         82        DO_ICALL                                         $54     
         83        ASSIGN                                                   !3, $54
   21    84        ASSIGN                                                   !4, 1
         85      > JMP                                                      ->89
         86    >   TYPE_CHECK                                  128  ~57     !2
         87        FREE                                                     ~57
         88        PRE_INC                                                  !4
         89    >   IS_SMALLER                                               !4, !1
         90      > JMPNZ                                                    ~59, ->86
   22    91    >   INIT_FCALL                                               'microtime'
         92        SEND_VAL                                                 <true>
         93        DO_ICALL                                         $60     
         94        SUB                                              ~61     $60, !3
         95        ASSIGN                                                   !6, ~61
   23    96        IS_SMALLER                                               !5, !6
         97      > JMPZ                                                     ~63, ->100
         98    >   QM_ASSIGN                                        ~64     'faster'
         99      > JMP                                                      ->101
        100    >   QM_ASSIGN                                        ~64     'slower'
        101    >   CONCAT                                           ~65     '%28array%29+%3D%3D%3D+is+', ~64
        102        ROPE_INIT                                     3  ~67     '+than+is_array%28%29+for+arrays+and+'
        103        ROPE_ADD                                      1  ~67     ~67, !0
        104        ROPE_END                                      2  ~66     ~67, '%0A'
        105        CONCAT                                           ~69     ~65, ~66
        106        ECHO                                                     ~69
   25   107        INIT_FCALL                                               'range'
        108        SEND_VAL                                                 0
        109        SEND_VAR                                                 !0
        110        DO_ICALL                                         $70     
        111        CAST                                          8  ~71     $70
        112        ASSIGN                                                   !2, ~71
   26   113        INIT_FCALL                                               'microtime'
        114        SEND_VAL                                                 <true>
        115        DO_ICALL                                         $73     
        116        ASSIGN                                                   !3, $73
   27   117        ASSIGN                                                   !4, 1
        118      > JMP                                                      ->123
        119    >   CAST                                          7  ~76     !2
        120        IS_NOT_IDENTICAL                                 ~77     !2, ~76
        121        FREE                                                     ~77
        122        PRE_INC                                                  !4
        123    >   IS_SMALLER                                               !4, !1
        124      > JMPNZ                                                    ~79, ->119
   28   125    >   INIT_FCALL                                               'microtime'
        126        SEND_VAL                                                 <true>
        127        DO_ICALL                                         $80     
        128        SUB                                              ~81     $80, !3
        129        ASSIGN                                                   !5, ~81
   29   130        INIT_FCALL                                               'microtime'
        131        SEND_VAL                                                 <true>
        132        DO_ICALL                                         $83     
        133        ASSIGN                                                   !3, $83
   30   134        ASSIGN                                                   !4, 1
        135      > JMP                                                      ->139
        136    >   TYPE_CHECK                                  128  ~86     !2
        137        BOOL_NOT                                         ~87     ~86
        138        PRE_INC                                                  !4
        139    >   IS_SMALLER                                               !4, !1
        140      > JMPNZ                                                    ~89, ->136
   31   141    >   INIT_FCALL                                               'microtime'
        142        SEND_VAL                                                 <true>
        143        DO_ICALL                                         $90     
        144        SUB                                              ~91     $90, !3
        145        ASSIGN                                                   !6, ~91
   32   146        IS_SMALLER                                               !5, !6
        147      > JMPZ                                                     ~93, ->150
        148    >   QM_ASSIGN                                        ~94     'faster'
        149      > JMP                                                      ->151
        150    >   QM_ASSIGN                                        ~94     'slower'
        151    >   CONCAT                                           ~95     '%28array%29+%21%3D%3D+is+', ~94
        152        ROPE_INIT                                     3  ~97     '+than+%21is_array%28%29+for+object+and+'
        153        ROPE_ADD                                      1  ~97     ~97, !0
        154        ROPE_END                                      2  ~96     ~97, '%0A'
        155        CONCAT                                           ~99     ~95, ~96
        156        ECHO                                                     ~99
   34   157        INIT_FCALL                                               'range'
        158        SEND_VAL                                                 0
        159        SEND_VAR                                                 !0
        160        DO_ICALL                                         $100    
        161        CAST                                          8  ~101    $100
        162        ASSIGN                                                   !2, ~101
   35   163        INIT_FCALL                                               'microtime'
        164        SEND_VAL                                                 <true>
        165        DO_ICALL                                         $103    
        166        ASSIGN                                                   !3, $103
   36   167        ASSIGN                                                   !4, 1
        168      > JMP                                                      ->173
        169    >   CAST                                          7  ~106    !2
        170        IS_IDENTICAL                                     ~107    !2, ~106
        171        FREE                                                     ~107
        172        PRE_INC                                                  !4
        173    >   IS_SMALLER                                               !4, !1
        174      > JMPNZ                                                    ~109, ->169
   37   175    >   INIT_FCALL                                               'microtime'
        176        SEND_VAL                                                 <true>
        177        DO_ICALL                                         $110    
        178        SUB                                              ~111    $110, !3
        179        ASSIGN                                                   !5, ~111
   38   180        INIT_FCALL                                               'microtime'
        181        SEND_VAL                                                 <true>
        182        DO_ICALL                                         $113    
        183        ASSIGN                                                   !3, $113
   39   184        ASSIGN                                                   !4, 1
        185      > JMP                                                      ->189
        186    >   TYPE_CHECK                                  128  ~116    !2
        187        FREE                                                     ~116
        188        PRE_INC                                                  !4
        189    >   IS_SMALLER                                               !4, !1
        190      > JMPNZ                                                    ~118, ->186
   40   191    >   INIT_FCALL                                               'microtime'
        192        SEND_VAL                                                 <true>
        193        DO_ICALL                                         $119    
        194        SUB                                              ~120    $119, !3
        195        ASSIGN                                                   !6, ~120
   41   196        IS_SMALLER                                               !5, !6
        197      > JMPZ                                                     ~122, ->200
        198    >   QM_ASSIGN                                        ~123    'faster'
        199      > JMP                                                      ->201
        200    >   QM_ASSIGN                                        ~123    'slower'
        201    >   CONCAT                                           ~124    '%28array%29+%3D%3D%3D+is+', ~123
        202        ROPE_INIT                                     3  ~126    '+than+is_array%28%29+for+objects+and+'
        203        ROPE_ADD                                      1  ~126    ~126, !0
        204        ROPE_END                                      2  ~125    ~126, '%0A'
        205        CONCAT                                           ~128    ~124, ~125
        206        ECHO                                                     ~128
   43   207      > RETURN                                                   null

End of function benchmark

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.07 ms | 1419 KiB | 20 Q