3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('ARRAY_SIZE', 512); define('RUNS', 1e4); function benchmark($function, $desc) { $total_time = 0; for($i = 0; $i < RUNS; $i++) { $total_time += $function(); } echo sprintf('%dx %s took %.5f seconds' . PHP_EOL, RUNS, $desc, $total_time); } benchmark(function() { $r = range(0, ARRAY_SIZE); $start = microtime(true); foreach ($r as $k => $v) { for($i = 0; $i++ < $v;) { $r[$k] = $v * $v; }} return microtime(true) - $start; }, 'foreach'); benchmark(function() { $r = range(0, ARRAY_SIZE); $start = microtime(true); $r = array_map(function($each) { return $each * $each; }, $r); return microtime(true) - $start; }, 'array_map');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Rc9rK
function name:  (null)
number of ops:  19
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'ARRAY_SIZE'
          2        SEND_VAL                                                 512
          3        DO_ICALL                                                 
    3     4        INIT_FCALL                                               'define'
          5        SEND_VAL                                                 'RUNS'
          6        SEND_VAL                                                 10000
          7        DO_ICALL                                                 
   13     8        INIT_FCALL                                               'benchmark'
          9        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FRc9rK%3A13%240'
   21    10        SEND_VAL                                                 ~2
         11        SEND_VAL                                                 'foreach'
         12        DO_FCALL                                      0          
   23    13        INIT_FCALL                                               'benchmark'
         14        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FRc9rK%3A23%241'
   28    15        SEND_VAL                                                 ~4
         16        SEND_VAL                                                 'array_map'
         17        DO_FCALL                                      0          
         18      > RETURN                                                   1

Function benchmark:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 5
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 5
Branch analysis from position: 12
Branch analysis from position: 5
filename:       /in/Rc9rK
function name:  benchmark
number of ops:  21
compiled vars:  !0 = $function, !1 = $desc, !2 = $total_time, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        ASSIGN                                                   !2, 0
    7     3        ASSIGN                                                   !3, 0
          4      > JMP                                                      ->9
    8     5    >   INIT_DYNAMIC_CALL                                        !0
          6        DO_FCALL                                      0  $6      
          7        ASSIGN_OP                                     1          !2, $6
    7     8        PRE_INC                                                  !3
          9    >   FETCH_CONSTANT                                   ~9      'RUNS'
         10        IS_SMALLER                                               !3, ~9
         11      > JMPNZ                                                    ~10, ->5
   10    12    >   INIT_FCALL                                               'sprintf'
         13        SEND_VAL                                                 '%25dx+%25s+took+%25.5f+seconds%0A'
         14        FETCH_CONSTANT                                   ~11     'RUNS'
         15        SEND_VAL                                                 ~11
         16        SEND_VAR                                                 !1
         17        SEND_VAR                                                 !2
         18        DO_ICALL                                         $12     
         19        ECHO                                                     $12
   11    20      > RETURN                                                   null

End of function benchmark

Function %00%7Bclosure%7D%2Fin%2FRc9rK%3A13%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 22
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 22
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 15
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 15
Branch analysis from position: 21
Branch analysis from position: 15
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/Rc9rK
function name:  {closure}
number of ops:  29
compiled vars:  !0 = $r, !1 = $start, !2 = $v, !3 = $k, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   INIT_FCALL                                               'range'
          1        SEND_VAL                                                 0
          2        FETCH_CONSTANT                                   ~5      'ARRAY_SIZE'
          3        SEND_VAL                                                 ~5
          4        DO_ICALL                                         $6      
          5        ASSIGN                                                   !0, $6
   15     6        INIT_FCALL                                               'microtime'
          7        SEND_VAL                                                 <true>
          8        DO_ICALL                                         $8      
          9        ASSIGN                                                   !1, $8
   16    10      > FE_RESET_R                                       $10     !0, ->22
         11    > > FE_FETCH_R                                       ~11     $10, !2, ->22
         12    >   ASSIGN                                                   !3, ~11
   17    13        ASSIGN                                                   !4, 0
         14      > JMP                                                      ->18
   18    15    >   MUL                                              ~15     !2, !2
         16        ASSIGN_DIM                                               !0, !3
         17        OP_DATA                                                  ~15
   17    18    >   POST_INC                                         ~16     !4
         19        IS_SMALLER                                               ~16, !2
         20      > JMPNZ                                                    ~17, ->15
   16    21    > > JMP                                                      ->11
         22    >   FE_FREE                                                  $10
   20    23        INIT_FCALL                                               'microtime'
         24        SEND_VAL                                                 <true>
         25        DO_ICALL                                         $18     
         26        SUB                                              ~19     $18, !1
         27      > RETURN                                                   ~19
   21    28*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FRc9rK%3A13%240

Function %00%7Bclosure%7D%2Fin%2FRc9rK%3A23%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Rc9rK
function name:  {closure}
number of ops:  22
compiled vars:  !0 = $r, !1 = $start
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   INIT_FCALL                                               'range'
          1        SEND_VAL                                                 0
          2        FETCH_CONSTANT                                   ~2      'ARRAY_SIZE'
          3        SEND_VAL                                                 ~2
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !0, $3
   25     6        INIT_FCALL                                               'microtime'
          7        SEND_VAL                                                 <true>
          8        DO_ICALL                                         $5      
          9        ASSIGN                                                   !1, $5
   26    10        INIT_FCALL                                               'array_map'
         11        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FRc9rK%3A26%242'
         12        SEND_VAL                                                 ~7
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $8      
         15        ASSIGN                                                   !0, $8
   27    16        INIT_FCALL                                               'microtime'
         17        SEND_VAL                                                 <true>
         18        DO_ICALL                                         $10     
         19        SUB                                              ~11     $10, !1
         20      > RETURN                                                   ~11
   28    21*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FRc9rK%3A23%241

Function %00%7Bclosure%7D%2Fin%2FRc9rK%3A26%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Rc9rK
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $each
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        MUL                                              ~1      !0, !0
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FRc9rK%3A26%242

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.82 ms | 1407 KiB | 25 Q