3v4l.org

run code in 300+ PHP versions simultaneously
<?php $test_numbers = array(20,100,555,777,1111); foreach($test_numbers as $number){ $test_array = randomArray($number); $ins = insertionSort($test_array); $select = selectionSort($test_array); echo " Select Time " .$select['time']." Select Iterations: ".$select['iterations']. " Insert Time " .$ins['time']." Insert Iterations: ".$ins['iterations']."</br>"; } function insertionSort($sort_array){ $time_start = microtime(true); $iterations = 0; for ($i = 0; $i<count($sort_array)-1; $i++){ $j = $i+1; while ($j>0){ if ($sort_array[$j-1] > $sort_array[$j]){ $iterations++; $temp = $sort_array[$j-1]; $sort_array[$j - 1] = $sort_array[$j]; $sort_array[$j] = $temp; } $j--; } } $time_end = microtime(true); $time = $time_end - $time_start; $return = array("array" => $sort_array, "time" => number_format(($time),7, '.', ''), "iterations" => $iterations); return $return; } function selectionSort($sort_array) { $time_start = microtime(true); $iterations = 0; $count = count($sort_array); for ($i = 0; $i < $count - 1; $i++) { $min = $i; for ($j = $i + 1; $j < $count; $j++) { $iterations++; if ($sort_array[$j] < $sort_array[$min]) $min = $j; } $temp = $sort_array[$i]; $sort_array[$i] = $sort_array[$min]; $sort_array[$min] = $temp; } $time_end = microtime(true); $time = $time_end - $time_start; $return = array("array" => $sort_array, "time" => number_format(($time),7, '.', ''), "iterations" => $iterations); return $return; } function randomArray($max){ $random = range(0, $max-1); shuffle($random ); return $random; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 29
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 29
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/3Y7O9
function name:  (null)
number of ops:  31
compiled vars:  !0 = $test_numbers, !1 = $number, !2 = $test_array, !3 = $ins, !4 = $select
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, <array>
    6     1      > FE_RESET_R                                       $6      !0, ->29
          2    > > FE_FETCH_R                                               $6, !1, ->29
    7     3    >   INIT_FCALL_BY_NAME                                       'randomArray'
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0  $7      
          6        ASSIGN                                                   !2, $7
    8     7        INIT_FCALL_BY_NAME                                       'insertionSort'
          8        SEND_VAR_EX                                              !2
          9        DO_FCALL                                      0  $9      
         10        ASSIGN                                                   !3, $9
    9    11        INIT_FCALL_BY_NAME                                       'selectionSort'
         12        SEND_VAR_EX                                              !2
         13        DO_FCALL                                      0  $11     
         14        ASSIGN                                                   !4, $11
   10    15        FETCH_DIM_R                                      ~13     !4, 'time'
         16        CONCAT                                           ~14     '+Select+Time+', ~13
         17        CONCAT                                           ~15     ~14, '+Select+Iterations%3A+'
         18        FETCH_DIM_R                                      ~16     !4, 'iterations'
         19        CONCAT                                           ~17     ~15, ~16
   11    20        CONCAT                                           ~18     ~17, '+Insert+Time+'
         21        FETCH_DIM_R                                      ~19     !3, 'time'
         22        CONCAT                                           ~20     ~18, ~19
         23        CONCAT                                           ~21     ~20, '+Insert+Iterations%3A+'
         24        FETCH_DIM_R                                      ~22     !3, 'iterations'
         25        CONCAT                                           ~23     ~21, ~22
         26        CONCAT                                           ~24     ~23, '%3C%2Fbr%3E'
         27        ECHO                                                     ~24
    6    28      > JMP                                                      ->2
         29    >   FE_FREE                                                  $6
   64    30      > RETURN                                                   1

Function insertionsort:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 8
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 11
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 8
Branch analysis from position: 34
Branch analysis from position: 8
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 26
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 11
Branch analysis from position: 29
Branch analysis from position: 11
Branch analysis from position: 26
filename:       /in/3Y7O9
function name:  insertionSort
number of ops:  52
compiled vars:  !0 = $sort_array, !1 = $time_start, !2 = $iterations, !3 = $i, !4 = $j, !5 = $temp, !6 = $time_end, !7 = $time, !8 = $return
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   16     1        INIT_FCALL                                               'microtime'
          2        SEND_VAL                                                 <true>
          3        DO_ICALL                                         $9      
          4        ASSIGN                                                   !1, $9
   17     5        ASSIGN                                                   !2, 0
   18     6        ASSIGN                                                   !3, 0
          7      > JMP                                                      ->30
   19     8    >   ADD                                              ~13     !3, 1
          9        ASSIGN                                                   !4, ~13
   20    10      > JMP                                                      ->27
   21    11    >   SUB                                              ~15     !4, 1
         12        FETCH_DIM_R                                      ~16     !0, ~15
         13        FETCH_DIM_R                                      ~17     !0, !4
         14        IS_SMALLER                                               ~17, ~16
         15      > JMPZ                                                     ~18, ->26
   22    16    >   PRE_INC                                                  !2
   23    17        SUB                                              ~20     !4, 1
         18        FETCH_DIM_R                                      ~21     !0, ~20
         19        ASSIGN                                                   !5, ~21
   24    20        SUB                                              ~23     !4, 1
         21        FETCH_DIM_R                                      ~25     !0, !4
         22        ASSIGN_DIM                                               !0, ~23
         23        OP_DATA                                                  ~25
   25    24        ASSIGN_DIM                                               !0, !4
         25        OP_DATA                                                  !5
   27    26    >   PRE_DEC                                                  !4
   20    27    >   IS_SMALLER                                               0, !4
         28      > JMPNZ                                                    ~28, ->11
   18    29    >   PRE_INC                                                  !3
         30    >   COUNT                                            ~30     !0
         31        SUB                                              ~31     ~30, 1
         32        IS_SMALLER                                               !3, ~31
         33      > JMPNZ                                                    ~32, ->8
   30    34    >   INIT_FCALL                                               'microtime'
         35        SEND_VAL                                                 <true>
         36        DO_ICALL                                         $33     
         37        ASSIGN                                                   !6, $33
   31    38        SUB                                              ~35     !6, !1
         39        ASSIGN                                                   !7, ~35
   32    40        INIT_ARRAY                                       ~37     !0, 'array'
         41        INIT_FCALL                                               'number_format'
         42        SEND_VAR                                                 !7
         43        SEND_VAL                                                 7
         44        SEND_VAL                                                 '.'
         45        SEND_VAL                                                 ''
         46        DO_ICALL                                         $38     
         47        ADD_ARRAY_ELEMENT                                ~37     $38, 'time'
         48        ADD_ARRAY_ELEMENT                                ~37     !2, 'iterations'
         49        ASSIGN                                                   !8, ~37
   33    50      > RETURN                                                   !8
   34    51*     > RETURN                                                   null

End of function insertionsort

Function selectionsort:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 10
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 14
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 10
Branch analysis from position: 34
Branch analysis from position: 10
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 14
Branch analysis from position: 23
Branch analysis from position: 14
Branch analysis from position: 20
filename:       /in/3Y7O9
function name:  selectionSort
number of ops:  52
compiled vars:  !0 = $sort_array, !1 = $time_start, !2 = $iterations, !3 = $count, !4 = $i, !5 = $min, !6 = $j, !7 = $temp, !8 = $time_end, !9 = $time, !10 = $return
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   38     1        INIT_FCALL                                               'microtime'
          2        SEND_VAL                                                 <true>
          3        DO_ICALL                                         $11     
          4        ASSIGN                                                   !1, $11
   39     5        ASSIGN                                                   !2, 0
   40     6        COUNT                                            ~14     !0
          7        ASSIGN                                                   !3, ~14
   41     8        ASSIGN                                                   !4, 0
          9      > JMP                                                      ->31
   43    10    >   ASSIGN                                                   !5, !4
   44    11        ADD                                              ~18     !4, 1
         12        ASSIGN                                                   !6, ~18
         13      > JMP                                                      ->21
   46    14    >   PRE_INC                                                  !2
   47    15        FETCH_DIM_R                                      ~21     !0, !6
         16        FETCH_DIM_R                                      ~22     !0, !5
         17        IS_SMALLER                                               ~21, ~22
         18      > JMPZ                                                     ~23, ->20
   48    19    >   ASSIGN                                                   !5, !6
   44    20    >   PRE_INC                                                  !6
         21    >   IS_SMALLER                                               !6, !3
         22      > JMPNZ                                                    ~26, ->14
   50    23    >   FETCH_DIM_R                                      ~27     !0, !4
         24        ASSIGN                                                   !7, ~27
   51    25        FETCH_DIM_R                                      ~30     !0, !5
         26        ASSIGN_DIM                                               !0, !4
         27        OP_DATA                                                  ~30
   52    28        ASSIGN_DIM                                               !0, !5
         29        OP_DATA                                                  !7
   41    30        PRE_INC                                                  !4
         31    >   SUB                                              ~33     !3, 1
         32        IS_SMALLER                                               !4, ~33
         33      > JMPNZ                                                    ~34, ->10
   54    34    >   INIT_FCALL                                               'microtime'
         35        SEND_VAL                                                 <true>
         36        DO_ICALL                                         $35     
         37        ASSIGN                                                   !8, $35
   55    38        SUB                                              ~37     !8, !1
         39        ASSIGN                                                   !9, ~37
   56    40        INIT_ARRAY                                       ~39     !0, 'array'
         41        INIT_FCALL                                               'number_format'
         42        SEND_VAR                                                 !9
         43        SEND_VAL                                                 7
         44        SEND_VAL                                                 '.'
         45        SEND_VAL                                                 ''
         46        DO_ICALL                                         $40     
         47        ADD_ARRAY_ELEMENT                                ~39     $40, 'time'
         48        ADD_ARRAY_ELEMENT                                ~39     !2, 'iterations'
         49        ASSIGN                                                   !10, ~39
   57    50      > RETURN                                                   !10
   58    51*     > RETURN                                                   null

End of function selectionsort

Function randomarray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3Y7O9
function name:  randomArray
number of ops:  12
compiled vars:  !0 = $max, !1 = $random
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   RECV                                             !0      
   61     1        INIT_FCALL                                               'range'
          2        SEND_VAL                                                 0
          3        SUB                                              ~2      !0, 1
          4        SEND_VAL                                                 ~2
          5        DO_ICALL                                         $3      
          6        ASSIGN                                                   !1, $3
   62     7        INIT_FCALL                                               'shuffle'
          8        SEND_REF                                                 !1
          9        DO_ICALL                                                 
   63    10      > RETURN                                                   !1
   64    11*     > RETURN                                                   null

End of function randomarray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.27 ms | 1014 KiB | 17 Q