3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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);
Output for 7.1.0
xrange (10000) took 0.00067687034606934 seconds. RangeIterator (10000) took 0.0032918453216553 seconds. urange (10000) took 0.00049400329589844 seconds. range (10000) took 0.00019598007202148 seconds.
Output for 7.0.14
xrange (10000) took 0.0006568431854248 seconds. RangeIterator (10000) took 0.0039188861846924 seconds. urange (10000) took 0.00049686431884766 seconds. range (10000) took 0.00019311904907227 seconds.
Output for 7.0.10
xrange (10000) took 0.0005190372467041 seconds. RangeIterator (10000) took 0.0026910305023193 seconds. urange (10000) took 0.00050497055053711 seconds. range (10000) took 0.00016093254089355 seconds.
Output for 7.0.9
xrange (10000) took 0.00060296058654785 seconds. RangeIterator (10000) took 0.0030910968780518 seconds. urange (10000) took 0.00058412551879883 seconds. range (10000) took 0.00018596649169922 seconds.
Output for 7.0.8
xrange (10000) took 0.00058984756469727 seconds. RangeIterator (10000) took 0.0030479431152344 seconds. urange (10000) took 0.00058293342590332 seconds. range (10000) took 0.00018715858459473 seconds.
Output for 7.0.7
xrange (10000) took 0.00043702125549316 seconds. RangeIterator (10000) took 0.0022280216217041 seconds. urange (10000) took 0.00045490264892578 seconds. range (10000) took 0.0001380443572998 seconds.
Output for 7.0.6
xrange (10000) took 0.00059700012207031 seconds. RangeIterator (10000) took 0.0032641887664795 seconds. urange (10000) took 0.00058484077453613 seconds. range (10000) took 0.00018310546875 seconds.
Output for 7.0.5
xrange (10000) took 0.0005950927734375 seconds. RangeIterator (10000) took 0.0029919147491455 seconds. urange (10000) took 0.00047111511230469 seconds. range (10000) took 0.0001521110534668 seconds.
Output for 7.0.4
xrange (10000) took 0.00056910514831543 seconds. RangeIterator (10000) took 0.0028228759765625 seconds. urange (10000) took 0.00041103363037109 seconds. range (10000) took 0.00017499923706055 seconds.
Output for 7.0.3
xrange (10000) took 0.00065398216247559 seconds. RangeIterator (10000) took 0.0038058757781982 seconds. urange (10000) took 0.00049090385437012 seconds. range (10000) took 0.00020503997802734 seconds.
Output for 7.0.2
xrange (10000) took 0.00090193748474121 seconds. RangeIterator (10000) took 0.00559401512146 seconds. urange (10000) took 0.00043702125549316 seconds. range (10000) took 0.00018191337585449 seconds.
Output for 7.0.1
xrange (10000) took 0.00060582160949707 seconds. RangeIterator (10000) took 0.0032269954681396 seconds. urange (10000) took 0.00042104721069336 seconds. range (10000) took 0.00015997886657715 seconds.
Output for 7.0.0
xrange (10000) took 0.0005950927734375 seconds. RangeIterator (10000) took 0.0028271675109863 seconds. urange (10000) took 0.0004270076751709 seconds. range (10000) took 0.00017905235290527 seconds.
Output for 5.6.28
xrange (10000) took 0.0025780200958252 seconds. RangeIterator (10000) took 0.010203838348389 seconds. urange (10000) took 0.0039329528808594 seconds. range (10000) took 0.0022809505462646 seconds.
Output for 5.6.25
xrange (10000) took 0.0011439323425293 seconds. RangeIterator (10000) took 0.0047709941864014 seconds. urange (10000) took 0.0022270679473877 seconds. range (10000) took 0.001413106918335 seconds.
Output for 5.6.24
xrange (10000) took 0.0014400482177734 seconds. RangeIterator (10000) took 0.0059120655059814 seconds. urange (10000) took 0.0029230117797852 seconds. range (10000) took 0.0019509792327881 seconds.
Output for 5.6.23
xrange (10000) took 0.0013718605041504 seconds. RangeIterator (10000) took 0.005511999130249 seconds. urange (10000) took 0.0026669502258301 seconds. range (10000) took 0.0018439292907715 seconds.
Output for 5.6.22
xrange (10000) took 0.0014901161193848 seconds. RangeIterator (10000) took 0.0064411163330078 seconds. urange (10000) took 0.0030159950256348 seconds. range (10000) took 0.0019431114196777 seconds.
Output for 5.6.21
xrange (10000) took 0.0013329982757568 seconds. RangeIterator (10000) took 0.004702091217041 seconds. urange (10000) took 0.002129077911377 seconds. range (10000) took 0.0013930797576904 seconds.
Output for 5.6.20
xrange (10000) took 0.001251220703125 seconds. RangeIterator (10000) took 0.0051469802856445 seconds. urange (10000) took 0.0021941661834717 seconds. range (10000) took 0.0012729167938232 seconds.
Output for 5.6.19
xrange (10000) took 0.0010130405426025 seconds. RangeIterator (10000) took 0.0041389465332031 seconds. urange (10000) took 0.0020968914031982 seconds. range (10000) took 0.0013768672943115 seconds.
Output for 5.6.18
xrange (10000) took 0.0015280246734619 seconds. RangeIterator (10000) took 0.0064229965209961 seconds. urange (10000) took 0.0029959678649902 seconds. range (10000) took 0.0020620822906494 seconds.
Output for 5.6.17
xrange (10000) took 0.0014948844909668 seconds. RangeIterator (10000) took 0.0061759948730469 seconds. urange (10000) took 0.0028729438781738 seconds. range (10000) took 0.0018138885498047 seconds.
Output for 5.6.16
xrange (10000) took 0.0014381408691406 seconds. RangeIterator (10000) took 0.0057179927825928 seconds. urange (10000) took 0.0027940273284912 seconds. range (10000) took 0.0019221305847168 seconds.
Output for 5.6.15
xrange (10000) took 0.001392126083374 seconds. RangeIterator (10000) took 0.0057690143585205 seconds. urange (10000) took 0.0028450489044189 seconds. range (10000) took 0.0018379688262939 seconds.
Output for 5.6.14
xrange (10000) took 0.001558780670166 seconds. RangeIterator (10000) took 0.006152868270874 seconds. urange (10000) took 0.0028858184814453 seconds. range (10000) took 0.0019149780273438 seconds.
Output for 5.6.13
xrange (10000) took 0.0016379356384277 seconds. RangeIterator (10000) took 0.0064430236816406 seconds. urange (10000) took 0.0030529499053955 seconds. range (10000) took 0.0020210742950439 seconds.
Output for 5.6.12
xrange (10000) took 0.0013270378112793 seconds. RangeIterator (10000) took 0.0054450035095215 seconds. urange (10000) took 0.0025691986083984 seconds. range (10000) took 0.0016651153564453 seconds.
Output for 5.6.11
xrange (10000) took 0.0013010501861572 seconds. RangeIterator (10000) took 0.0053820610046387 seconds. urange (10000) took 0.0026719570159912 seconds. range (10000) took 0.0016851425170898 seconds.
Output for 5.6.10
xrange (10000) took 0.0017991065979004 seconds. RangeIterator (10000) took 0.0067219734191895 seconds. urange (10000) took 0.0028989315032959 seconds. range (10000) took 0.0021519660949707 seconds.
Output for 5.6.9
xrange (10000) took 0.0010800361633301 seconds. RangeIterator (10000) took 0.0052430629730225 seconds. urange (10000) took 0.0023610591888428 seconds. range (10000) took 0.0014810562133789 seconds.
Output for 5.6.8
xrange (10000) took 0.0012099742889404 seconds. RangeIterator (10000) took 0.0051138401031494 seconds. urange (10000) took 0.002504825592041 seconds. range (10000) took 0.0018229484558105 seconds.
Output for 5.6.7
xrange (10000) took 0.0012261867523193 seconds. RangeIterator (10000) took 0.0049459934234619 seconds. urange (10000) took 0.0023939609527588 seconds. range (10000) took 0.0015740394592285 seconds.
Output for 5.6.6
xrange (10000) took 0.001054048538208 seconds. RangeIterator (10000) took 0.0044071674346924 seconds. urange (10000) took 0.0020549297332764 seconds. range (10000) took 0.00148606300354 seconds.
Output for 5.6.5
xrange (10000) took 0.001209020614624 seconds. RangeIterator (10000) took 0.0049569606781006 seconds. urange (10000) took 0.002418041229248 seconds. range (10000) took 0.0015799999237061 seconds.
Output for 5.6.4
xrange (10000) took 0.0014300346374512 seconds. RangeIterator (10000) took 0.0059149265289307 seconds. urange (10000) took 0.0028009414672852 seconds. range (10000) took 0.0018389225006104 seconds.
Output for 5.6.3
xrange (10000) took 0.00091099739074707 seconds. RangeIterator (10000) took 0.0037338733673096 seconds. urange (10000) took 0.0019679069519043 seconds. range (10000) took 0.0012550354003906 seconds.
Output for 5.6.2
xrange (10000) took 0.0014951229095459 seconds. RangeIterator (10000) took 0.0058920383453369 seconds. urange (10000) took 0.0025210380554199 seconds. range (10000) took 0.0016360282897949 seconds.
Output for 5.6.1
xrange (10000) took 0.0011692047119141 seconds. RangeIterator (10000) took 0.0047509670257568 seconds. urange (10000) took 0.0022790431976318 seconds. range (10000) took 0.001492977142334 seconds.
Output for 5.6.0
xrange (10000) took 0.00142502784729 seconds. RangeIterator (10000) took 0.0059370994567871 seconds. urange (10000) took 0.0028889179229736 seconds. range (10000) took 0.0016391277313232 seconds.
Output for 5.5.38
xrange (10000) took 0.0016529560089111 seconds. RangeIterator (10000) took 0.0063440799713135 seconds. urange (10000) took 0.0030519962310791 seconds. range (10000) took 0.0020420551300049 seconds.
Output for 5.5.37
xrange (10000) took 0.00096321105957031 seconds. RangeIterator (10000) took 0.0039138793945312 seconds. urange (10000) took 0.0020308494567871 seconds. range (10000) took 0.0013439655303955 seconds.
Output for 5.5.36
xrange (10000) took 0.00093412399291992 seconds. RangeIterator (10000) took 0.0038480758666992 seconds. urange (10000) took 0.0019230842590332 seconds. range (10000) took 0.0012540817260742 seconds.
Output for 5.5.35
xrange (10000) took 0.0015199184417725 seconds. RangeIterator (10000) took 0.0057330131530762 seconds. urange (10000) took 0.0028219223022461 seconds. range (10000) took 0.0019090175628662 seconds.
Output for 5.5.34
xrange (10000) took 0.001323938369751 seconds. RangeIterator (10000) took 0.0052659511566162 seconds. urange (10000) took 0.0026421546936035 seconds. range (10000) took 0.0017669200897217 seconds.
Output for 5.5.33
xrange (10000) took 0.0016169548034668 seconds. RangeIterator (10000) took 0.0059390068054199 seconds. urange (10000) took 0.0030322074890137 seconds. range (10000) took 0.0018501281738281 seconds.
Output for 5.5.32
xrange (10000) took 0.0014941692352295 seconds. RangeIterator (10000) took 0.0074729919433594 seconds. urange (10000) took 0.003809928894043 seconds. range (10000) took 0.0019071102142334 seconds.
Output for 5.5.31
xrange (10000) took 0.001323938369751 seconds. RangeIterator (10000) took 0.0052270889282227 seconds. urange (10000) took 0.0025968551635742 seconds. range (10000) took 0.0016927719116211 seconds.
Output for 5.5.30
xrange (10000) took 0.0012519359588623 seconds. RangeIterator (10000) took 0.0050709247589111 seconds. urange (10000) took 0.0023012161254883 seconds. range (10000) took 0.0012729167938232 seconds.
Output for 5.5.29
xrange (10000) took 0.0011780261993408 seconds. RangeIterator (10000) took 0.0046288967132568 seconds. urange (10000) took 0.0024731159210205 seconds. range (10000) took 0.0015971660614014 seconds.
Output for 5.5.28
xrange (10000) took 0.0018899440765381 seconds. RangeIterator (10000) took 0.0057089328765869 seconds. urange (10000) took 0.002316951751709 seconds. range (10000) took 0.001474142074585 seconds.
Output for 5.5.27
xrange (10000) took 0.0014369487762451 seconds. RangeIterator (10000) took 0.0058319568634033 seconds. urange (10000) took 0.0026519298553467 seconds. range (10000) took 0.0018210411071777 seconds.
Output for 5.5.26
xrange (10000) took 0.0014019012451172 seconds. RangeIterator (10000) took 0.0054638385772705 seconds. urange (10000) took 0.0027599334716797 seconds. range (10000) took 0.0017859935760498 seconds.
Output for 5.5.25
xrange (10000) took 0.0011780261993408 seconds. RangeIterator (10000) took 0.0046501159667969 seconds. urange (10000) took 0.0022850036621094 seconds. range (10000) took 0.0015020370483398 seconds.
Output for 5.5.24
xrange (10000) took 0.0013480186462402 seconds. RangeIterator (10000) took 0.0056421756744385 seconds. urange (10000) took 0.002892017364502 seconds. range (10000) took 0.0018930435180664 seconds.
Output for 5.5.23
xrange (10000) took 0.0013201236724854 seconds. RangeIterator (10000) took 0.0057878494262695 seconds. urange (10000) took 0.0029251575469971 seconds. range (10000) took 0.0019040107727051 seconds.
Output for 5.5.22
xrange (10000) took 0.0013010501861572 seconds. RangeIterator (10000) took 0.0048949718475342 seconds. urange (10000) took 0.0023529529571533 seconds. range (10000) took 0.0013771057128906 seconds.
Output for 5.5.21
xrange (10000) took 0.0014970302581787 seconds. RangeIterator (10000) took 0.0076539516448975 seconds. urange (10000) took 0.0029342174530029 seconds. range (10000) took 0.0027129650115967 seconds.
Output for 5.5.20
xrange (10000) took 0.0014259815216064 seconds. RangeIterator (10000) took 0.005856990814209 seconds. urange (10000) took 0.0028800964355469 seconds. range (10000) took 0.0018429756164551 seconds.
Output for 5.5.19
xrange (10000) took 0.00092601776123047 seconds. RangeIterator (10000) took 0.0039222240447998 seconds. urange (10000) took 0.0019388198852539 seconds. range (10000) took 0.0012860298156738 seconds.
Output for 5.5.18
xrange (10000) took 0.0015771389007568 seconds. RangeIterator (10000) took 0.0065710544586182 seconds. urange (10000) took 0.003046989440918 seconds. range (10000) took 0.0016047954559326 seconds.
Output for 5.5.16
xrange (10000) took 0.0014598369598389 seconds. RangeIterator (10000) took 0.0052618980407715 seconds. urange (10000) took 0.0025410652160645 seconds. range (10000) took 0.0017540454864502 seconds.
Output for 5.5.15
xrange (10000) took 0.00091409683227539 seconds. RangeIterator (10000) took 0.003680944442749 seconds. urange (10000) took 0.0018680095672607 seconds. range (10000) took 0.0012350082397461 seconds.
Output for 5.5.14
xrange (10000) took 0.0013549327850342 seconds. RangeIterator (10000) took 0.0053131580352783 seconds. urange (10000) took 0.0026638507843018 seconds. range (10000) took 0.0017590522766113 seconds.
Output for 5.5.13
xrange (10000) took 0.0014071464538574 seconds. RangeIterator (10000) took 0.0054059028625488 seconds. urange (10000) took 0.0027568340301514 seconds. range (10000) took 0.0018351078033447 seconds.
Output for 5.5.12
xrange (10000) took 0.0012979507446289 seconds. RangeIterator (10000) took 0.004410982131958 seconds. urange (10000) took 0.0025501251220703 seconds. range (10000) took 0.0014920234680176 seconds.
Output for 5.5.11
xrange (10000) took 0.001507043838501 seconds. RangeIterator (10000) took 0.006260871887207 seconds. urange (10000) took 0.003046989440918 seconds. range (10000) took 0.0019669532775879 seconds.
Output for 5.5.10
xrange (10000) took 0.0013411045074463 seconds. RangeIterator (10000) took 0.0054910182952881 seconds. urange (10000) took 0.0027399063110352 seconds. range (10000) took 0.0016961097717285 seconds.
Output for 5.5.9
xrange (10000) took 0.0010418891906738 seconds. RangeIterator (10000) took 0.0041561126708984 seconds. urange (10000) took 0.0022001266479492 seconds. range (10000) took 0.0014100074768066 seconds.
Output for 5.5.8
xrange (10000) took 0.0014288425445557 seconds. RangeIterator (10000) took 0.0056989192962646 seconds. urange (10000) took 0.0029089450836182 seconds. range (10000) took 0.0016310214996338 seconds.
Output for 5.5.7
xrange (10000) took 0.0014779567718506 seconds. RangeIterator (10000) took 0.0056171417236328 seconds. urange (10000) took 0.0027501583099365 seconds. range (10000) took 0.0018110275268555 seconds.
Output for 5.5.6
xrange (10000) took 0.0013740062713623 seconds. RangeIterator (10000) took 0.0052850246429443 seconds. urange (10000) took 0.0026891231536865 seconds. range (10000) took 0.0017650127410889 seconds.
Output for 5.5.5
xrange (10000) took 0.0011351108551025 seconds. RangeIterator (10000) took 0.0046360492706299 seconds. urange (10000) took 0.0022351741790771 seconds. range (10000) took 0.0013461112976074 seconds.
Output for 5.5.4
xrange (10000) took 0.0014171600341797 seconds. RangeIterator (10000) took 0.0042951107025146 seconds. urange (10000) took 0.0022079944610596 seconds. range (10000) took 0.001535177230835 seconds.
Output for 5.5.3
xrange (10000) took 0.0011088848114014 seconds. RangeIterator (10000) took 0.0051770210266113 seconds. urange (10000) took 0.0028650760650635 seconds. range (10000) took 0.0018861293792725 seconds.
Output for 5.5.2
xrange (10000) took 0.002971887588501 seconds. RangeIterator (10000) took 0.0095791816711426 seconds. urange (10000) took 0.0032720565795898 seconds. range (10000) took 0.0016698837280273 seconds.
Output for 5.5.1
xrange (10000) took 0.001511812210083 seconds. RangeIterator (10000) took 0.006148099899292 seconds. urange (10000) took 0.0024640560150146 seconds. range (10000) took 0.001533031463623 seconds.
Output for 5.5.0
xrange (10000) took 0.0010020732879639 seconds. RangeIterator (10000) took 0.0039341449737549 seconds. urange (10000) took 0.0019428730010986 seconds. range (10000) took 0.0014162063598633 seconds.
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '$i' (T_VARIABLE) in /in/9BkXH on line 7
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected T_VARIABLE in /in/9BkXH on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_VARIABLE in /in/9BkXH on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/9BkXH on line 7
Process exited with code 255.