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::string('4.7'); echo $d->sum(DecimalNumber::string('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.40.0040.01119.02
8.3.30.0090.00618.84
8.3.20.0040.00418.69
8.3.10.0080.00021.23
8.3.00.0080.00021.73
8.2.170.0150.00022.96
8.2.160.0070.00720.35
8.2.150.0040.00424.18
8.2.140.0000.00824.66
8.2.130.0070.00026.16
8.2.120.0070.00019.65
8.2.110.0050.00520.64
8.2.100.0040.00717.84
8.2.90.0070.00319.19
8.2.80.0000.00818.04
8.2.70.0000.01017.25
8.2.60.0050.00318.05
8.2.50.0050.00318.07
8.2.40.0060.00318.22
8.2.30.0000.01019.34
8.2.20.0050.00317.74
8.2.10.0030.00517.77
8.2.00.0000.00917.82
8.1.270.0040.00423.99
8.1.260.0160.00326.35
8.1.250.0070.00328.09
8.1.240.0090.00022.52
8.1.230.0040.00820.97
8.1.220.0050.00318.77
8.1.210.0050.00319.03
8.1.200.0050.00517.35
8.1.190.0060.00317.53
8.1.180.0080.00018.10
8.1.170.0040.00418.50
8.1.160.0050.00318.92
8.1.150.0040.00418.58
8.1.140.0040.00417.48
8.1.130.0030.00317.86
8.1.120.0050.00317.50
8.1.110.0090.00017.52
8.1.100.0070.00017.52
8.1.90.0040.00417.47
8.1.80.0070.00017.52
8.1.70.0030.00317.38
8.1.60.0040.00417.68
8.1.50.0060.00317.48
8.1.40.0000.00817.47
8.1.30.0050.00317.61
8.1.20.0000.00817.55
8.1.10.0030.00617.62
8.1.00.0080.00017.51
8.0.300.0020.00519.93
8.0.290.0000.00717.18
8.0.280.0000.00718.34
8.0.270.0050.00317.24
8.0.260.0030.00316.97
8.0.250.0050.00316.92
8.0.240.0030.00516.93
8.0.230.0000.00917.06
8.0.220.0100.00016.95
8.0.210.0060.00316.98
8.0.200.0040.00417.09
8.0.190.0040.00417.10
8.0.180.0000.00717.07
8.0.170.0000.00816.86
8.0.160.0000.00716.98
8.0.150.0040.00416.91
8.0.140.0050.00316.82
8.0.130.0050.00013.37
8.0.120.0040.00416.85
8.0.110.0040.00416.83
8.0.100.0040.00417.02
8.0.90.0000.00716.81
8.0.80.0080.00816.87
8.0.70.0000.00717.02
8.0.60.0000.00816.83
8.0.50.0040.00416.96
8.0.30.0090.01417.09
8.0.20.0150.00417.40
8.0.10.0030.00516.90
8.0.00.0110.00916.81
7.4.330.0000.00614.59
7.4.320.0000.00616.55
7.4.300.0070.00016.53
7.4.290.0030.00316.66
7.4.280.0030.00316.56
7.4.270.0030.00316.52
7.4.260.0000.00513.41
7.4.250.0000.00716.56
7.4.240.0030.00316.62
7.4.230.0030.00316.69
7.4.220.0070.01116.48
7.4.210.0070.00716.61
7.4.200.0070.00016.72
7.4.190.0030.00316.76
7.4.160.0060.01516.51
7.4.150.0030.01417.40
7.4.140.0050.01417.86
7.4.130.0120.00716.42
7.4.120.0100.00816.45
7.4.110.0100.00716.49
7.4.100.0170.00516.53
7.4.90.0060.01116.58
7.4.80.0060.01019.37
7.4.70.0060.01016.38
7.4.60.0090.01316.33
7.4.50.0060.00016.33
7.4.40.0040.01522.52
7.4.30.0140.00316.45
7.4.10.0070.01114.89
7.4.00.0030.01314.90
7.3.330.0000.00613.27
7.3.320.0030.00313.43
7.3.310.0000.00716.39
7.3.300.0000.00616.24
7.3.290.0100.00516.37
7.3.280.0120.00616.41
7.3.270.0140.00317.40
7.3.260.0170.00918.24
7.3.250.0120.00516.39
7.3.240.0100.00716.32
7.3.230.0090.00916.61
7.3.210.0100.00616.42
7.3.200.0120.00619.39
7.3.190.0040.01816.41
7.3.180.0040.01116.37
7.3.170.0060.01516.62
7.3.160.0060.01316.59
7.3.130.0130.00314.79
7.3.120.0000.01214.74
7.3.110.0070.01314.97
7.3.100.0060.00914.59
7.3.90.0100.00714.82
7.3.80.0030.00914.75
7.3.70.0060.00914.86
7.3.60.0000.01414.66
7.3.50.0060.00914.78
7.3.40.0100.00314.68
7.3.30.0070.00714.71
7.3.20.0060.01016.58
7.3.10.0030.01016.56
7.3.00.0120.00316.72
7.2.330.0040.01316.52
7.2.320.0030.01616.79
7.2.310.0030.01716.79
7.2.300.0090.00616.77
7.2.290.0120.00616.80
7.2.260.0090.00915.08
7.2.250.0090.00915.20
7.2.240.0060.00815.16
7.2.230.0000.01815.37
7.2.220.0070.01415.12
7.2.210.0070.00415.04
7.2.200.0140.00315.29
7.2.190.0100.00714.92
7.2.180.0090.00615.16
7.2.170.0070.00715.11
7.2.160.0090.00615.16
7.2.150.0030.01016.88
7.2.140.0050.00516.95
7.2.130.0030.01316.91
7.2.120.0030.00616.93
7.2.110.0040.00816.86
7.2.100.0030.00816.95
7.2.90.0040.00817.04
7.2.80.0030.00917.00
7.2.70.0030.01716.79
7.2.60.0120.00616.73
7.2.50.0130.00716.89
7.2.40.0070.00716.88
7.2.30.0100.00717.02
7.2.20.0030.00716.94
7.2.10.0120.00316.95
7.2.00.0050.01018.14
7.1.330.0100.00315.88
7.1.320.0110.00415.93
7.1.310.0140.00015.77
7.1.300.0100.00715.51
7.1.290.0040.01215.68
7.1.280.0060.00915.75
7.1.270.0070.00716.01
7.1.260.0140.00015.91
7.1.250.0070.00715.54
7.1.240.0080.00015.99
7.1.230.0030.01315.59
7.1.220.0030.01015.76
7.1.210.0110.00315.58
7.1.200.0110.00415.87
7.1.190.0070.01115.61
7.1.180.0060.00615.95
7.1.170.0100.00015.84
7.1.160.0070.01015.84
7.1.150.0070.01015.74
7.1.140.0070.00315.70
7.1.130.0060.00715.82
7.1.120.0070.01015.64
7.1.110.0060.00615.64
7.1.100.0050.00916.95
7.1.90.0070.00715.77
7.1.80.0070.00315.86
7.1.70.0040.00516.59
7.1.60.0070.01317.70
7.1.50.0100.00816.43
7.1.40.0030.00815.87
7.1.30.0030.01215.91
7.1.20.0000.01015.60
7.1.10.0030.01015.86
7.1.00.0080.03119.23
7.0.330.0090.00315.26
7.0.320.0110.00315.47
7.0.310.0100.00715.45
7.0.300.0060.01015.57
7.0.290.0070.00715.37
7.0.280.0100.00715.24
7.0.270.0030.01315.24
7.0.260.0030.01015.33
7.0.250.0030.00915.12
7.0.240.0040.01115.42
7.0.230.0040.01115.59
7.0.220.0060.00615.39
7.0.210.0070.00715.47
7.0.200.0080.00416.14
7.0.190.0060.00915.68
7.0.180.0110.00415.53
7.0.170.0030.01015.45
7.0.160.0040.00815.55
7.0.150.0030.01315.55
7.0.140.0020.04118.66
7.0.130.0100.00315.39
7.0.120.0030.01015.36
7.0.110.0060.00915.52
7.0.100.0080.00815.52
7.0.90.0110.00315.39
7.0.80.0260.02117.78
7.0.70.0280.02817.48
7.0.60.0280.04317.49
7.0.50.0280.05217.83
7.0.40.0050.04816.85
7.0.30.0100.04016.75
7.0.20.0120.04216.70
7.0.10.0050.04016.67
7.0.00.0070.04616.70
5.6.400.0030.01314.26
5.6.390.0070.00714.72
5.6.380.0070.00714.41
5.6.370.0100.01014.22
5.6.360.0090.00614.23
5.6.350.0070.01014.31
5.6.340.0120.00014.63
5.6.330.0040.01414.17
5.6.320.0030.00914.17
5.6.310.0060.00614.33
5.6.300.0040.01214.49
5.6.290.0070.00714.21
5.6.280.0100.03517.78
5.6.270.0070.01014.68
5.6.260.0000.00914.43
5.6.250.0040.01114.50
5.6.240.0070.01114.52
5.6.230.0070.04517.46
5.6.220.0090.03917.33
5.6.210.0070.04517.54
5.6.200.0110.04017.66
5.6.190.0080.04117.78
5.6.180.0090.02417.81
5.6.170.0030.04817.68
5.6.160.0020.05017.81
5.6.150.0020.05117.73
5.6.140.0090.04317.60
5.6.130.0050.03917.64
5.6.120.0050.02917.68
5.6.110.0070.02717.68
5.6.100.0050.02317.57
5.6.90.0070.03417.82
5.6.80.0030.04117.36
5.6.70.0020.04017.46
5.6.60.0020.02717.37
5.6.50.0100.04017.31
5.6.40.0030.03617.27
5.6.30.0060.03817.23
5.6.20.0120.03717.27
5.6.10.0060.04117.31
5.6.00.0070.04317.37
5.5.380.0070.00714.02
5.5.370.0060.04617.47
5.5.360.0050.03717.34
5.5.350.0080.04517.16
5.5.340.0080.04217.67
5.5.330.0100.03817.47
5.5.320.0080.04517.65
5.5.310.0080.03117.47
5.5.300.0020.03817.48
5.5.290.0040.03717.62
5.5.280.0030.04617.40
5.5.270.0100.02717.74
5.5.260.0070.02417.69
5.5.250.0030.02717.50
5.5.240.0020.02517.25
5.5.230.0110.03617.10
5.5.220.0030.03317.26
5.5.210.0100.03617.31
5.5.200.0050.04517.30
5.5.190.0050.03217.18
5.5.180.0110.03817.26
5.5.170.0030.00714.34
5.5.160.0040.04917.15
5.5.150.0050.04517.09
5.5.140.0090.04017.10
5.5.130.0080.04317.13
5.5.120.0120.04117.13
5.5.110.0100.04017.27
5.5.100.0080.04217.21
5.5.90.0080.04217.14
5.5.80.0100.02317.13
5.5.70.0110.02317.10
5.5.60.0070.02817.13
5.5.50.0140.03317.22
5.5.40.0020.03217.20
5.5.30.0110.04117.22
5.5.20.0100.03517.18
5.5.10.0110.03817.00
5.5.00.0110.04117.04
5.4.450.0050.03215.18
5.4.440.0030.04215.27
5.4.430.0050.02315.06
5.4.420.0070.02715.24
5.4.410.0080.03715.08
5.4.400.0100.03915.11
5.4.390.0060.02615.00
5.4.380.0070.03215.20
5.4.370.0100.03414.77
5.4.360.0050.03814.99
5.4.350.0000.04515.02
5.4.340.0020.03114.96
5.4.330.0030.00911.05
5.4.320.0070.03315.16
5.4.310.0090.03914.89
5.4.300.0030.04414.91
5.4.290.0050.04315.02
5.4.280.0080.03815.11
5.4.270.0040.03315.13
5.4.260.0080.02514.77
5.4.250.0080.04014.99
5.4.240.0020.04015.04
5.4.230.0080.02315.03
5.4.220.0030.04114.86
5.4.210.0060.04114.88
5.4.200.0030.04515.13
5.4.190.0020.04415.05
5.4.180.0060.03914.93
5.4.170.0070.03514.87
5.4.160.0020.04015.13
5.4.150.0070.03714.83
5.4.140.0050.03513.84
5.4.130.0060.04013.52
5.4.120.0030.03913.65
5.4.110.0050.04013.74
5.4.100.0020.04213.57
5.4.90.0030.02213.70
5.4.80.0100.03513.54
5.4.70.0110.03213.66
5.4.60.0070.03813.82
5.4.50.0060.02213.80
5.4.40.0100.02513.78
5.4.30.0060.02913.77
5.4.20.0060.03613.68
5.4.10.0060.03913.74
5.4.00.0050.03813.44
5.3.290.0070.03512.76
5.3.280.0070.03712.67
5.3.270.0030.04612.56
5.3.260.0090.03712.74
5.3.250.0050.04212.55
5.3.240.0100.03712.51
5.3.230.0070.03212.62
5.3.220.0080.04012.54
5.3.210.0030.04312.56
5.3.200.0050.02412.55
5.3.190.0050.02012.49
5.3.180.0050.03312.64
5.3.170.0080.04112.45
5.3.160.0160.03312.65
5.3.150.0080.02812.48
5.3.140.0050.03712.58
5.3.130.0030.04012.59
5.3.120.0090.03012.55
5.3.110.0070.04012.49
5.3.100.0070.03512.26
5.3.90.0100.01812.26
5.3.80.0080.02812.30
5.3.70.0090.03912.29
5.3.60.0100.03412.33
5.3.50.0070.02712.29
5.3.40.0080.03812.21
5.3.30.0100.03012.32
5.3.20.0050.03912.20
5.3.10.0070.03811.88
5.3.00.0090.02212.00
5.2.170.0070.05711.58
5.2.160.0000.04011.58
5.2.150.0030.06311.58
5.2.140.0100.02711.58
5.2.130.0030.06311.58
5.2.120.0070.03311.58
5.2.110.0070.05011.58
5.2.100.0000.04011.58
5.2.90.0170.05711.58
5.2.80.0030.06011.58
5.2.70.0130.05311.58
5.2.60.0070.04011.58
5.2.50.0030.06311.58
5.2.40.0030.04711.58
5.2.30.0030.04311.58
5.2.20.0000.06011.58
5.2.10.0070.06011.58
5.2.00.0070.05711.58
5.1.60.0130.03711.58
5.1.50.0000.05711.58
5.1.40.0070.04011.58
5.1.30.0030.05311.58
5.1.20.0130.04711.58
5.1.10.0070.03011.58
5.1.00.0130.03311.58
5.0.50.0030.04711.58
5.0.40.0130.03311.58
5.0.30.0000.06011.58
5.0.20.0030.04311.58
5.0.10.0030.04711.58
5.0.00.0000.04011.58
4.4.90.0070.03311.58
4.4.80.0000.03311.58
4.4.70.0000.02711.58
4.4.60.0100.01711.58
4.4.50.0130.02711.58
4.4.40.0070.02711.58
4.4.30.0030.03311.58
4.4.20.0070.03311.58
4.4.10.0030.03711.58
4.4.00.0000.05711.58
4.3.110.0030.03711.58
4.3.100.0030.03311.58
4.3.90.0030.03311.58
4.3.80.0000.02711.58
4.3.70.0070.03311.58
4.3.60.0030.03011.58
4.3.50.0100.02011.58
4.3.40.0070.02011.58
4.3.30.0030.03311.58
4.3.20.0000.03011.58
4.3.10.0000.03311.58
4.3.00.0000.02311.58

preferences:
29.32 ms | 400 KiB | 5 Q