3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(E_ALL); function xrange($start, $end, $step = 1) { for ($i = $start; $i < $end; $i += $step) { yield $i; } } class RangeIterator implements Iterator { protected $start; protected $end; protected $step; protected $key; protected $value; public function __construct($start, $end, $step = 1) { $this->start = $start; $this->end = $end; $this->step = $step; } public function rewind() { $this->key = 0; $this->value = $this->start; } public function valid() { return $this->value < $this->end; } public function next() { $this->value += $this->step; $this->key += 1; } public function current() { return $this->value; } public function key() { return $this->key; } } function urange($start, $end, $step = 1) { $result = []; for ($i = $start; $i < $end; $i += $step) { $result[] = $i; } return $result; } function testTraversable($name, callable $traversableFactory) { $startTime = microtime(true); foreach ($traversableFactory() as $value) { // noop } echo $name, ' took ', microtime(true) - $startTime, ' seconds.', "\n"; } function testVariants($count) { testTraversable( "xrange ($count)", function() use($count) { return xrange(0, $count); } ); testTraversable( "RangeIterator ($count)", function() use($count) { return new RangeIterator(0, $count); } ); testTraversable( "urange ($count)", function() use($count) { return urange(0, $count); } ); testTraversable( "range ($count)", function() use($count) { return range(0, $count); } ); } testVariants(1000000); testVariants(10000); testVariants(100);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/24GEa
function name:  (null)
number of ops:  14
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 32767
          2        DO_ICALL                                                 
   11     3        DECLARE_CLASS                                            'rangeiterator'
   76     4        INIT_FCALL                                               'testvariants'
          5        SEND_VAL                                                 1000000
          6        DO_FCALL                                      0          
   77     7        INIT_FCALL                                               'testvariants'
          8        SEND_VAL                                                 10000
          9        DO_FCALL                                      0          
   78    10        INIT_FCALL                                               'testvariants'
         11        SEND_VAL                                                 100
         12        DO_FCALL                                      0          
         13      > RETURN                                                   1

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

End of function xrange

Function urange:
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 = 11, Position 2 = 6
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 6
Branch analysis from position: 11
Branch analysis from position: 6
filename:       /in/24GEa
function name:  urange
number of ops:  13
compiled vars:  !0 = $start, !1 = $end, !2 = $step, !3 = $result, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      1
   42     3        ASSIGN                                                   !3, <array>
   43     4        ASSIGN                                                   !4, !0
          5      > JMP                                                      ->9
   44     6    >   ASSIGN_DIM                                               !3
          7        OP_DATA                                                  !4
   43     8        ASSIGN_OP                                     1          !4, !2
          9    >   IS_SMALLER                                               !4, !1
         10      > JMPNZ                                                    ~9, ->6
   46    11    > > RETURN                                                   !3
   47    12*     > RETURN                                                   null

End of function urange

Function testtraversable:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/24GEa
function name:  testTraversable
number of ops:  22
compiled vars:  !0 = $name, !1 = $traversableFactory, !2 = $startTime, !3 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   50     2        INIT_FCALL                                               'microtime'
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $4      
          5        ASSIGN                                                   !2, $4
   51     6        INIT_DYNAMIC_CALL                                        !1
          7        DO_FCALL                                      0  $6      
          8      > FE_RESET_R                                       $7      $6, ->11
          9    > > FE_FETCH_R                                               $7, !3, ->11
         10    > > JMP                                                      ->9
         11    >   FE_FREE                                                  $7
   54    12        ECHO                                                     !0
         13        ECHO                                                     '+took+'
         14        INIT_FCALL                                               'microtime'
         15        SEND_VAL                                                 <true>
         16        DO_ICALL                                         $8      
         17        SUB                                              ~9      $8, !2
         18        ECHO                                                     ~9
         19        ECHO                                                     '+seconds.'
         20        ECHO                                                     '%0A'
   55    21      > RETURN                                                   null

End of function testtraversable

Function testvariants:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/24GEa
function name:  testVariants
number of ops:  38
compiled vars:  !0 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   RECV                                             !0      
   58     1        INIT_FCALL                                               'testtraversable'
   59     2        ROPE_INIT                                     3  ~2      'xrange+%28'
          3        ROPE_ADD                                      1  ~2      ~2, !0
          4        ROPE_END                                      2  ~1      ~2, '%29'
          5        SEND_VAL                                                 ~1
   60     6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F24GEa%3A60%241'
          7        BIND_LEXICAL                                             ~4, !0
          8        SEND_VAL                                                 ~4
          9        DO_FCALL                                      0          
   62    10        INIT_FCALL                                               'testtraversable'
   63    11        ROPE_INIT                                     3  ~7      'RangeIterator+%28'
         12        ROPE_ADD                                      1  ~7      ~7, !0
         13        ROPE_END                                      2  ~6      ~7, '%29'
         14        SEND_VAL                                                 ~6
   64    15        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F24GEa%3A64%242'
         16        BIND_LEXICAL                                             ~9, !0
         17        SEND_VAL                                                 ~9
         18        DO_FCALL                                      0          
   66    19        INIT_FCALL                                               'testtraversable'
   67    20        ROPE_INIT                                     3  ~12     'urange+%28'
         21        ROPE_ADD                                      1  ~12     ~12, !0
         22        ROPE_END                                      2  ~11     ~12, '%29'
         23        SEND_VAL                                                 ~11
   68    24        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F24GEa%3A68%243'
         25        BIND_LEXICAL                                             ~14, !0
         26        SEND_VAL                                                 ~14
         27        DO_FCALL                                      0          
   70    28        INIT_FCALL                                               'testtraversable'
   71    29        ROPE_INIT                                     3  ~17     'range+%28'
         30        ROPE_ADD                                      1  ~17     ~17, !0
         31        ROPE_END                                      2  ~16     ~17, '%29'
         32        SEND_VAL                                                 ~16
   72    33        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F24GEa%3A72%244'
         34        BIND_LEXICAL                                             ~19, !0
         35        SEND_VAL                                                 ~19
         36        DO_FCALL                                      0          
   74    37      > RETURN                                                   null

End of function testvariants

Function %00%7Bclosure%7D%2Fin%2F24GEa%3A60%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/24GEa
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   BIND_STATIC                                              !0
          1        INIT_FCALL                                               'xrange'
          2        SEND_VAL                                                 0
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $1      
          5      > RETURN                                                   $1
          6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F24GEa%3A60%241

Function %00%7Bclosure%7D%2Fin%2F24GEa%3A64%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/24GEa
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   BIND_STATIC                                              !0
          1        NEW                                              $1      'RangeIterator'
          2        SEND_VAL_EX                                              0
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
          5      > RETURN                                                   $1
          6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F24GEa%3A64%242

Function %00%7Bclosure%7D%2Fin%2F24GEa%3A68%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/24GEa
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   68     0  E >   BIND_STATIC                                              !0
          1        INIT_FCALL                                               'urange'
          2        SEND_VAL                                                 0
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $1      
          5      > RETURN                                                   $1
          6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F24GEa%3A68%243

Function %00%7Bclosure%7D%2Fin%2F24GEa%3A72%244:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/24GEa
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   72     0  E >   BIND_STATIC                                              !0
          1        INIT_FCALL                                               'range'
          2        SEND_VAL                                                 0
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5      > RETURN                                                   $1
          6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F24GEa%3A72%244

Class RangeIterator:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/24GEa
function name:  __construct
number of ops:  10
compiled vars:  !0 = $start, !1 = $end, !2 = $step
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      1
   18     3        ASSIGN_OBJ                                               'start'
          4        OP_DATA                                                  !0
   19     5        ASSIGN_OBJ                                               'end'
          6        OP_DATA                                                  !1
   20     7        ASSIGN_OBJ                                               'step'
          8        OP_DATA                                                  !2
   21     9      > RETURN                                                   null

End of function __construct

Function rewind:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/24GEa
function name:  rewind
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   ASSIGN_OBJ                                               'key'
          1        OP_DATA                                                  0
   24     2        FETCH_OBJ_R                                      ~2      'start'
          3        ASSIGN_OBJ                                               'value'
          4        OP_DATA                                                  ~2
   25     5      > RETURN                                                   null

End of function rewind

Function valid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/24GEa
function name:  valid
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   FETCH_OBJ_R                                      ~0      'value'
          1        FETCH_OBJ_R                                      ~1      'end'
          2        IS_SMALLER                                       ~2      ~0, ~1
          3      > RETURN                                                   ~2
   28     4*     > RETURN                                                   null

End of function valid

Function next:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/24GEa
function name:  next
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   FETCH_OBJ_R                                      ~1      'step'
          1        ASSIGN_OBJ_OP                                 1          'value'
          2        OP_DATA                                                  ~1
   31     3        ASSIGN_OBJ_OP                                 1          'key'
          4        OP_DATA                                                  1
   32     5      > RETURN                                                   null

End of function next

Function current:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/24GEa
function name:  current
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   FETCH_OBJ_R                                      ~0      'value'
          1      > RETURN                                                   ~0
   35     2*     > RETURN                                                   null

End of function current

Function key:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/24GEa
function name:  key
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   FETCH_OBJ_R                                      ~0      'key'
          1      > RETURN                                                   ~0
   38     2*     > RETURN                                                   null

End of function key

End of class RangeIterator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.02 ms | 1410 KiB | 28 Q