3v4l.org

run code in 300+ PHP versions simultaneously
<?php function partition(&$arr, $left, $right) { $pivot = $arr[($left + $right)/2]; while ($left <= $right) { while ($arr[$left] < $pivot) $left++; while ($arr[$right] > $pivot) $right--; if ($left <= $right) { $tmp = $arr[$left]; $arr[$left] = $arr[$right]; $arr[$right] = $tmp; $left++; $right--; } } return $left; } function quickSort($arr, $left = 0, $right = null) { if(!$right) $right = (count($arr)-1); $index = partition($arr, $left, $right); if ($left < $index - 1) { $arr = quickSort($arr, $left, $index - 1); } if ($index < $right) { $arr = quickSort($arr, $index, $right); } return $arr; } $sortMe = [8,11,10,13,4,12,56,9]; print_r(quickSort($sortMe));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Vm4rd
function name:  (null)
number of ops:  8
compiled vars:  !0 = $sortMe
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   ASSIGN                                                   !0, <array>
   41     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'quicksort'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function partition:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 8
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 9
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 14
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 29
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 8
Branch analysis from position: 31
Branch analysis from position: 8
Branch analysis from position: 29
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 14
Branch analysis from position: 18
Branch analysis from position: 14
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 9
Branch analysis from position: 13
Branch analysis from position: 9
filename:       /in/Vm4rd
function name:  partition
number of ops:  33
compiled vars:  !0 = $arr, !1 = $left, !2 = $right, !3 = $pivot, !4 = $tmp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    5     3        ADD                                              ~5      !1, !2
          4        DIV                                              ~6      ~5, 2
          5        FETCH_DIM_R                                      ~7      !0, ~6
          6        ASSIGN                                                   !3, ~7
    7     7      > JMP                                                      ->29
    9     8    > > JMP                                                      ->10
   10     9    >   PRE_INC                                                  !1
    9    10    >   FETCH_DIM_R                                      ~10     !0, !1
         11        IS_SMALLER                                               ~10, !3
         12      > JMPNZ                                                    ~11, ->9
   11    13    > > JMP                                                      ->15
   12    14    >   PRE_DEC                                                  !2
   11    15    >   FETCH_DIM_R                                      ~13     !0, !2
         16        IS_SMALLER                                               !3, ~13
         17      > JMPNZ                                                    ~14, ->14
   13    18    >   IS_SMALLER_OR_EQUAL                                      !1, !2
         19      > JMPZ                                                     ~15, ->29
   14    20    >   FETCH_DIM_R                                      ~16     !0, !1
         21        ASSIGN                                                   !4, ~16
   15    22        FETCH_DIM_R                                      ~19     !0, !2
         23        ASSIGN_DIM                                               !0, !1
         24        OP_DATA                                                  ~19
   16    25        ASSIGN_DIM                                               !0, !2
         26        OP_DATA                                                  !4
   17    27        PRE_INC                                                  !1
   18    28        PRE_DEC                                                  !2
    7    29    >   IS_SMALLER_OR_EQUAL                                      !1, !2
         30      > JMPNZ                                                    ~23, ->8
   22    31    > > RETURN                                                   !1
   23    32*     > RETURN                                                   null

End of function partition

Function quicksort:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 24
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 32
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
Branch analysis from position: 24
Branch analysis from position: 8
filename:       /in/Vm4rd
function name:  quickSort
number of ops:  34
compiled vars:  !0 = $arr, !1 = $left, !2 = $right, !3 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
          2        RECV_INIT                                        !2      null
   27     3        BOOL_NOT                                         ~4      !2
          4      > JMPZ                                                     ~4, ->8
          5    >   COUNT                                            ~5      !0
          6        SUB                                              ~6      ~5, 1
          7        ASSIGN                                                   !2, ~6
   29     8    >   INIT_FCALL                                               'partition'
          9        SEND_REF                                                 !0
         10        SEND_VAR                                                 !1
         11        SEND_VAR                                                 !2
         12        DO_FCALL                                      0  $8      
         13        ASSIGN                                                   !3, $8
   30    14        SUB                                              ~10     !3, 1
         15        IS_SMALLER                                               !1, ~10
         16      > JMPZ                                                     ~11, ->24
   31    17    >   INIT_FCALL_BY_NAME                                       'quickSort'
         18        SEND_VAR_EX                                              !0
         19        SEND_VAR_EX                                              !1
         20        SUB                                              ~12     !3, 1
         21        SEND_VAL_EX                                              ~12
         22        DO_FCALL                                      0  $13     
         23        ASSIGN                                                   !0, $13
   33    24    >   IS_SMALLER                                               !3, !2
         25      > JMPZ                                                     ~15, ->32
   34    26    >   INIT_FCALL_BY_NAME                                       'quickSort'
         27        SEND_VAR_EX                                              !0
         28        SEND_VAR_EX                                              !3
         29        SEND_VAR_EX                                              !2
         30        DO_FCALL                                      0  $16     
         31        ASSIGN                                                   !0, $16
   37    32    > > RETURN                                                   !0
   38    33*     > RETURN                                                   null

End of function quicksort

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
193.64 ms | 1407 KiB | 17 Q