3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = range(0, 1000, 1); $benchmarks = []; $runs = 100; $benchmarks['foreach'] = function ($array) { $newArray = []; foreach ($array as $item) { $newArray[] = $item * 2; } return $newArray; }; foreach ($benchmarks as $code => $callable) { $start = microtime(true); $collected = 0; while ($collected < $runs) { $collected++; $callable($array); } $end = microtime(true); printf('%s runs in %ss %s', $code, $end - $start, PHP_EOL); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 38
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 38
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 20
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 20
Branch analysis from position: 26
Branch analysis from position: 20
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/ohVb1
function name:  (null)
number of ops:  40
compiled vars:  !0 = $array, !1 = $benchmarks, !2 = $runs, !3 = $callable, !4 = $code, !5 = $start, !6 = $collected, !7 = $end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'range'
          1        SEND_VAL                                                 0
          2        SEND_VAL                                                 1000
          3        SEND_VAL                                                 1
          4        DO_ICALL                                         $8      
          5        ASSIGN                                                   !0, $8
    4     6        ASSIGN                                                   !1, <array>
    6     7        ASSIGN                                                   !2, 100
    8     8        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FohVb1%3A8%240'
          9        ASSIGN_DIM                                               !1, 'foreach'
   15    10        OP_DATA                                                  ~13
   17    11      > FE_RESET_R                                       $14     !1, ->38
         12    > > FE_FETCH_R                                       ~15     $14, !3, ->38
         13    >   ASSIGN                                                   !4, ~15
   19    14        INIT_FCALL                                               'microtime'
         15        SEND_VAL                                                 <true>
         16        DO_ICALL                                         $17     
         17        ASSIGN                                                   !5, $17
   20    18        ASSIGN                                                   !6, 0
   21    19      > JMP                                                      ->24
   22    20    >   PRE_INC                                                  !6
   23    21        INIT_DYNAMIC_CALL                                        !3
         22        SEND_VAR_EX                                              !0
         23        DO_FCALL                                      0          
   21    24    >   IS_SMALLER                                               !6, !2
         25      > JMPNZ                                                    ~22, ->20
   25    26    >   INIT_FCALL                                               'microtime'
         27        SEND_VAL                                                 <true>
         28        DO_ICALL                                         $23     
         29        ASSIGN                                                   !7, $23
   27    30        INIT_FCALL                                               'printf'
         31        SEND_VAL                                                 '%25s+runs+in+%25ss+%25s'
         32        SEND_VAR                                                 !4
         33        SUB                                              ~25     !7, !5
         34        SEND_VAL                                                 ~25
         35        SEND_VAL                                                 '%0A'
         36        DO_ICALL                                                 
   17    37      > JMP                                                      ->12
         38    >   FE_FREE                                                  $14
   28    39      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FohVb1%3A8%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/ohVb1
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $array, !1 = $newArray, !2 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
    9     1        ASSIGN                                                   !1, <array>
   10     2      > FE_RESET_R                                       $4      !0, ->8
          3    > > FE_FETCH_R                                               $4, !2, ->8
   11     4    >   MUL                                              ~6      !2, 2
          5        ASSIGN_DIM                                               !1
          6        OP_DATA                                                  ~6
   10     7      > JMP                                                      ->3
          8    >   FE_FREE                                                  $4
   14     9      > RETURN                                                   !1
   15    10*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FohVb1%3A8%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.92 ms | 1404 KiB | 19 Q