3v4l.org

run code in 300+ PHP versions simultaneously
<?php // The slow, although default way of doing fibonacci --------------------------- function _fibs($n) { if ($n < 2) return $n; else return _fibs($n-1) + _fibs($n-2); } function fibs() { $i = 0; while (1) yield _fibs($i++); } // The speedy way to do fibonacci----------------------------------------------- function fibf() { $a = 0; $b = 0; $t = 1; while (1) { yield $b; if ($b > 0) { $t = $a; $a = $b; } $b += $t; } } // Test utils ------------------------------------------------------------------ // // function to test an iterator by iterating it until the $compare function // returns false // // print the result visually because its sexy function visual_iterator_tester($fn, $cmpr) { echo "timing $fn "; $then = time(); foreach ($fn() as $f) { if ($cmpr($f)) break; echo "."; } $now = time(); $diff = $now - $then; echo "\n$fn completed in $diff second(s)\n"; } // Run the damn thing ---------------------------------------------------------- $fns = ['fibs', 'fibf']; $runs = 9999999; foreach ($fns as $fn) visual_iterator_tester($fn, function($a) use($runs) { return $a > $runs; });

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
7.2.60.0032.49516.96
7.2.00.0002.50019.57
7.1.200.0032.49215.80
7.1.100.0072.49418.11
7.1.70.0002.50117.08
7.1.60.0102.49119.21
7.1.50.0032.49817.08
7.1.00.0102.49022.39
7.0.200.0302.45014.75
7.0.140.0002.50021.94
7.0.100.0372.46319.95
7.0.90.0032.49719.95
7.0.80.0072.49319.88
7.0.70.0032.49719.91
7.0.60.0072.49319.93
7.0.50.0072.49320.30
7.0.40.0132.48720.07
7.0.30.0072.49320.09
7.0.20.0002.50020.08
7.0.10.0072.49320.04
7.0.00.0102.49019.98
5.6.280.0002.50021.07
5.6.250.0102.49020.62
5.6.240.0172.48320.63
5.6.230.0032.49720.72
5.6.220.0032.49720.70
5.6.210.0032.49720.70
5.6.200.0132.48721.15
5.6.190.0132.48720.98
5.6.180.0072.49321.11
5.6.170.0032.49721.05
5.6.160.0132.48721.17
5.6.150.0032.49721.12
5.6.140.0032.49721.11
5.6.130.0032.49721.06
5.6.120.0132.48721.11
5.6.110.0102.49021.15
5.6.100.0102.49021.08
5.6.90.0032.49721.09
5.6.80.0072.49320.46
5.6.70.0032.49720.45
5.6.60.0132.48720.34
5.6.50.0002.50020.38
5.6.40.0172.48320.56
5.6.30.0032.49720.58
5.6.20.0172.48320.36
5.6.10.2172.28320.46
5.6.00.0172.48320.54
5.5.380.0002.50020.39
5.5.370.0272.39320.46
5.5.360.0272.38320.60
5.5.350.0272.41320.44
5.5.340.0232.37020.92
5.5.330.0232.41021.01
5.5.320.0332.37720.99
5.5.310.0232.41020.95
5.5.300.0202.40320.96
5.5.290.0202.42020.86
5.5.280.0132.39320.98
5.5.270.0572.20321.00
5.5.260.0172.41320.96
5.5.250.0072.44020.62
5.5.240.0332.38320.20
5.5.230.0402.33320.34
5.5.220.0372.39020.34
5.5.210.0272.38720.36
5.5.200.0332.39720.25
5.5.190.0132.39720.31
5.5.180.0202.38720.25
5.5.160.0202.38320.22
5.5.150.0272.41720.31
5.5.140.0372.39020.05
5.5.130.0302.34320.33
5.5.120.0272.35720.36
5.5.110.0332.40320.30
5.5.100.0272.40320.08
5.5.90.0432.37720.20
5.5.80.0332.35320.00
5.5.70.0202.39320.25
5.5.60.0272.40320.25
5.5.50.0472.35720.19
5.5.40.0232.39320.25
5.5.30.0172.42020.14
5.5.20.0472.38320.05
5.5.10.0372.39320.13
5.5.00.0332.39020.13
5.4.450.0000.07719.22
5.4.440.0130.06319.36
5.4.430.0100.07319.17
5.4.420.0030.03719.44
5.4.410.0000.04019.43
5.4.400.0070.06019.09
5.4.390.0070.02719.18
5.4.380.0070.07319.03
5.4.370.0000.06319.08
5.4.360.0070.06319.16
5.4.350.0070.07319.16
5.4.340.0030.08018.90
5.4.320.0100.07019.14
5.4.310.0030.08018.85
5.4.300.0000.05718.85
5.4.290.0130.04019.03
5.4.280.0070.04318.84
5.4.270.0070.07719.04
5.4.260.0070.08019.04
5.4.250.0100.07019.20
5.4.240.0070.02719.02
5.4.230.0100.07018.91
5.4.220.0000.03719.20
5.4.210.0070.07018.89
5.4.200.0100.08019.04
5.4.190.0130.06719.04
5.4.180.0030.04719.08
5.4.170.0070.07719.17
5.4.160.0000.07719.14
5.4.150.0100.07319.11
5.4.140.0070.07716.51
5.4.130.0200.05716.48
5.4.120.0100.07316.39
5.4.110.0100.06716.46
5.4.100.0100.03316.42
5.4.90.0070.08316.40
5.4.80.0030.07316.40
5.4.70.0030.07716.40
5.4.60.0100.05316.49
5.4.50.0130.07716.37
5.4.40.0070.06316.54
5.4.30.0100.07716.46
5.4.20.0100.07016.29
5.4.10.0100.07316.48
5.4.00.0100.07015.90
5.3.290.0030.08314.73
5.3.280.0100.05714.68
5.3.270.0070.08014.57
5.3.260.0030.08014.64
5.3.250.0130.03714.66
5.3.240.0070.07714.55
5.3.230.0100.04314.66
5.3.220.0030.06714.62
5.3.210.0000.05014.49
5.3.200.0030.04314.52
5.3.190.0070.06714.69
5.3.180.0100.07314.53
5.3.170.0070.07314.69
5.3.160.0030.03714.71
5.3.150.0100.03714.52
5.3.140.0030.05014.65
5.3.130.0130.05014.57
5.3.120.0100.07014.47
5.3.110.0100.07714.63
5.3.100.0070.06714.14
5.3.90.0070.06713.99
5.3.80.0100.06313.95
5.3.70.0070.07714.01
5.3.60.0000.07714.01
5.3.50.0100.05714.07
5.3.40.0030.08313.98
5.3.30.0070.08313.90
5.3.20.0070.06713.81
5.3.10.0070.07313.55
5.3.00.0130.06313.54

preferences:
35.9 ms | 400 KiB | 5 Q