3v4l.org

run code in 300+ PHP versions simultaneously
<?php function formatHMS($inputval, $full = false, $timeFormat = '') { $minus = ''; if ($inputval < 0) { $minus = '- '; $inputval = -$inputval; } $unith = 3600; // Num of seconds in an Hour... $unitm = 60; // Num of seconds in a min... $hh = (int)($inputval / $unith); // '/' given value by num sec in hour... output = HOURS $ss_remaining = ($inputval - ($hh * 3600)); // '*' number of hours by seconds, then '-' from given value... output = REMAINING seconds $mm = (int)($ss_remaining / $unitm); // take remaining sec and devide by sec in a min... output = MINS $ss = ($ss_remaining - ($mm * 60)); // '*' number of mins by seconds, then '-' from remaining sec... output = REMAINING seconds. if (!$full && $ss > 30) { if ($mm === 60) { $hh++; $mm = 0; } } if ($timeFormat == '' || $timeFormat == 0) { if ($full) { return $minus . round($hh) . 'h ' . sprintf("%02d", round($mm)) . 'm ' . sprintf("%02d", round($ss)) . 's'; } if ($hh > 0) { return $minus . round($hh) . 'h ' . sprintf("%02d", round($mm)).'m'; } if ($mm > 0) { return $minus . sprintf("%02d", round($mm)).'m'; } return $minus . round($ss) . 's'; } switch ($timeFormat) { case 1: if ($full) { return $minus . sprintf("%02d", round($hh)) . ':' . sprintf("%02d", round($mm)) . ':' . sprintf("%02d", round($ss)); } return $minus . sprintf("%02d", round($hh)) . ':' . sprintf("%02d", round($mm)); case 2: return $minus . str_replace(".", ",", number_format(round($hh) + ($mm + ($ss / $unitm)) / $unitm, 2)); case 3: return $minus . number_format(round($hh) + ($mm + ($ss / $unitm)) / $unitm, 2); } } function test(){ echo formatHMS(10021, false, 0) . PHP_EOL; echo formatHMS(10021, false, 1) . PHP_EOL; echo formatHMS(10021, false, 2) . PHP_EOL; echo formatHMS(10021, false, 3) . PHP_EOL; echo formatHMS(10021, true, 0) . PHP_EOL; echo formatHMS(10021, true, 1) . PHP_EOL; echo formatHMS(10021, true, 2) . PHP_EOL; echo formatHMS(10021, true, 3) . PHP_EOL; } for($i = 0; $i < 1000; $i++){ test(); }

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.0230.01318.28
8.3.50.0160.02016.22
8.3.40.0210.01818.74
8.3.30.0130.02618.79
8.3.20.0150.00320.95
8.3.10.0090.00922.03
8.3.00.0080.01123.51
8.2.180.0250.01216.63
8.2.170.0100.01922.96
8.2.160.0200.01020.20
8.2.150.0130.01024.18
8.2.140.0100.01024.66
8.2.130.0030.01226.16
8.2.120.0120.00626.16
8.2.110.0210.00320.54
8.2.100.0090.01319.70
8.2.90.0040.01517.75
8.2.80.0150.01220.61
8.2.70.0100.00317.75
8.2.60.0060.01218.05
8.2.50.0030.01018.05
8.2.40.0070.01018.22
8.2.30.0080.00819.54
8.2.20.0100.00618.19
8.2.10.0110.00719.41
8.2.00.0070.01019.33
8.1.280.0100.02725.92
8.1.270.0180.00323.99
8.1.260.0100.01026.35
8.1.250.0090.00928.09
8.1.240.0100.01023.97
8.1.230.0070.02117.89
8.1.220.0070.01117.77
8.1.210.0070.01318.77
8.1.200.0070.01617.36
8.1.190.0060.01317.22
8.1.180.0120.00918.10
8.1.170.0000.01717.62
8.1.160.0070.01018.94
8.1.150.0120.00919.06
8.1.140.0030.01420.86
8.1.130.0100.00720.49
8.1.120.0070.01117.55
8.1.110.0060.01317.45
8.1.100.0100.00717.59
8.1.90.0060.00917.63
8.1.80.0070.01017.45
8.1.70.0070.01017.57
8.1.60.0080.01617.68
8.1.50.0140.00717.64
8.1.40.0040.01417.57
8.1.30.0000.01617.75
8.1.20.0060.02517.64
8.1.10.0040.01417.56
8.1.00.0110.00417.56
8.0.300.0090.00918.77
8.0.290.0110.00416.58
8.0.280.0060.00618.54
8.0.270.0120.00918.03
8.0.260.0060.00920.17
8.0.250.0000.01616.96
8.0.240.0030.01216.93
8.0.230.0140.00317.01
8.0.220.0060.01216.93
8.0.210.0110.00416.80
8.0.200.0080.00816.92
8.0.190.0110.01116.92
8.0.180.0030.01316.89
8.0.170.0030.02017.02
8.0.160.0000.01916.99
8.0.150.0060.00616.84
8.0.140.0100.01016.93
8.0.130.0060.00913.49
8.0.120.0070.01516.96
8.0.110.0070.01316.92
8.0.100.0100.00716.98
8.0.90.0000.01816.84
8.0.80.0130.03617.04
8.0.70.0040.01216.88
8.0.60.0070.00716.89
8.0.50.0070.00716.85
8.0.30.0210.05317.26
8.0.20.0280.06817.53
8.0.10.0070.00716.83
8.0.00.0330.05516.84
7.4.330.0090.00416.72
7.4.320.0040.01116.70
7.4.300.0060.00616.64
7.4.290.0110.00416.41
7.4.280.0060.01316.58
7.4.270.0070.01016.50
7.4.260.0070.00813.50
7.4.250.0090.00616.44
7.4.240.0050.01216.56
7.4.230.0040.01116.82
7.4.220.0050.01016.70
7.4.210.0250.02816.65
7.4.200.0070.00716.64
7.4.130.0510.07016.43
7.4.120.0440.04216.55
7.4.110.0390.03316.49
7.4.100.0460.06916.64
7.4.90.0260.04516.42
7.4.80.0190.04919.39
7.4.70.0140.04216.61
7.4.60.0260.04816.70
7.4.50.0100.02416.73
7.4.40.0260.03316.61
7.4.10.0420.05716.39
7.4.00.0480.02616.44
7.3.330.0070.01016.51
7.3.320.0060.00813.47
7.3.310.0070.01316.48
7.3.300.0000.01616.32
7.3.290.0180.04216.41
7.3.280.0190.05916.53
7.3.260.0400.03616.51
7.3.240.0300.03616.52
7.3.230.0350.03516.64
7.3.210.0340.03716.38
7.3.200.0230.03616.48
7.3.190.0320.03916.74
7.3.180.0240.03116.52
7.3.170.0240.04816.46
7.3.160.0200.03416.38
7.3.130.0520.07116.59
7.3.120.0340.04016.51
7.3.110.0400.02916.32
7.3.100.0390.04816.27
7.3.90.0370.05016.34
7.3.80.0240.07716.46
7.3.70.0420.03916.43
7.3.60.0390.05016.46
7.3.50.0490.05816.36
7.3.40.0440.03816.38
7.3.30.0320.04916.45
7.3.20.0410.06716.28
7.3.10.0330.05416.43
7.3.00.0430.07016.52
7.2.330.0290.04416.54
7.2.320.0190.04716.65
7.2.310.0210.03716.99
7.2.300.0240.03716.85
7.2.290.0160.05016.93
7.2.260.0350.03816.44
7.2.250.0190.05716.90
7.2.240.0410.03516.72
7.2.230.0360.04716.79
7.2.220.0350.06816.82
7.2.210.0420.04216.74
7.2.200.0310.04316.62
7.2.190.0290.05116.66
7.2.180.0360.04916.62
7.2.170.0360.04316.59
7.2.160.0510.06016.59
7.2.150.0430.06316.82
7.2.140.0370.05916.49
7.2.130.0480.05616.71
7.2.120.0440.05316.72
7.2.110.0270.04316.62
7.2.100.0310.04916.82
7.2.90.0290.04516.76
7.2.80.0570.04716.54
7.2.70.0260.04716.64
7.2.60.0340.04316.50
7.2.50.0350.04916.65
7.2.40.0320.03916.53
7.2.30.0410.03916.76
7.2.20.0420.03916.72
7.2.10.0470.04116.72
7.2.00.0500.03616.77

preferences:
75.81 ms | 401 KiB | 5 Q