3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getBigArray($n){ $arr = []; for ($i=0; $i<$n; $i++) { $arr[] = $i; } return $arr; } function testSpeed1($n){ $array1 = getBigArray($n); $array2 = getBigArray($n); $new = []; $start = microtime(true); testArrayManipulation1($array1, $array2); $new[] = $array1; $end = microtime(true); return $end-$start; } function testSpeed2($n){ $array1 = getBigArray($n); $array2 = getBigArray($n); $new = []; $start = microtime(true); $new[] = testArrayManipulation2($array1, $array2); $end = microtime(true); return $end-$start; } function testSpeed3($n){ $array1 = getBigArray($n); $array2 = getBigArray($n); $new = []; $start = microtime(true); $new[] = testArrayManipulation3($array1, $array2); $end = microtime(true); return $end-$start; } function testArrayManipulation1(&$array1, $array2){ foreach($array2 as $v){ $array1[] = $v; } } function testArrayManipulation2(&$array1, $array2){ foreach($array2 as $v){ $array1[] = $v; } return $array1; } function testArrayManipulation3($array1, $array2){ foreach($array2 as $v){ $array1[] = $v; } return $array1; } $n = 10; $test1 = []; $test2 = []; $test3 = []; for ($i=0; $i<$n; $i++) { $length = 100000; $test1[] = testSpeed1($length); $test2[] = testSpeed2($length); $test3[] = testSpeed3($length); } echo array_sum($test1)/count($test1); echo '<br>'; echo array_sum($test2)/count($test2); echo '<br>'; echo array_sum($test3)/count($test3);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 6
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 6
Branch analysis from position: 25
Branch analysis from position: 6
filename:       /in/LaffP
function name:  (null)
number of ops:  46
compiled vars:  !0 = $n, !1 = $test1, !2 = $test2, !3 = $test3, !4 = $i, !5 = $length
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   ASSIGN                                                   !0, 10
   65     1        ASSIGN                                                   !1, <array>
   66     2        ASSIGN                                                   !2, <array>
   67     3        ASSIGN                                                   !3, <array>
   68     4        ASSIGN                                                   !4, 0
          5      > JMP                                                      ->23
   69     6    >   ASSIGN                                                   !5, 100000
   70     7        INIT_FCALL                                               'testspeed1'
          8        SEND_VAR                                                 !5
          9        DO_FCALL                                      0  $13     
         10        ASSIGN_DIM                                               !1
         11        OP_DATA                                                  $13
   71    12        INIT_FCALL                                               'testspeed2'
         13        SEND_VAR                                                 !5
         14        DO_FCALL                                      0  $15     
         15        ASSIGN_DIM                                               !2
         16        OP_DATA                                                  $15
   72    17        INIT_FCALL                                               'testspeed3'
         18        SEND_VAR                                                 !5
         19        DO_FCALL                                      0  $17     
         20        ASSIGN_DIM                                               !3
         21        OP_DATA                                                  $17
   68    22        PRE_INC                                                  !4
         23    >   IS_SMALLER                                               !4, !0
         24      > JMPNZ                                                    ~19, ->6
   75    25    >   INIT_FCALL                                               'array_sum'
         26        SEND_VAR                                                 !1
         27        DO_ICALL                                         $20     
         28        COUNT                                            ~21     !1
         29        DIV                                              ~22     $20, ~21
         30        ECHO                                                     ~22
   76    31        ECHO                                                     '%3Cbr%3E'
   77    32        INIT_FCALL                                               'array_sum'
         33        SEND_VAR                                                 !2
         34        DO_ICALL                                         $23     
         35        COUNT                                            ~24     !2
         36        DIV                                              ~25     $23, ~24
         37        ECHO                                                     ~25
   78    38        ECHO                                                     '%3Cbr%3E'
   79    39        INIT_FCALL                                               'array_sum'
         40        SEND_VAR                                                 !3
         41        DO_ICALL                                         $26     
         42        COUNT                                            ~27     !3
         43        DIV                                              ~28     $26, ~27
         44        ECHO                                                     ~28
         45      > RETURN                                                   1

Function getbigarray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 9, Position 2 = 4
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 9, Position 2 = 4
Branch analysis from position: 9
Branch analysis from position: 4
filename:       /in/LaffP
function name:  getBigArray
number of ops:  11
compiled vars:  !0 = $n, !1 = $arr, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, <array>
    5     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->7
    6     4    >   ASSIGN_DIM                                               !1
          5        OP_DATA                                                  !2
    5     6        PRE_INC                                                  !2
          7    >   IS_SMALLER                                               !2, !0
          8      > JMPNZ                                                    ~7, ->4
    8     9    > > RETURN                                                   !1
    9    10*     > RETURN                                                   null

End of function getbigarray

Function testspeed1:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LaffP
function name:  testSpeed1
number of ops:  27
compiled vars:  !0 = $n, !1 = $array1, !2 = $array2, !3 = $new, !4 = $start, !5 = $end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1        INIT_FCALL                                               'getbigarray'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $6      
          4        ASSIGN                                                   !1, $6
   14     5        INIT_FCALL                                               'getbigarray'
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0  $8      
          8        ASSIGN                                                   !2, $8
   15     9        ASSIGN                                                   !3, <array>
   16    10        INIT_FCALL                                               'microtime'
         11        SEND_VAL                                                 <true>
         12        DO_ICALL                                         $11     
         13        ASSIGN                                                   !4, $11
   17    14        INIT_FCALL_BY_NAME                                       'testArrayManipulation1'
         15        SEND_VAR_EX                                              !1
         16        SEND_VAR_EX                                              !2
         17        DO_FCALL                                      0          
   18    18        ASSIGN_DIM                                               !3
         19        OP_DATA                                                  !1
   19    20        INIT_FCALL                                               'microtime'
         21        SEND_VAL                                                 <true>
         22        DO_ICALL                                         $15     
         23        ASSIGN                                                   !5, $15
   20    24        SUB                                              ~17     !5, !4
         25      > RETURN                                                   ~17
   21    26*     > RETURN                                                   null

End of function testspeed1

Function testspeed2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LaffP
function name:  testSpeed2
number of ops:  27
compiled vars:  !0 = $n, !1 = $array1, !2 = $array2, !3 = $new, !4 = $start, !5 = $end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   24     1        INIT_FCALL                                               'getbigarray'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $6      
          4        ASSIGN                                                   !1, $6
   25     5        INIT_FCALL                                               'getbigarray'
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0  $8      
          8        ASSIGN                                                   !2, $8
   26     9        ASSIGN                                                   !3, <array>
   27    10        INIT_FCALL                                               'microtime'
         11        SEND_VAL                                                 <true>
         12        DO_ICALL                                         $11     
         13        ASSIGN                                                   !4, $11
   28    14        INIT_FCALL_BY_NAME                                       'testArrayManipulation2'
         15        SEND_VAR_EX                                              !1
         16        SEND_VAR_EX                                              !2
         17        DO_FCALL                                      0  $14     
         18        ASSIGN_DIM                                               !3
         19        OP_DATA                                                  $14
   29    20        INIT_FCALL                                               'microtime'
         21        SEND_VAL                                                 <true>
         22        DO_ICALL                                         $15     
         23        ASSIGN                                                   !5, $15
   30    24        SUB                                              ~17     !5, !4
         25      > RETURN                                                   ~17
   31    26*     > RETURN                                                   null

End of function testspeed2

Function testspeed3:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LaffP
function name:  testSpeed3
number of ops:  27
compiled vars:  !0 = $n, !1 = $array1, !2 = $array2, !3 = $new, !4 = $start, !5 = $end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
   34     1        INIT_FCALL                                               'getbigarray'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $6      
          4        ASSIGN                                                   !1, $6
   35     5        INIT_FCALL                                               'getbigarray'
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0  $8      
          8        ASSIGN                                                   !2, $8
   36     9        ASSIGN                                                   !3, <array>
   37    10        INIT_FCALL                                               'microtime'
         11        SEND_VAL                                                 <true>
         12        DO_ICALL                                         $11     
         13        ASSIGN                                                   !4, $11
   38    14        INIT_FCALL_BY_NAME                                       'testArrayManipulation3'
         15        SEND_VAR_EX                                              !1
         16        SEND_VAR_EX                                              !2
         17        DO_FCALL                                      0  $14     
         18        ASSIGN_DIM                                               !3
         19        OP_DATA                                                  $14
   39    20        INIT_FCALL                                               'microtime'
         21        SEND_VAL                                                 <true>
         22        DO_ICALL                                         $15     
         23        ASSIGN                                                   !5, $15
   40    24        SUB                                              ~17     !5, !4
         25      > RETURN                                                   ~17
   41    26*     > RETURN                                                   null

End of function testspeed3

Function testarraymanipulation1:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/LaffP
function name:  testArrayManipulation1
number of ops:  9
compiled vars:  !0 = $array1, !1 = $array2, !2 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   44     2      > FE_RESET_R                                       $3      !1, ->7
          3    > > FE_FETCH_R                                               $3, !2, ->7
   45     4    >   ASSIGN_DIM                                               !0
          5        OP_DATA                                                  !2
   44     6      > JMP                                                      ->3
          7    >   FE_FREE                                                  $3
   47     8      > RETURN                                                   null

End of function testarraymanipulation1

Function testarraymanipulation2:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/LaffP
function name:  testArrayManipulation2
number of ops:  10
compiled vars:  !0 = $array1, !1 = $array2, !2 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   50     2      > FE_RESET_R                                       $3      !1, ->7
          3    > > FE_FETCH_R                                               $3, !2, ->7
   51     4    >   ASSIGN_DIM                                               !0
          5        OP_DATA                                                  !2
   50     6      > JMP                                                      ->3
          7    >   FE_FREE                                                  $3
   53     8      > RETURN                                                   !0
   54     9*     > RETURN                                                   null

End of function testarraymanipulation2

Function testarraymanipulation3:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/LaffP
function name:  testArrayManipulation3
number of ops:  10
compiled vars:  !0 = $array1, !1 = $array2, !2 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   57     2      > FE_RESET_R                                       $3      !1, ->7
          3    > > FE_FETCH_R                                               $3, !2, ->7
   58     4    >   ASSIGN_DIM                                               !0
          5        OP_DATA                                                  !2
   57     6      > JMP                                                      ->3
          7    >   FE_FREE                                                  $3
   60     8      > RETURN                                                   !0
   61     9*     > RETURN                                                   null

End of function testarraymanipulation3

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.95 ms | 1025 KiB | 24 Q