3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @param string format Sets format for size. * Format should containt string parseable by sprintf function and contain one %F macro that will be replaced by size. Another macro is U/u. It will be replaced with used unit. U for uppercase, u - lowercase. If 'i' is present at the end of format string, size multiplier will be set to 1024 (and units be KiB, MiB and so on), otherwise multiplier is set to 1000. * @example "%.0F Ui" 617 KiB * @example "%.3F Ui" 617.070 KiB * @example "%10.3F Ui" 616.85 KiB * @example "%.3F U" 632.096 KB * * @param integer $bytes Size in bytes * @param string $unit Sets default unit. Can have these values: B, KB, MG, GB, TB, PB, EB, ZB and YB */ function size_format($format, $bytes, $unit = null) { $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); $bytes = max($bytes, 0); if ($unit !== null) $unit = strtoupper($unit); if (substr($format, -1) === 'i') { $multiplier = 1024; $format = substr($format, 0, -1); } else $multiplier = 1000; if ($unit === null || !in_array($unit, $units)) { $pow = floor(($bytes ? log($bytes) : 0) / log($multiplier)); $pow = min($pow, count($units) - 1); $bytes /= pow($multiplier, $pow); $unit = $units[$pow]; } else { $pow = array_search($unit, $units); $bytes /= pow($multiplier, $pow); } if ($multiplier == 1024) $unit = (strlen($unit) == 2) ? substr($unit, 0, 1).'iB' : $unit; if (strpos($format, 'u') !== false) $format = str_replace('u', strtolower($unit), $format); else $format = str_replace('U', $unit, $format); return sprintf($format, $bytes); } var_dump(PHP_INT_MAX); $s = '9223372036854775808'; $i = (int)$s; var_dump($s, $i); var_dump(size_format('%.2F Ui', $s)); var_dump(size_format('%.2F Ui', $i));

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)
8.3.60.0100.01017.00
8.3.50.0120.00618.43
8.3.40.0140.00319.23
8.3.30.0110.00318.92
8.3.20.0050.00323.70
8.3.10.0040.00423.89
8.3.00.0050.00320.04
8.2.180.0100.00716.88
8.2.170.0090.00622.96
8.2.160.0100.00319.54
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0040.00422.36
8.2.120.0000.00726.35
8.2.110.0100.00022.56
8.2.100.0040.00818.16
8.2.90.0000.01019.48
8.2.80.0040.00417.97
8.2.70.0000.00818.18
8.2.60.0040.00418.28
8.2.50.0050.00318.10
8.2.40.0020.00519.69
8.2.30.0000.00719.45
8.2.20.0050.00318.25
8.2.10.0040.00418.30
8.2.00.0040.00418.35
8.1.280.0130.01025.92
8.1.270.0040.00420.90
8.1.260.0080.00026.35
8.1.250.0040.00428.09
8.1.240.0080.00022.86
8.1.230.0000.01218.07
8.1.220.0060.00318.04
8.1.210.0060.00318.77
8.1.200.0040.00417.48
8.1.190.0040.00417.23
8.1.180.0080.00018.10
8.1.170.0060.00318.82
8.1.160.0040.00419.13
8.1.150.0030.00519.21
8.1.140.0040.00419.68
8.1.130.0000.00719.08
8.1.120.0000.00717.74
8.1.110.0080.00017.78
8.1.100.0030.00617.76
8.1.90.0040.00417.69
8.1.80.0090.00017.58
8.1.70.0000.00817.58
8.1.60.0040.00417.88
8.1.50.0030.00617.82
8.1.40.0030.00617.75
8.1.30.0040.00417.91
8.1.20.0000.00717.79
8.1.10.0000.00717.87
8.1.00.0070.00017.66
8.0.300.0060.00318.77
8.0.290.0040.00416.88
8.0.280.0000.00718.58
8.0.270.0030.00317.45
8.0.260.0030.00317.49
8.0.250.0000.00817.17
8.0.240.0080.00017.23
8.0.230.0000.00717.08
8.0.220.0050.00316.93
8.0.210.0030.00317.16
8.0.200.0030.00317.11
8.0.190.0030.00617.23
8.0.180.0070.00017.15
8.0.170.0000.00717.04
8.0.160.0080.00017.22
8.0.150.0030.00717.07
8.0.140.0000.00717.19
8.0.130.0030.00613.55
8.0.120.0030.00517.10
8.0.110.0040.00417.00
8.0.100.0040.00417.04
8.0.90.0030.00517.12
8.0.80.0070.01417.04
8.0.70.0040.00417.18
8.0.60.0000.00817.01
8.0.50.0000.00817.19
8.0.30.0120.00517.27
8.0.20.0070.01317.57
8.0.10.0000.00817.19
8.0.00.0070.01017.28
7.4.330.0000.00515.55
7.4.320.0030.00316.82
7.4.300.0060.00016.66
7.4.290.0030.00316.79
7.4.280.0030.00716.74
7.4.270.0030.00316.87
7.4.260.0000.00716.74
7.4.250.0080.00016.69
7.4.240.0030.00316.92
7.4.230.0050.00217.00
7.4.220.0060.01216.82
7.4.210.0100.00616.80
7.4.200.0000.00716.71
7.4.160.0090.00716.67
7.4.150.0090.00917.40
7.4.140.0100.00917.86
7.4.130.0170.00816.71
7.4.120.0110.01016.68
7.4.110.0070.01016.74
7.4.100.0070.01016.77
7.4.90.0180.00716.79
7.4.80.0060.01219.39
7.4.70.0030.01316.94
7.4.60.0060.01116.85
7.4.50.0030.01316.64
7.4.40.0100.00716.71
7.4.30.0100.00716.75
7.4.00.0100.00715.14
7.3.330.0020.00213.52
7.3.320.0000.00613.60
7.3.310.0040.00416.63
7.3.300.0030.00316.58
7.3.290.0000.00716.68
7.3.280.0090.00816.60
7.3.270.0060.01117.40
7.3.260.0070.01316.95
7.3.250.0150.00816.62
7.3.240.0120.00816.63
7.3.230.0100.01016.63
7.3.210.0100.00716.63
7.3.200.0100.00716.77
7.3.190.0060.01116.66
7.3.180.0060.00916.81
7.3.170.0030.01316.86
7.3.160.0150.00316.59
7.2.330.0080.01116.56
7.2.320.0090.00916.77
7.2.310.0060.01016.92
7.2.300.0100.00717.06
7.2.290.0130.01016.72
7.2.60.0030.01017.52
7.2.00.0030.00719.80
7.1.200.0130.00516.04
7.1.100.0030.01018.63
7.1.70.0000.00817.52
7.1.60.0070.00317.58
7.1.50.0100.01334.97
7.1.40.0230.01334.57
7.1.30.0100.02734.79
7.1.20.0200.01034.59
7.1.10.0100.00716.59
7.1.00.0070.00716.82
7.0.200.0090.00317.17
7.0.190.0030.01016.68
7.0.180.0070.01016.22
7.0.170.0030.01016.38
7.0.160.0030.01016.41
7.0.150.0070.01016.31
7.0.140.0030.01016.59
7.0.130.0100.00716.57
7.0.120.0100.00716.77
7.0.110.0000.01716.39
7.0.100.0100.00716.42
7.0.90.0070.00716.62
7.0.80.0000.01016.49
7.0.70.0070.00716.41
7.0.60.0100.00716.09
7.0.50.0000.01016.32
7.0.40.0030.01016.64
7.0.30.0070.00716.55
7.0.20.0070.00716.33
7.0.10.0030.00716.59
7.0.00.0000.01016.68

preferences:
63.45 ms | 401 KiB | 5 Q