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; } 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.0160.01318.18
8.3.50.0190.00616.27
8.3.40.0100.02018.84
8.3.30.0120.01518.84
8.3.20.0080.00620.89
8.3.10.0030.01021.94
8.3.00.0040.00823.62
8.2.180.0100.01625.92
8.2.170.0210.00718.90
8.2.160.0160.01022.96
8.2.150.0090.00324.18
8.2.140.0030.01024.66
8.2.130.0070.00726.16
8.2.120.0120.00019.72
8.2.110.0130.00320.96
8.2.100.0210.00717.78
8.2.90.0060.00919.16
8.2.80.0030.00917.97
8.2.70.0060.00817.50
8.2.60.0060.00618.16
8.2.50.0090.00318.07
8.2.40.0040.00818.35
8.2.30.0110.00418.09
8.2.20.0000.01218.08
8.2.10.0040.00919.30
8.2.00.0040.01119.46
8.1.280.0160.01325.92
8.1.270.0090.00622.20
8.1.260.0100.00326.35
8.1.250.0070.00728.09
8.1.240.0070.01021.27
8.1.230.0160.00318.96
8.1.220.0100.00317.77
8.1.210.0030.00918.77
8.1.200.0070.01017.48
8.1.190.0070.00717.35
8.1.180.0090.00318.10
8.1.170.0090.00318.67
8.1.160.0090.00618.95
8.1.150.0000.01318.98
8.1.140.0060.00620.87
8.1.130.0000.01217.43
8.1.120.0060.00617.45
8.1.110.0070.00717.51
8.1.100.0090.00317.51
8.1.90.0000.01217.38
8.1.80.0060.00617.45
8.1.70.0030.00917.53
8.1.60.0070.01017.66
8.1.50.0030.00917.62
8.1.40.0090.00317.55
8.1.30.0060.00617.74
8.1.20.0100.00717.67
8.1.10.0000.01517.60
8.1.00.0060.00617.59
8.0.300.0060.00618.77
8.0.290.0080.00816.63
8.0.280.0060.00618.44
8.0.270.0100.00717.96
8.0.260.0000.01216.91
8.0.250.0040.00716.91
8.0.240.0000.01117.05
8.0.230.0040.00816.96
8.0.220.0000.01416.92
8.0.210.0070.00717.05
8.0.200.0040.00717.13
8.0.190.0090.00617.09
8.0.180.0030.01317.04
8.0.170.0130.00817.02
8.0.160.0040.01116.96
8.0.150.0040.00816.82
8.0.140.0040.01116.80
8.0.130.0070.00413.39
8.0.120.0060.00616.97
8.0.110.0060.00616.95
8.0.100.0040.00716.78
8.0.90.0070.00716.85
8.0.80.0130.01917.04
8.0.70.0040.00816.86
8.0.60.0040.00816.78
8.0.50.0100.00316.97
8.0.30.0250.01617.29
8.0.20.0210.02417.23
8.0.10.0040.00817.22
8.0.00.0450.04716.90
7.4.330.0090.00016.90
7.4.320.0030.00916.70
7.4.300.0050.00516.61
7.4.290.0030.00816.49
7.4.280.0070.00716.60
7.4.270.0060.00616.61
7.4.260.0030.00613.38
7.4.250.0040.00716.66
7.4.240.0000.01216.55
7.4.230.0030.00816.73
7.4.220.0040.00716.63
7.4.210.0100.03216.55
7.4.200.0040.00716.54
7.4.130.0270.03016.62
7.4.120.0130.03516.68
7.4.110.0210.02116.62
7.4.100.0230.02016.88
7.4.90.0230.03616.49
7.4.80.0240.01719.39
7.4.70.0160.02016.56
7.4.60.0260.01316.60
7.4.50.0070.01716.57
7.4.40.0260.01316.50
7.4.10.0130.03316.58
7.4.00.0130.03016.66
7.3.330.0030.00916.39
7.3.320.0030.00613.31
7.3.310.0060.00616.50
7.3.300.0030.00916.32
7.3.290.0120.03016.43
7.3.280.0220.01616.46
7.3.260.0250.01816.57
7.3.240.0230.02216.62
7.3.230.0220.02516.41
7.3.210.0110.03816.68
7.3.200.0180.02416.45
7.3.190.0250.02916.74
7.3.180.0130.02316.62
7.3.170.0170.03816.49
7.3.160.0130.03316.45
7.3.130.0350.02516.62
7.3.120.0210.02116.39
7.3.110.0250.01416.38
7.3.100.0200.02616.58
7.3.90.0410.02816.41
7.3.80.0170.03416.46
7.3.70.0160.03316.53
7.3.60.0310.02816.63
7.3.50.0290.01616.48
7.3.40.0140.03116.36
7.3.30.0150.03116.47
7.3.20.0340.03616.31
7.3.10.0200.02416.44
7.3.00.0210.03016.39
7.2.330.0150.02816.82
7.2.320.0260.01016.75
7.2.310.0170.02116.81
7.2.300.0220.02616.56
7.2.290.0190.03216.59
7.2.260.0280.02816.44
7.2.250.0200.02816.77
7.2.240.0160.02916.76
7.2.230.0160.04016.63
7.2.220.0310.04016.55
7.2.210.0260.02216.45
7.2.200.0250.03116.60
7.2.190.0170.02716.54
7.2.180.0140.02416.64
7.2.170.0190.02916.62
7.2.160.0160.02516.64
7.2.150.0130.03816.64
7.2.140.0280.01916.71
7.2.130.0330.02716.70
7.2.120.0030.04216.62
7.2.110.0160.03316.66
7.2.100.0190.02516.55
7.2.90.0210.02316.75
7.2.80.0070.03616.59
7.2.70.0160.03316.55
7.2.60.0190.02116.62
7.2.50.0190.02316.56
7.2.40.0240.02116.86
7.2.30.0160.02916.86
7.2.20.0160.03516.62
7.2.10.0290.02016.55
7.2.00.0190.02216.59

preferences:
42.89 ms | 401 KiB | 5 Q