3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Immutable class for handling numbers with precision. * * Never change the $number or the $precision after the creation of the object. */ class DecimalNumber { private $precision; private $number; /** * Get an instance given a string and a precision * @param string $string The decimal number in string form * @param int $precision The precision of the number * @return DecimalNumber Return new instance */ public static function string($string, $precision = 4) { $me = get_called_class(); $number = new $me; $number->precision = $precision; $number->number = bcadd($string, '0', $precision); return $number; } /** * Perform an addition operation * @param DecimalNumber $number the number to add * @return DecimalNumber Return the sum */ public function sum(DecimalNumber $number) { return DecimalNumber::string(bcadd($this->number, $number, $this->precision)); } public function floored() { return bcadd(bcadd($this->number, '0'), '0', $this->precision); } /** * Automagically convert to a string * @return string returns a string containing the value of this DecimalNumber */ public function __toString() { return $this->number; } } $d = DecimalNumber::createWithString('4.7'); echo $d->sum(DecimalNumber::createWithString('2.1')); echo $d->floored();

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.0120.00616.75
8.3.50.0100.00917.50
8.3.40.0150.00018.80
8.3.30.0080.00618.87
8.3.20.0030.00518.94
8.3.10.0030.00620.65
8.3.00.0040.00419.50
8.2.180.0160.00616.73
8.2.170.0070.00722.96
8.2.160.0060.01220.64
8.2.150.0080.00024.18
8.2.140.0040.00424.66
8.2.130.0050.00226.16
8.2.120.0070.00021.04
8.2.110.0100.00022.26
8.2.100.0040.00819.16
8.2.90.0060.00319.08
8.2.80.0040.00419.23
8.2.70.0040.00417.63
8.2.60.0080.00017.68
8.2.50.0040.00418.07
8.2.40.0040.00418.22
8.2.30.0030.00518.05
8.2.20.0060.00319.37
8.2.10.0040.00417.62
8.2.00.0000.00917.83
8.1.280.0110.00725.92
8.1.270.0040.00423.99
8.1.260.0080.00026.35
8.1.250.0080.00028.09
8.1.240.0000.00922.05
8.1.230.0040.00719.00
8.1.220.0050.00318.77
8.1.210.0040.00419.00
8.1.200.0060.00317.34
8.1.190.0000.00817.42
8.1.180.0040.00418.10
8.1.170.0000.00918.76
8.1.160.0080.00018.90
8.1.150.0000.00718.48
8.1.140.0040.00417.41
8.1.130.0030.00317.71
8.1.120.0040.00317.43
8.1.110.0050.00217.29
8.1.100.0000.00717.42
8.1.90.0040.00417.44
8.1.80.0000.00717.41
8.1.70.0030.00317.35
8.1.60.0060.00617.51
8.1.50.0080.00017.43
8.1.40.0080.00017.46
8.1.30.0060.00317.63
8.1.20.0040.00417.58
8.1.10.0070.00017.52
8.1.00.0000.00717.45
8.0.300.0030.00319.98
8.0.290.0030.00616.75
8.0.280.0000.00718.55
8.0.270.0070.00017.20
8.0.260.0030.00316.82
8.0.250.0040.00417.07
8.0.240.0000.00717.11
8.0.230.0030.00316.95
8.0.220.0050.00316.86
8.0.210.0030.00316.94
8.0.200.0000.00617.06
8.0.190.0040.00417.02
8.0.180.0080.00017.01
8.0.170.0000.00816.95
8.0.160.0030.00517.06
8.0.150.0040.00716.80
8.0.140.0000.00716.87
8.0.130.0030.00313.47
8.0.120.0040.00416.90
8.0.110.0050.00317.01
8.0.100.0050.00216.81
8.0.90.0000.00916.90
8.0.80.0060.01217.03
8.0.70.0000.00716.85
8.0.60.0070.00016.84
8.0.50.0040.00416.86
8.0.30.0120.00917.21
8.0.20.0160.00817.17
8.0.10.0000.00716.98
8.0.00.0080.01116.64
7.4.330.0020.00212.90
7.4.320.0030.00316.39
7.4.300.0000.00616.44
7.4.290.0030.00316.46
7.4.280.0090.00016.53
7.4.270.0070.00016.44
7.4.260.0060.00013.27
7.4.250.0000.00816.53
7.4.240.0040.00416.42
7.4.230.0030.00316.46
7.4.220.0190.00016.38
7.4.210.0000.01516.58
7.4.200.0030.00316.64
7.4.190.0070.00016.64
7.4.160.0040.01216.51
7.4.150.0130.00616.51
7.4.140.0140.01116.44
7.4.130.0070.01016.49
7.4.120.0080.00816.61
7.4.110.0170.00016.43
7.4.100.0070.01016.46
7.4.90.0110.00616.47
7.4.80.0070.01019.39
7.4.70.0140.00316.50
7.4.60.0140.00316.65
7.4.50.0080.00016.65
7.4.40.0070.01116.60
7.4.30.0090.00616.41
7.4.00.0060.00914.96
7.3.330.0000.00713.17
7.3.320.0030.00313.24
7.3.310.0030.00316.15
7.3.300.0000.00716.35
7.3.290.0090.00816.34
7.3.280.0060.01116.29
7.3.270.0130.00616.53
7.3.260.0140.00716.21
7.3.250.0090.00916.35
7.3.240.0130.00316.32
7.3.230.0150.00316.33
7.3.210.0170.00716.48
7.3.200.0060.01116.57
7.3.190.0030.01616.61
7.3.180.0060.00916.54
7.3.170.0070.00716.38
7.3.160.0070.01116.38
7.3.120.0070.01014.81
7.2.330.0100.00716.70
7.2.320.0140.00416.75
7.2.310.0120.00916.53
7.2.300.0130.00316.39
7.2.290.0090.01216.59
7.2.80.0060.00816.61
7.2.60.0070.00716.75
7.2.00.0060.00618.99
7.1.200.0040.00815.39
7.1.100.0000.01118.12
7.1.70.0000.00917.00
7.1.60.0040.01819.30
7.1.50.0000.01116.75
7.1.00.0000.04722.41
7.0.200.0000.00716.43
7.0.140.0100.06722.09
7.0.120.0100.06022.07
7.0.60.0030.08319.82
7.0.50.0200.06017.88
7.0.40.0070.08717.76
7.0.30.0170.07317.73
7.0.20.0100.08017.75
7.0.10.0170.06717.84
7.0.00.0030.08317.78
5.6.280.0100.06720.93
5.6.210.0100.08320.48
5.6.200.0000.09318.22
5.6.190.0000.07318.16
5.6.180.0130.07318.29
5.6.170.0100.07018.29
5.6.160.0130.05718.16
5.6.150.0100.07718.17
5.6.140.0030.08018.18
5.6.130.0000.07318.16
5.6.120.0100.06718.29
5.6.110.0070.05018.13
5.6.100.0070.06018.14
5.6.90.0130.05018.23
5.6.80.0070.08017.57
5.6.70.0070.06017.55
5.6.60.0070.08317.61
5.6.50.0100.04717.65
5.6.40.0070.07717.50
5.6.30.0170.06717.51
5.6.20.0070.07717.54
5.6.10.0100.05017.64
5.6.00.0030.08017.59
5.5.350.0230.08320.42
5.5.340.0170.05018.05
5.5.330.0070.04718.04
5.5.320.0000.06717.93
5.5.310.0100.08018.05
5.5.300.0100.07717.96
5.5.290.0100.08017.97
5.5.280.0030.05018.00
5.5.270.0130.04018.04
5.5.260.0100.08317.94
5.5.250.0030.04717.89
5.5.240.0070.07717.37
5.5.230.0100.07017.46
5.5.220.0070.07017.30
5.5.210.0070.05017.46
5.5.200.0070.04017.44
5.5.190.0070.06317.32
5.5.180.0030.08317.30
5.5.160.0100.04717.41
5.5.150.0070.04717.39
5.5.140.0070.06017.39
5.5.130.0130.07317.32
5.5.120.0100.05317.43
5.5.110.0100.07017.38
5.5.100.0000.05317.24
5.5.90.0070.06317.26
5.5.80.0000.05017.19
5.5.70.0200.06017.20
5.5.60.0070.05017.22
5.5.50.0100.04317.22
5.5.40.0130.07017.27
5.5.30.0130.05717.22
5.5.20.0130.05717.27
5.5.10.0030.06017.29
5.5.00.0070.07717.30
5.4.450.0030.06019.43
5.4.440.0070.04319.38
5.4.430.0100.03319.37
5.4.420.0100.06719.41
5.4.410.0130.05319.15
5.4.400.0130.07319.04
5.4.390.0100.04319.01
5.4.380.0100.03319.10
5.4.370.0100.07019.12
5.4.360.0030.05019.09
5.4.350.0030.04019.05
5.4.340.0030.08018.89
5.4.320.0130.03718.88
5.4.310.0070.04319.03
5.4.300.0000.05718.98
5.4.290.0070.05318.94
5.4.280.0100.06018.95
5.4.270.0170.06719.11
5.4.260.0070.04718.98
5.4.250.0000.08019.14
5.4.240.0070.07019.12
5.4.230.0070.07719.25
5.4.220.0030.05319.09
5.4.210.0170.06719.03
5.4.200.0070.07318.97
5.4.190.0030.07319.26
5.4.180.0100.03718.87
5.4.170.0100.03719.04
5.4.160.0130.07019.07
5.4.150.0070.03719.04
5.4.140.0100.07316.41
5.4.130.0130.06716.23
5.4.120.0030.06316.30
5.4.110.0170.06316.41
5.4.100.0100.07316.48
5.4.90.0000.07316.35
5.4.80.0070.05716.37
5.4.70.0070.06016.57
5.4.60.0130.06716.45
5.4.50.0030.05716.37
5.4.40.0100.08016.46
5.4.30.0030.06716.32
5.4.20.0070.04716.26
5.4.10.0070.07716.39
5.4.00.0030.04315.83
5.3.290.0030.04014.73
5.3.280.0170.07014.71
5.3.270.0070.04714.65
5.3.260.0030.04014.57
5.3.250.0030.06314.63
5.3.240.0200.06014.58
5.3.230.0070.06014.65
5.3.220.0070.07014.59
5.3.210.0070.07014.43
5.3.200.0030.06014.62
5.3.190.0130.07014.59
5.3.180.0070.06014.60
5.3.170.0000.05314.57
5.3.160.0000.05714.58
5.3.150.0070.06014.63
5.3.140.0130.06314.55
5.3.130.0030.06014.59
5.3.120.0100.08014.57
5.3.110.0030.07714.59
5.3.100.0100.03014.01
5.3.90.0000.04314.08
5.3.80.0130.06714.05
5.3.70.0100.06714.05
5.3.60.0000.04013.85
5.3.50.0030.08013.96
5.3.40.0030.05013.95
5.3.30.0100.07313.99
5.3.20.0070.07013.77
5.3.10.0030.07013.70
5.3.00.0170.06013.48
5.2.170.0000.06711.20
5.2.160.0000.04711.20
5.2.150.0070.06011.15
5.2.140.0100.04711.25
5.2.130.0070.06010.96
5.2.120.0030.05011.01
5.2.110.0100.05311.33
5.2.100.0070.05711.10
5.2.90.0100.05311.02
5.2.80.0130.05311.15
5.2.70.0100.05711.15
5.2.60.0000.03711.09
5.2.50.0030.03711.09
5.2.40.0100.05311.22
5.2.30.0030.06711.04
5.2.20.0030.05011.04
5.2.10.0070.04011.08
5.2.00.0100.03710.77
5.1.60.0030.03010.00
5.1.50.0030.0239.93
5.1.40.0130.0439.99
5.1.30.0030.04710.38
5.1.20.0000.04310.58
5.1.10.0030.04710.16
5.1.00.0000.03710.15
5.0.50.0030.0508.64
5.0.40.0000.0378.46
5.0.30.0030.0678.33
5.0.20.0000.0478.18
5.0.10.0100.0408.22
5.0.00.0070.0538.08
4.4.90.0000.0277.61
4.4.80.0000.0407.61
4.4.70.0100.0177.61
4.4.60.0000.0237.61
4.4.50.0000.0337.61
4.4.40.0000.0277.61
4.4.30.0000.0237.61
4.4.20.0130.0237.61
4.4.10.0030.0137.61
4.4.00.0070.0407.61
4.3.110.0000.0307.61
4.3.100.0000.0407.61
4.3.90.0000.0377.61
4.3.80.0030.0577.61
4.3.70.0030.0237.61
4.3.60.0000.0277.61
4.3.50.0070.0307.61
4.3.40.0070.0237.61
4.3.30.0000.0337.61
4.3.20.0000.0307.61
4.3.10.0030.0337.61
4.3.00.0030.0377.61

preferences:
49.25 ms | 401 KiB | 5 Q