3v4l.org

run code in 300+ PHP versions simultaneously
<?php function merger($array1, $array2) { $result = array_merge($array1, $array2); } function spreader($array1, $array2) { $result = [...$array1, ...$array2]; } function uniter($array1, $array2) { $result = $array1 + $array2; } $array1 = []; $key = 'a'; for ($i = 0; $i < 500; ++$i) { $array1[++$key] = $i; } $array2 = []; for ($i = 500; $i < 1000; ++$i) { $array2[++$key] = $i; } $runs = 1000; // array_merge in loop $t0 = microtime(true); for ($i = 0; $i < $runs; ++$i) { merger($array1, $array2); } $tMerge = microtime(true); echo "merge: " . ($tMerge - $t0) . PHP_EOL; // array_merge with spread operator $t1 = microtime(true); for ($i = 0; $i < $runs; ++$i) { spreader($array1, $array2); } $tSpread = microtime(true); echo "spread: " . ($tSpread - $t1) . PHP_EOL; // union operator $t2 = microtime(true); for ($i = 0; $i < $runs; ++$i) { uniter($array1, $array2); } $tUnion = microtime(true); echo "union: " . ($tUnion - $t2);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 4
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 13
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 26
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
2 jumps found. (Code = 44) Position 1 = 54, Position 2 = 47
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
2 jumps found. (Code = 44) Position 1 = 75, Position 2 = 68
Branch analysis from position: 75
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 68
2 jumps found. (Code = 44) Position 1 = 75, Position 2 = 68
Branch analysis from position: 75
Branch analysis from position: 68
Branch analysis from position: 47
2 jumps found. (Code = 44) Position 1 = 54, Position 2 = 47
Branch analysis from position: 54
Branch analysis from position: 47
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 26
Branch analysis from position: 33
Branch analysis from position: 26
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 13
Branch analysis from position: 19
Branch analysis from position: 13
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 4
Branch analysis from position: 10
Branch analysis from position: 4
filename:       /in/J78dk
function name:  (null)
number of ops:  83
compiled vars:  !0 = $array1, !1 = $key, !2 = $i, !3 = $array2, !4 = $runs, !5 = $t0, !6 = $tMerge, !7 = $t1, !8 = $tSpread, !9 = $t2, !10 = $tUnion
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   ASSIGN                                                   !0, <array>
   16     1        ASSIGN                                                   !1, 'a'
   17     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->8
   18     4    >   PRE_INC                                          ~14     !1
          5        ASSIGN_DIM                                               !0, ~14
          6        OP_DATA                                                  !2
   17     7        PRE_INC                                                  !2
          8    >   IS_SMALLER                                               !2, 500
          9      > JMPNZ                                                    ~17, ->4
   20    10    >   ASSIGN                                                   !3, <array>
   21    11        ASSIGN                                                   !2, 500
         12      > JMP                                                      ->17
   22    13    >   PRE_INC                                          ~20     !1
         14        ASSIGN_DIM                                               !3, ~20
         15        OP_DATA                                                  !2
   21    16        PRE_INC                                                  !2
         17    >   IS_SMALLER                                               !2, 1000
         18      > JMPNZ                                                    ~23, ->13
   25    19    >   ASSIGN                                                   !4, 1000
   27    20        INIT_FCALL                                               'microtime'
         21        SEND_VAL                                                 <true>
         22        DO_ICALL                                         $25     
         23        ASSIGN                                                   !5, $25
   28    24        ASSIGN                                                   !2, 0
         25      > JMP                                                      ->31
   29    26    >   INIT_FCALL                                               'merger'
         27        SEND_VAR                                                 !0
         28        SEND_VAR                                                 !3
         29        DO_FCALL                                      0          
   28    30        PRE_INC                                                  !2
         31    >   IS_SMALLER                                               !2, !4
         32      > JMPNZ                                                    ~30, ->26
   31    33    >   INIT_FCALL                                               'microtime'
         34        SEND_VAL                                                 <true>
         35        DO_ICALL                                         $31     
         36        ASSIGN                                                   !6, $31
   32    37        SUB                                              ~33     !6, !5
         38        CONCAT                                           ~34     'merge%3A+', ~33
         39        CONCAT                                           ~35     ~34, '%0A'
         40        ECHO                                                     ~35
   35    41        INIT_FCALL                                               'microtime'
         42        SEND_VAL                                                 <true>
         43        DO_ICALL                                         $36     
         44        ASSIGN                                                   !7, $36
   36    45        ASSIGN                                                   !2, 0
         46      > JMP                                                      ->52
   37    47    >   INIT_FCALL                                               'spreader'
         48        SEND_VAR                                                 !0
         49        SEND_VAR                                                 !3
         50        DO_FCALL                                      0          
   36    51        PRE_INC                                                  !2
         52    >   IS_SMALLER                                               !2, !4
         53      > JMPNZ                                                    ~41, ->47
   39    54    >   INIT_FCALL                                               'microtime'
         55        SEND_VAL                                                 <true>
         56        DO_ICALL                                         $42     
         57        ASSIGN                                                   !8, $42
   40    58        SUB                                              ~44     !8, !7
         59        CONCAT                                           ~45     'spread%3A+', ~44
         60        CONCAT                                           ~46     ~45, '%0A'
         61        ECHO                                                     ~46
   43    62        INIT_FCALL                                               'microtime'
         63        SEND_VAL                                                 <true>
         64        DO_ICALL                                         $47     
         65        ASSIGN                                                   !9, $47
   44    66        ASSIGN                                                   !2, 0
         67      > JMP                                                      ->73
   45    68    >   INIT_FCALL                                               'uniter'
         69        SEND_VAR                                                 !0
         70        SEND_VAR                                                 !3
         71        DO_FCALL                                      0          
   44    72        PRE_INC                                                  !2
         73    >   IS_SMALLER                                               !2, !4
         74      > JMPNZ                                                    ~52, ->68
   47    75    >   INIT_FCALL                                               'microtime'
         76        SEND_VAL                                                 <true>
         77        DO_ICALL                                         $53     
         78        ASSIGN                                                   !10, $53
   48    79        SUB                                              ~55     !10, !9
         80        CONCAT                                           ~56     'union%3A+', ~55
         81        ECHO                                                     ~56
         82      > RETURN                                                   1

Function merger:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/J78dk
function name:  merger
number of ops:  8
compiled vars:  !0 = $array1, !1 = $array2, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        INIT_FCALL                                               'array_merge'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $3      
          6        ASSIGN                                                   !2, $3
    5     7      > RETURN                                                   null

End of function merger

Function spreader:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/J78dk
function name:  spreader
number of ops:  7
compiled vars:  !0 = $array1, !1 = $array2, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        INIT_ARRAY                                       ~3      
          3        ADD_ARRAY_UNPACK                                 ~3      !0
          4        ADD_ARRAY_UNPACK                                 ~3      !1
          5        ASSIGN                                                   !2, ~3
    9     6      > RETURN                                                   null

End of function spreader

Function uniter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/J78dk
function name:  uniter
number of ops:  5
compiled vars:  !0 = $array1, !1 = $array2, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   12     2        ADD                                              ~3      !0, !1
          3        ASSIGN                                                   !2, ~3
   13     4      > RETURN                                                   null

End of function uniter

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.34 ms | 1010 KiB | 18 Q