3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a=str_split(str_repeat("a",99999)); $pre_best = PHP_INT_MAX; $post_best = PHP_INT_MAX; for($i=0;$i<99;++$i){ $t=microtime(true); array_is_list_pre($a); $t=microtime(true)-$t; if($t < $pre_best){ $pre_best = $t; } } for($i=0;$i<99;++$i){ $t=microtime(true); array_is_list_post($a); $t=microtime(true)-$t; if($t < $post_best){ $post_best = $t; } } if($pre_best===$post_best){ echo "it's a tie!"; }elseif($pre_best<$post_best){ echo "pre won!"; }else{ echo "post won!"; } var_dump($pre_best,$post_best); function array_is_list_pre(array $array): bool { $i = 0; foreach ($array as $k => $v) { if ($k !== $i) { return false; } ++$i; } return true; } function array_is_list_post(array $array): bool { $i = 0; foreach ($array as $k => $v) { if ($k !== $i++) { return false; } } return true; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 12
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 32
Branch analysis from position: 50
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 54
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 58
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 47
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 32
Branch analysis from position: 50
Branch analysis from position: 32
Branch analysis from position: 47
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 27
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 12
Branch analysis from position: 30
Branch analysis from position: 12
Branch analysis from position: 27
filename:       /in/iAekR
function name:  (null)
number of ops:  64
compiled vars:  !0 = $a, !1 = $pre_best, !2 = $post_best, !3 = $i, !4 = $t
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'str_split'
          1        INIT_FCALL                                               'str_repeat'
          2        SEND_VAL                                                 'a'
          3        SEND_VAL                                                 99999
          4        DO_ICALL                                         $5      
          5        SEND_VAR                                                 $5
          6        DO_ICALL                                         $6      
          7        ASSIGN                                                   !0, $6
    4     8        ASSIGN                                                   !1, 9223372036854775807
    5     9        ASSIGN                                                   !2, 9223372036854775807
    7    10        ASSIGN                                                   !3, 0
         11      > JMP                                                      ->28
    8    12    >   INIT_FCALL                                               'microtime'
         13        SEND_VAL                                                 <true>
         14        DO_ICALL                                         $11     
         15        ASSIGN                                                   !4, $11
    9    16        INIT_FCALL_BY_NAME                                       'array_is_list_pre'
         17        SEND_VAR_EX                                              !0
         18        DO_FCALL                                      0          
   10    19        INIT_FCALL                                               'microtime'
         20        SEND_VAL                                                 <true>
         21        DO_ICALL                                         $14     
         22        SUB                                              ~15     $14, !4
         23        ASSIGN                                                   !4, ~15
   11    24        IS_SMALLER                                               !4, !1
         25      > JMPZ                                                     ~17, ->27
   12    26    >   ASSIGN                                                   !1, !4
    7    27    >   PRE_INC                                                  !3
         28    >   IS_SMALLER                                               !3, 99
         29      > JMPNZ                                                    ~20, ->12
   15    30    >   ASSIGN                                                   !3, 0
         31      > JMP                                                      ->48
   16    32    >   INIT_FCALL                                               'microtime'
         33        SEND_VAL                                                 <true>
         34        DO_ICALL                                         $22     
         35        ASSIGN                                                   !4, $22
   17    36        INIT_FCALL_BY_NAME                                       'array_is_list_post'
         37        SEND_VAR_EX                                              !0
         38        DO_FCALL                                      0          
   18    39        INIT_FCALL                                               'microtime'
         40        SEND_VAL                                                 <true>
         41        DO_ICALL                                         $25     
         42        SUB                                              ~26     $25, !4
         43        ASSIGN                                                   !4, ~26
   19    44        IS_SMALLER                                               !4, !2
         45      > JMPZ                                                     ~28, ->47
   20    46    >   ASSIGN                                                   !2, !4
   15    47    >   PRE_INC                                                  !3
         48    >   IS_SMALLER                                               !3, 99
         49      > JMPNZ                                                    ~31, ->32
   23    50    >   IS_IDENTICAL                                             !1, !2
         51      > JMPZ                                                     ~32, ->54
   24    52    >   ECHO                                                     'it%27s+a+tie%21'
   23    53      > JMP                                                      ->59
   25    54    >   IS_SMALLER                                               !1, !2
         55      > JMPZ                                                     ~33, ->58
   26    56    >   ECHO                                                     'pre+won%21'
   25    57      > JMP                                                      ->59
   28    58    >   ECHO                                                     'post+won%21'
   30    59    >   INIT_FCALL                                               'var_dump'
         60        SEND_VAR                                                 !1
         61        SEND_VAR                                                 !2
         62        DO_ICALL                                                 
   52    63      > RETURN                                                   1

Function array_is_list_pre:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 11
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/iAekR
function name:  array_is_list_pre
number of ops:  15
compiled vars:  !0 = $array, !1 = $i, !2 = $v, !3 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
   34     1        ASSIGN                                                   !1, 0
   35     2      > FE_RESET_R                                       $5      !0, ->11
          3    > > FE_FETCH_R                                       ~6      $5, !2, ->11
          4    >   ASSIGN                                                   !3, ~6
   36     5        IS_NOT_IDENTICAL                                         !3, !1
          6      > JMPZ                                                     ~8, ->9
   37     7    >   FE_FREE                                                  $5
          8      > RETURN                                                   <false>
   39     9    >   PRE_INC                                                  !1
   35    10      > JMP                                                      ->3
         11    >   FE_FREE                                                  $5
   41    12      > RETURN                                                   <true>
   42    13*       VERIFY_RETURN_TYPE                                       
         14*     > RETURN                                                   null

End of function array_is_list_pre

Function array_is_list_post:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 11
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/iAekR
function name:  array_is_list_post
number of ops:  15
compiled vars:  !0 = $array, !1 = $i, !2 = $v, !3 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
   45     1        ASSIGN                                                   !1, 0
   46     2      > FE_RESET_R                                       $5      !0, ->11
          3    > > FE_FETCH_R                                       ~6      $5, !2, ->11
          4    >   ASSIGN                                                   !3, ~6
   47     5        POST_INC                                         ~8      !1
          6        IS_NOT_IDENTICAL                                         !3, ~8
          7      > JMPZ                                                     ~9, ->10
   48     8    >   FE_FREE                                                  $5
          9      > RETURN                                                   <false>
   46    10    > > JMP                                                      ->3
         11    >   FE_FREE                                                  $5
   51    12      > RETURN                                                   <true>
   52    13*       VERIFY_RETURN_TYPE                                       
         14*     > RETURN                                                   null

End of function array_is_list_post

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.2 ms | 1438 KiB | 17 Q