3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (phpversion() < '5.2.1') { die('php sucks'); } function gdr_encode($val) { // all characters that json encode without escaping $chrs = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 !#$%&\'()*+,-.:;<=>?@[]^_`{|}~'; $base = strlen($chrs); $str = ''; while ($val > 0) { $str = $chrs[$val % $base] . $str; $val = (int)($val / $base); } return $str; } function gdr_decode($str) { // all characters that json encode without escaping $chrs = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 !#$%&\'()*+,-.:;<=>?@[]^_`{|}~'; $base = strlen($chrs); $map = array(); for ($i=0; $i<$base; $i++) { $map[$chrs[$i]] = $i; } $val = 0; for ($i=0; $i<strlen($str); $i++) { $val *= $base; $val += (int)$map[$str[$i]]; } return $val; } function duration($val) { if ($val < 24) { return sprintf('%d', $val).'h'; } if ($val < 24*10) { return sprintf('%1.2f', $val/24).'d'; } if ($val < 168*10) { return sprintf('%1.2f', $val/168).'w'; } //if ($val < 730*10) { // return sprintf('%1.2f', $val/730).'m'; //} return sprintf('%1.2f', $val/8760).'y'; } function cmp($val) { return strlen(gdr_encode($val))+2-strlen($val); } function insert(&$vals, $n) { $min = intval('1'.str_repeat('0', $n-1)); $max = intval(str_repeat('9', $n)); $vals[] = $min; $vals[] = $max; $cmp_min = cmp($min); $cmp_max = cmp($max); if ($cmp_min === $cmp_max) { return; } // binary search for edges if ($cmp_min+1 !== $cmp_max) { echo "ERROR: invalid search assumption: possibly missing edges: [$min => $cmp_min, $max => $cmp_max]\n"; } while ($min <= $max) { $mid = (int)(($min+$max)/2); $cmp_mid = cmp($mid); //echo "trace: [$min => $cmp_min, $mid => $cmp_mid, $max=>$cmp_max]\n"; if ($cmp_min === $cmp_mid && $cmp_mid !== cmp($mid+1)) { $vals[] = $mid; $vals[] = $mid+1; return; } //$vals[] = $mid; // include visited values in results if ($min === $max) { return; } if ($cmp_min < $cmp_mid) { $max = $mid-1; } else { $min = $mid+1; } } } $vals = array(0); for ($i=1; $i<8; $i++) { insert($vals, $i); } $vals = array_unique($vals); sort($vals); echo sprintf("%7s %7s %8s %4s\n", 'num', 'str', 'time', 'cmp'); foreach ($vals as $val) { $enc = gdr_encode($val); $dec = gdr_decode($enc); if ($dec !== $val) { echo "ERROR: $val => $enc => $dec\n"; } else { echo sprintf("%7d %7s %8s %4d\n", $dec, "\"$enc\"", duration($val), cmp($val)); } }

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.3.10.0150.00516.26
7.3.00.0140.00616.50
7.2.130.0080.01316.35
7.2.120.0230.00016.69
7.2.110.0090.01516.72
7.2.100.0150.00816.38
7.2.90.0170.00916.70
7.2.80.0150.00016.40
7.2.70.0070.01416.29
7.2.60.0110.00416.57
7.2.50.0100.00516.68
7.2.40.0140.00416.69
7.2.30.0100.01016.46
7.2.20.0070.01016.79
7.2.10.0090.00916.74
7.2.00.0070.01317.99
7.1.250.0120.00615.28
7.1.100.0090.00018.20
7.1.70.0000.00817.32
7.1.60.0140.01119.40
7.1.50.0070.01017.02
7.1.00.0100.07022.30
7.0.200.0040.00416.92
7.0.140.0030.07322.09
7.0.60.0100.08019.99
7.0.50.0070.08017.91
7.0.40.0000.05019.96
7.0.30.0300.03720.31
7.0.20.0170.04020.09
7.0.10.0070.08320.15
7.0.00.0030.04320.24
5.6.280.0070.06720.89
5.6.210.0030.08020.54
5.6.200.0030.07318.20
5.6.190.0030.08720.60
5.6.180.0230.05020.61
5.6.170.0270.05020.53
5.6.160.0070.06020.62
5.6.150.0100.05718.19
5.6.140.0030.08318.16
5.6.130.0100.05018.25
5.6.120.0130.03721.00
5.6.110.0070.08321.02
5.6.100.0100.08021.02
5.6.90.0130.07721.13
5.6.80.0070.05720.31
5.5.350.0030.08320.43
5.5.340.0030.04318.03
5.5.330.0100.05020.46
5.5.320.0400.06320.20
5.5.310.0270.06320.36
5.5.300.0100.07717.96
5.5.290.0070.04017.99
5.5.280.0100.08720.91
5.5.270.0200.07020.78
5.5.260.0030.07320.89
5.5.250.0100.06320.60
5.5.240.0230.07320.29
5.4.450.0430.04019.42
5.4.440.0530.03719.41
5.4.430.0170.05719.63
5.4.420.0470.04019.41
5.4.410.0200.04319.37
5.4.400.0800.04019.21
5.4.390.0300.04019.25
5.4.380.1030.06018.49
5.4.370.0900.05718.67
5.4.360.0770.05718.72
5.4.350.1100.05018.67
5.4.340.0670.06318.61
5.4.320.0060.04212.54
5.4.310.0050.04312.53
5.4.300.0090.03812.54
5.4.290.0070.03912.54
5.4.280.0060.03712.43
5.4.270.0080.03612.43
5.4.260.0080.03912.44
5.4.250.0090.03412.43
5.4.240.0040.03812.43
5.4.230.0040.04212.43
5.4.220.0080.03512.43
5.4.210.0060.05212.43
5.4.200.0100.04312.43
5.4.190.0040.04012.42
5.4.180.0080.03612.42
5.4.170.0090.03612.43
5.4.160.0060.03712.43
5.4.150.0040.03912.43
5.4.140.0080.03512.10
5.4.130.0070.03512.10
5.4.120.0030.03812.05
5.4.110.0130.04512.05
5.4.100.0060.03612.05
5.4.90.0060.03912.05
5.4.80.0050.03912.05
5.4.70.0090.03212.04
5.4.60.0040.03712.05
5.4.50.0040.03812.04
5.4.40.0060.03612.03
5.4.30.0080.03712.03
5.4.20.0100.04812.03
5.4.10.0070.05812.03
5.4.00.0090.04111.52
5.3.290.0100.03912.80
5.3.280.0060.04512.72
5.3.270.0080.04012.74
5.3.260.0090.04112.73
5.3.250.0160.05212.74
5.3.240.0050.06512.73
5.3.230.0110.05612.73
5.3.220.0100.05312.70
5.3.210.0090.05312.70
5.3.200.0070.05212.70
5.3.190.0060.04112.70
5.3.180.0070.03912.69
5.3.170.0100.03512.70
5.3.160.0120.04712.70
5.3.150.0110.06312.69
5.3.140.0080.04212.69
5.3.130.0080.04912.68
5.3.120.0110.04812.68
5.3.110.0050.04412.68
5.3.100.0070.04012.16
5.3.90.0070.03712.15
5.3.80.0040.04012.14
5.3.70.0050.03912.14
5.3.60.0040.03912.12
5.3.50.0060.03712.07
5.3.40.0080.03612.07
5.3.30.0100.03512.03
5.3.20.0100.03411.81
5.3.10.0060.03611.78
5.3.00.0090.03611.77
5.2.170.0040.0339.27
5.2.160.0050.0339.27
5.2.150.0030.0339.28
5.2.140.0040.0349.27
5.2.130.0060.0359.23
5.2.120.0060.0379.23
5.2.110.0060.0399.24
5.2.100.0070.0399.23
5.2.90.0060.0309.23
5.2.80.0050.0319.22
5.2.70.0040.0329.22
5.2.60.0070.0329.18
5.2.50.0070.0299.14
5.2.40.0090.0279.13
5.2.30.0060.0339.10
5.2.20.0060.0309.09
5.2.10.0070.0279.00
5.2.00.0050.0288.85
5.1.60.0030.0308.14
5.1.50.0010.0348.14
5.1.40.0030.0278.12
5.1.30.0040.0268.47
5.1.20.0030.0288.49
5.1.10.0050.0268.21
5.1.00.0070.0358.21
5.0.50.0020.0316.70
5.0.40.0030.0256.56
5.0.30.0030.0326.38
5.0.20.0020.0216.37
5.0.10.0010.0226.35
5.0.00.0050.0296.34
4.4.90.0040.0164.78
4.4.80.0000.0174.76
4.4.70.0000.0184.75
4.4.60.0040.0144.75
4.4.50.0030.0154.77
4.4.40.0020.0264.71
4.4.30.0020.0174.76
4.4.20.0010.0174.84
4.4.10.0030.0154.85
4.4.00.0030.0274.76
4.3.110.0050.0154.66
4.3.100.0020.0164.67
4.3.90.0020.0194.64
4.3.80.0070.0284.62
4.3.70.0020.0174.63
4.3.60.0050.0134.63
4.3.50.0020.0174.63
4.3.40.0040.0234.58
4.3.30.0010.0173.39
4.3.20.0030.0263.36
4.3.10.0010.0183.32
4.3.00.0000.02015.91

preferences:
37.15 ms | 401 KiB | 5 Q