3v4l.org

run code in 300+ PHP versions simultaneously
<?php function xrange($start, $end, $step = 1) { while ($start <= $end) { yield $start; $start += $step; } } function reduce(Generator $iterator, Callable $callback, $initial = null) { $result = $initial; foreach($iterator as $value) { $result = $callback($result, $value); } return $result; } $start = microtime(true); reduce(xrange(1, 140000), function($r, $v) {return $r + $v;}, 0); $byGen = microtime(true) - $start; $start =microtime(true); array_reduce(range(1,140000), function($r, $v) {return $r + $v;}, 0); $byNormal = microtime(true) - $start; $percent = ($byGen - $byNormal)*100/$byNormal; printf("Generator is %s than normal function %.2f%%.\n", ($byGen > $byNormal ? 'Slower' : 'Faster'), ($percent));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 48
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XFnjS
function name:  (null)
number of ops:  53
compiled vars:  !0 = $start, !1 = $byGen, !2 = $byNormal, !3 = $percent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   INIT_FCALL                                               'microtime'
          1        SEND_VAL                                                 <true>
          2        DO_ICALL                                         $4      
          3        ASSIGN                                                   !0, $4
   18     4        INIT_FCALL                                               'reduce'
          5        INIT_FCALL                                               'xrange'
          6        SEND_VAL                                                 1
          7        SEND_VAL                                                 140000
          8        DO_FCALL                                      0  $6      
          9        SEND_VAR                                                 $6
         10        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FXFnjS%3A18%240'
         11        SEND_VAL                                                 ~7
         12        SEND_VAL                                                 0
         13        DO_FCALL                                      0          
   19    14        INIT_FCALL                                               'microtime'
         15        SEND_VAL                                                 <true>
         16        DO_ICALL                                         $9      
         17        SUB                                              ~10     $9, !0
         18        ASSIGN                                                   !1, ~10
   20    19        INIT_FCALL                                               'microtime'
         20        SEND_VAL                                                 <true>
         21        DO_ICALL                                         $12     
         22        ASSIGN                                                   !0, $12
   21    23        INIT_FCALL                                               'array_reduce'
         24        INIT_FCALL                                               'range'
         25        SEND_VAL                                                 1
         26        SEND_VAL                                                 140000
         27        DO_ICALL                                         $14     
         28        SEND_VAR                                                 $14
         29        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FXFnjS%3A21%241'
         30        SEND_VAL                                                 ~15
         31        SEND_VAL                                                 0
         32        DO_ICALL                                                 
   22    33        INIT_FCALL                                               'microtime'
         34        SEND_VAL                                                 <true>
         35        DO_ICALL                                         $17     
         36        SUB                                              ~18     $17, !0
         37        ASSIGN                                                   !2, ~18
   24    38        SUB                                              ~20     !1, !2
         39        MUL                                              ~21     ~20, 100
         40        DIV                                              ~22     ~21, !2
         41        ASSIGN                                                   !3, ~22
   25    42        INIT_FCALL                                               'printf'
         43        SEND_VAL                                                 'Generator+is+%25s+than+normal+function+%25.2f%25%25.%0A'
         44        IS_SMALLER                                               !2, !1
         45      > JMPZ                                                     ~24, ->48
         46    >   QM_ASSIGN                                        ~25     'Slower'
         47      > JMP                                                      ->49
         48    >   QM_ASSIGN                                        ~25     'Faster'
         49    >   SEND_VAL                                                 ~25
         50        SEND_VAR                                                 !3
         51        DO_ICALL                                                 
         52      > RETURN                                                   1

Function xrange:
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 = 5
Branch analysis from position: 9
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 9, Position 2 = 5
Branch analysis from position: 9
Branch analysis from position: 5
filename:       /in/XFnjS
function name:  xrange
number of ops:  10
compiled vars:  !0 = $start, !1 = $end, !2 = $step
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      1
          3        GENERATOR_CREATE                                         
    3     4      > JMP                                                      ->7
    4     5    >   YIELD                                                    !0
    5     6        ASSIGN_OP                                     1          !0, !2
    3     7    >   IS_SMALLER_OR_EQUAL                                      !0, !1
          8      > JMPNZ                                                    ~5, ->5
    7     9    > > GENERATOR_RETURN                                         

End of function xrange

Function reduce:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/XFnjS
function name:  reduce
number of ops:  15
compiled vars:  !0 = $iterator, !1 = $callback, !2 = $initial, !3 = $result, !4 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
   10     3        ASSIGN                                                   !3, !2
   11     4      > FE_RESET_R                                       $6      !0, ->12
          5    > > FE_FETCH_R                                               $6, !4, ->12
   12     6    >   INIT_DYNAMIC_CALL                                        !1
          7        SEND_VAR_EX                                              !3
          8        SEND_VAR_EX                                              !4
          9        DO_FCALL                                      0  $7      
         10        ASSIGN                                                   !3, $7
   11    11      > JMP                                                      ->5
         12    >   FE_FREE                                                  $6
   14    13      > RETURN                                                   !3
   15    14*     > RETURN                                                   null

End of function reduce

Function %00%7Bclosure%7D%2Fin%2FXFnjS%3A18%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XFnjS
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $r, !1 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        ADD                                              ~2      !0, !1
          3      > RETURN                                                   ~2
          4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FXFnjS%3A18%240

Function %00%7Bclosure%7D%2Fin%2FXFnjS%3A21%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XFnjS
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $r, !1 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        ADD                                              ~2      !0, !1
          3      > RETURN                                                   ~2
          4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FXFnjS%3A21%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.87 ms | 1407 KiB | 23 Q