3v4l.org

run code in 300+ PHP versions simultaneously
<?php function mickmackusa($number, $decimals = 2, $dec_point = ',', $thousands_sep = ' ') { $number = number_format($number, min(5, $decimals), $dec_point, $thousands_sep); // round to decimal max return preg_replace("~".$dec_point."\d{".min(2, $decimals)."}[^0]*\K0+$~", '', $number); // trim zeros (if any, beyond minimum allowance) from right side of decimal character } function dersy($number, $decimals=2, $dec_point = ',', $thousands_sep = ' ') { $decimals = (int)$decimals; if($decimals > 5) { $decimals = 5; //Maximum decimals limit.. } $number = number_format((float)$number, $decimals, $dec_point, $thousands_sep); if(strpos($number, $dec_point) === false) { return $number; //No decimal values.. } $splArr = explode($dec_point, $number); $split = array_reverse(str_split($splArr[1])); foreach($split as $cleanNum) { if($decimals > 2 && $cleanNum === '0') { //Keep minimum two decimals. $number = substr($number, 0, -1); $decimals--; } else { break; //Found a non zero number. } } return rtrim($number,$dec_point); } $test = [ '1.01', '1.044', '0.240000', '0.200', '0.24540', '0.24546', '6500.00', '3760.54', '3760.000000000', '0.04000', '1.000000', '1.000005' ]; for ($x=0; $x<7; ++$x) { foreach ($test as $number) { $mickmackusa = mickmackusa($number, $x); $dersy = dersy($number, $x); echo "$number & $x -> Assert: $mickmackusa (Expect: $dersy) "; if ($mickmackusa === $dersy) { echo "IDENTICAL\n"; } else { echo "FAILURE\n"; } } }

Abusive script

This script was stopped while abusing our resources

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.110.0100.00020.94
8.3.100.0050.00524.06
8.3.90.0080.00026.77
8.3.80.0030.00618.68
8.3.70.0150.00416.75
8.3.60.0180.00318.43
8.3.50.0110.00817.49
8.3.40.0040.01219.00
8.3.30.0130.00319.01
8.3.20.0030.00621.89
8.3.10.0030.00523.79
8.3.00.0050.00323.41
8.2.230.0200.00022.58
8.2.220.0000.00937.54
8.2.210.0100.01026.77
8.2.200.0030.00616.88
8.2.190.0190.00616.63
8.2.180.0130.00316.62
8.2.170.0060.00922.96
8.2.160.0140.00522.25
8.2.150.0040.00424.18
8.2.140.0030.00624.66
8.2.130.0070.00420.37
8.2.120.0000.00826.35
8.2.110.0070.00321.13
8.2.100.0040.00819.28
8.2.90.0050.00319.30
8.2.80.0000.00820.63
8.2.70.0030.00617.75
8.2.60.0030.00618.05
8.2.50.0060.00318.07
8.2.40.0060.00318.22
8.2.30.0060.00318.19
8.2.20.0040.00418.17
8.2.10.0040.00418.11
8.2.00.0050.00318.36
8.1.290.0070.00330.84
8.1.280.0110.01125.92
8.1.270.0000.00824.04
8.1.260.0110.00026.35
8.1.250.0030.00628.09
8.1.240.0030.00622.35
8.1.230.0060.00621.23
8.1.220.0060.00317.89
8.1.210.0000.00818.99
8.1.200.0000.00917.48
8.1.190.0040.00417.48
8.1.180.0000.01018.10
8.1.170.0090.00018.97
8.1.160.0030.00518.95
8.1.150.0000.00820.32
8.1.140.0030.00517.75
8.1.130.0040.00419.19
8.1.120.0000.01117.73
8.1.110.0040.00417.76
8.1.100.0040.00417.61
8.1.90.0000.00817.60
8.1.80.0050.00317.68
8.1.70.0030.00917.59
8.1.60.0030.00617.80
8.1.50.0030.00617.65
8.1.40.0000.00817.78
8.1.30.0000.00917.80
8.1.20.0080.00017.86
8.1.10.0040.00417.75
8.1.00.0000.00817.75
8.0.300.0000.00720.21
8.0.290.0040.00416.75
8.0.280.0040.00418.49
8.0.270.0050.00317.32
8.0.260.0070.00017.06
8.0.250.0070.00017.23
8.0.240.0030.00617.20
8.0.230.0040.00417.10
8.0.220.0060.00317.00
8.0.210.0040.00417.16
8.0.200.0030.00317.14
8.0.190.0040.00417.17
8.0.180.0000.00717.20
8.0.170.0090.00017.19
8.0.160.0000.00817.15
8.0.150.0030.00717.09
8.0.140.0030.00517.09
8.0.130.0070.00013.58
8.0.120.0000.00817.14
8.0.110.0000.00716.97
8.0.100.0040.00417.02
8.0.90.0050.00317.19
8.0.80.0060.01017.15
8.0.70.0000.00817.18
8.0.60.0000.00817.05
8.0.50.0080.00017.20
8.0.30.0110.01117.45
8.0.20.0060.01517.40
8.0.10.0000.00817.24
8.0.00.0110.01216.96
7.4.330.0050.00015.55
7.4.320.0000.00716.84
7.4.300.0030.00316.95
7.4.290.0030.00816.80
7.4.280.0030.00516.82
7.4.270.0040.00416.89
7.4.260.0000.00716.72
7.4.250.0040.00416.79
7.4.240.0080.00016.82
7.4.230.0040.00416.63
7.4.220.0050.00317.03
7.4.210.0090.00816.86
7.4.200.0000.00816.85
7.4.160.0080.00916.78
7.4.140.0110.01217.86
7.4.130.0120.00816.69
7.4.120.0130.01016.89
7.4.110.0150.00316.68
7.4.100.0060.01216.84
7.4.90.0150.00616.70
7.4.80.0140.00719.39
7.4.70.0090.00916.90
7.4.60.0140.00716.58
7.4.50.0030.01016.66
7.4.40.0090.00916.71
7.4.10.0030.01715.13
7.4.00.0050.01115.12
7.3.330.0060.00013.59
7.3.320.0000.00713.39
7.3.310.0000.00816.62
7.3.300.0030.00316.63
7.3.290.0100.00716.58
7.3.280.0040.01416.57
7.3.260.0110.01216.78
7.3.250.0140.00716.71
7.3.240.0090.01216.67
7.3.230.0090.01216.66
7.3.210.0090.00916.97
7.3.200.0120.00616.66
7.3.190.0110.00716.68
7.3.180.0040.01416.79
7.3.170.0100.01016.59
7.3.160.0100.00716.57
7.3.130.0060.00914.94
7.3.120.0070.01115.02
7.3.110.0030.01715.31
7.3.100.0060.01015.05
7.3.90.0140.00014.98
7.3.80.0100.00715.22
7.3.70.0070.00715.17
7.3.60.0120.00315.19
7.3.50.0070.00715.09
7.3.40.0070.01015.08
7.3.30.0060.00914.71
7.3.20.0000.01816.75
7.3.10.0040.01116.82
7.3.00.0140.00317.00
7.2.330.0060.01316.71
7.2.320.0150.00716.85
7.2.310.0180.00516.88
7.2.300.0050.01416.87
7.2.290.0090.01216.98
7.2.260.0000.01815.29
7.2.250.0030.01715.50
7.2.240.0110.00715.40
7.2.230.0130.00615.14
7.2.220.0070.01015.29
7.2.210.0130.00015.23
7.2.200.0070.01015.32
7.2.190.0090.00615.33
7.2.180.0060.00615.17
7.2.170.0080.00615.25
7.2.160.0030.01315.45
7.2.150.0040.01617.06
7.2.140.0040.00716.91
7.2.130.0070.00717.10
7.2.120.0100.00717.07
7.2.110.0090.00617.30
7.2.100.0080.00317.30
7.2.90.0060.00917.33
7.2.80.0030.01217.29
7.2.70.0070.01017.30
7.2.60.0150.01017.10
7.2.50.0090.00917.19
7.2.40.0070.01017.21
7.2.30.0130.01018.42
7.2.20.0110.01318.29
7.2.10.0090.01318.42
7.2.00.0100.01218.51
7.1.330.0110.00316.18
7.1.320.0140.00315.95
7.1.310.0040.01215.91
7.1.300.0030.01015.90
7.1.290.0040.01115.95
7.1.280.0040.01116.02
7.1.270.0060.00615.90
7.1.260.0000.01316.15
7.1.250.0030.00616.00
7.1.240.0120.00315.98
7.1.230.0090.00016.04
7.1.220.0070.00715.68
7.1.210.0060.00615.83
7.1.200.0050.01316.00
7.1.190.0110.00416.07
7.1.180.0060.00915.86
7.1.170.0130.00315.73
7.1.160.0070.01115.95
7.1.150.0090.01017.18
7.1.140.0100.01417.29
7.1.130.0110.01117.22
7.1.120.0070.01517.27
7.1.110.0090.01116.92
7.1.100.0100.01117.02
7.1.90.0120.01116.70
7.1.80.0150.01016.99
7.1.70.0100.00916.19
7.1.60.0210.01628.34
7.1.50.0220.01528.07
7.1.40.0190.01427.86
7.1.30.0200.01427.85
7.1.20.0250.01527.77
7.1.10.0080.01215.95
7.1.00.0080.01215.97
7.0.330.0040.00815.64
7.0.320.0030.01015.68
7.0.310.0120.00615.70
7.0.300.0100.00315.57
7.0.290.0040.01215.52
7.0.280.0060.00615.69
7.0.270.0040.00715.54
7.0.260.0110.00315.71
7.0.250.0030.00615.47
7.0.240.0060.00615.77
7.0.230.0040.01115.76
7.0.220.0100.00315.50
7.0.210.0060.00615.51
7.0.200.0050.00315.75
7.0.190.0070.00715.34
7.0.180.0090.00315.65
7.0.170.0070.00715.74
7.0.160.0000.01315.51
7.0.150.0030.00615.73
7.0.140.0040.00815.57
7.0.130.0030.01215.71
7.0.120.0060.00315.69
7.0.110.0030.01015.80
7.0.100.0060.00315.52
7.0.90.0000.01715.60
7.0.80.0000.01215.41
7.0.70.0030.01415.59
7.0.60.0040.01115.70
7.0.50.0060.00915.68
7.0.40.0130.00313.45
7.0.30.0040.01113.79
7.0.20.0000.01013.68
7.0.10.0090.00613.77
7.0.00.0060.00513.73
5.6.400.0000.01014.28
5.6.390.0070.01014.54
5.6.380.0060.00914.71
5.6.370.0100.01014.45
5.6.360.0070.01014.38
5.6.350.0030.01314.12
5.6.340.0130.00314.72
5.6.330.0070.01014.74
5.6.320.0030.00714.77
5.6.310.0060.00614.55
5.6.300.0080.00414.17
5.6.290.0090.00014.63
5.6.280.0060.00614.32
5.6.270.0060.01014.66
5.6.260.0080.00814.46
5.6.250.0040.01114.71
5.6.240.0030.01614.41
5.6.230.0090.00914.58
5.6.220.0110.00314.80
5.6.210.0060.00914.50
5.6.200.0040.01514.38
5.6.190.0030.01314.52
5.6.180.0070.01114.54
5.6.170.0120.00314.38
5.6.160.0000.01214.34
5.6.150.0120.00314.39
5.6.140.0060.00614.65
5.6.130.0030.00614.62
5.6.120.0030.01314.40
5.6.110.0100.00014.39
5.6.100.0040.00814.46
5.6.90.0070.01014.57
5.6.80.0030.01314.38
5.6.70.0060.00614.13
5.6.60.0070.01014.52
5.6.50.0080.00414.14
5.6.40.0100.00714.50
5.6.30.0040.01214.34
5.6.20.0030.01314.57
5.6.10.0040.01114.40
5.6.00.0000.01414.43

preferences:
42.47 ms | 403 KiB | 5 Q