3v4l.org

run code in 300+ PHP versions simultaneously
<?php class BigDecimal { private $value; private $scale; function __construct(string $value){ if(preg_match('@^[0-9]*(?:.[0-9]*)?$@', $value) !== 1){ throw new Error("Invalid BigDecimal value $value"); } $this->value = $value; $this->scale = $this->getScaleOf($value); } private function getScale(BigDecimal $other){ return max($this->scale, $other->scale); } private function getScaleOf(string $value){ $pos = strrpos($value, '.'); if($pos === false){ return 0; } return strlen($value) - $pos - 1; } function compareTo($other){ return bccomp($this, $other, $this->getScale($other)); } function gt($other){ return $this->compareTo($other) > 0; } function gte($other){ return $this->compareTo($other) >= 0; } function lt($other){ return $this->compareTo($other) < 0; } function lte($other){ return $this->compareTo($other) <= 0; } function eq($other){ return $this->compareTo($other) === 0; } function add(BigDecimal $other){ return new self(bcadd($this, $other, $this->getScale($other))); } function div(BigDecimal $other){ return new self(bcdiv($this, $other, $this->getScale($other))); } function mod(BigDecimal $other){ // not sure if mod or rem return new self(bcmod($this, $other, $this->getScale($other))); } function mul(BigDecimal $other){ return new self(bcmul($this, $other, $this->getScale($other))); } function pow(BigDecimal $other){ return new self(bcpow($this, $other, $this->getScale($other))); } function sub(BigDecimal $other){ return new self(bcsub($this, $other, $this->getScale($other))); } function __toString(){ return $this->value; } } function d(string $value){ return new BigDecimal($value); } echo d('10.123')->sub(d('5.02')) . "\n"; echo d('10')->sub(d('5')) . "\n"; var_dump(d('10.12345678')->gt(d('10.1234567777777777777777777777777'))); var_dump(d('10.12345678')->gt(d('10.1234567800000000000000000000000000001'))); // false var_dump(d('10.12345678')->gte(d('10.123456780000000000000000000'))); // true

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.5.30.0070.01120.21
8.5.20.0120.00620.27
8.5.10.0040.00420.09
8.5.00.0130.00821.75
8.4.180.0050.00721.68
8.4.170.0150.00920.40
8.4.160.0140.00723.93
8.4.150.0070.00517.02
8.4.140.0130.00817.73
8.4.130.0060.00418.83
8.4.120.0150.00324.07
8.4.110.0110.01018.89
8.4.100.0080.01318.61
8.4.90.0100.01020.55
8.4.80.0100.01018.59
8.4.70.0120.00918.95
8.4.60.0100.01118.62
8.4.50.0120.00720.60
8.4.40.0130.00317.95
8.4.30.0030.01819.71
8.4.20.0060.01320.41
8.4.10.0030.00619.61
8.3.300.0170.01120.91
8.3.290.0100.01120.69
8.3.280.0140.01118.54
8.3.270.0100.01016.75
8.3.260.0110.00916.96
8.3.250.0140.00519.01
8.3.240.0130.00617.31
8.3.230.0140.00517.00
8.3.220.0110.00919.16
8.3.210.0080.01118.62
8.3.200.0050.00616.78
8.3.190.0090.01117.09
8.3.180.0100.00919.16
8.3.170.0090.00918.96
8.3.160.0120.00617.08
8.3.150.0070.01116.86
8.3.140.0120.00619.12
8.3.130.0100.00018.59
8.3.120.0100.00718.81
8.3.110.0060.00320.94
8.3.100.0090.00916.97
8.3.90.0080.00016.98
8.3.80.0090.00018.55
8.3.70.0070.00718.43
8.3.60.0170.00417.00
8.3.50.0080.00922.11
8.3.40.0040.01119.01
8.3.30.0040.01118.82
8.3.20.0040.00419.23
8.3.10.0050.00321.72
8.3.00.0030.00620.85
8.2.300.0110.01022.16
8.2.290.0030.00520.54
8.2.280.0090.00620.21
8.2.270.0060.01316.79
8.2.260.0030.00516.71
8.2.250.0140.00016.98
8.2.240.0000.00818.56
8.2.230.0030.00722.58
8.2.220.0060.00324.06
8.2.210.0040.00426.77
8.2.200.0060.00318.41
8.2.190.0040.01518.79
8.2.180.0100.01018.50
8.2.170.0000.01522.96
8.2.160.0070.01020.51
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0060.00320.07
8.2.120.0080.00026.35
8.2.110.0070.00321.13
8.2.100.0040.00817.84
8.2.90.0040.00418.09
8.2.80.0060.00318.09
8.2.70.0000.00919.63
8.2.60.0040.00417.88
8.2.50.0080.00018.10
8.2.40.0050.00320.40
8.2.30.0070.00419.28
8.2.20.0050.00218.05
8.2.10.0080.00018.15
8.2.00.0040.00417.87
8.1.340.0110.00917.93
8.1.330.0130.00622.09
8.1.320.0130.00718.26
8.1.310.0000.01916.66
8.1.300.0040.00416.70
8.1.290.0040.00818.88
8.1.280.0070.01125.92
8.1.270.0100.01021.99
8.1.260.0080.00028.09
8.1.250.0050.00328.09
8.1.240.0030.00723.83
8.1.230.0110.00020.97
8.1.220.0000.00817.77
8.1.210.0060.00319.04
8.1.200.0050.00317.60
8.1.190.0000.00817.36
8.1.180.0030.00618.10
8.1.170.0040.00418.89
8.1.160.0000.00718.96
8.1.150.0000.00720.44
8.1.140.0040.00419.64
8.1.130.0070.00017.78
8.1.120.0000.00717.56
8.1.110.0050.00317.55
8.1.100.0000.00817.57
8.1.90.0000.00717.68
8.1.80.0040.00417.68
8.1.70.0000.00717.56
8.1.60.0000.00817.78
8.1.50.0030.00617.77
8.1.40.0000.00917.75
8.1.30.0030.00517.79
8.1.20.0040.00417.76
8.1.10.0080.00017.68
8.1.00.0030.00517.69
8.0.300.0000.00720.11
8.0.290.0050.00217.00
8.0.280.0050.00318.64
8.0.270.0040.00417.43
8.0.260.0030.00617.24
8.0.250.0000.00717.15
8.0.240.0000.00817.20
8.0.230.0000.00817.21
8.0.220.0040.00417.04
8.0.210.0000.00717.15
8.0.200.0000.00717.07
8.0.190.0030.00717.10
8.0.180.0030.00517.20
8.0.170.0040.00417.21
8.0.160.0050.00217.11
8.0.150.0040.00417.10
8.0.140.0040.00417.09
8.0.130.0060.00013.63
8.0.120.0080.00017.16
8.0.110.0050.00317.19
8.0.100.0080.00016.97
8.0.90.0000.00717.10
8.0.80.0110.01217.11
8.0.70.0000.00716.95
8.0.60.0040.00417.05
8.0.50.0040.00416.97
8.0.30.0060.01117.18
8.0.20.0090.00917.45
8.0.10.0040.00417.14
8.0.00.0060.01217.03
7.4.330.0060.00015.55
7.4.320.0000.00616.91
7.4.300.0040.00416.74
7.4.290.0040.00416.76
7.4.280.0030.00516.64
7.4.270.0000.00716.68
7.4.260.0000.00716.84
7.4.250.0030.00516.75
7.4.240.0040.00316.82
7.4.230.0000.00716.70
7.4.220.0140.00616.81
7.4.210.0160.00616.81
7.4.200.0040.00416.61
7.4.160.0070.01016.91
7.4.150.0100.01017.40
7.4.140.0120.00617.86
7.4.130.0090.01016.82
7.4.120.0160.00216.78
7.4.110.0110.00716.68
7.4.100.0070.01116.62
7.4.90.0100.00716.80
7.4.80.0090.01319.39
7.4.70.0130.00316.64
7.4.60.0130.00416.85
7.4.50.0060.01216.70
7.4.40.0130.01016.84
7.4.30.0090.01716.70
7.4.00.0040.00815.24
7.3.330.0050.00013.44
7.3.320.0030.00313.48
7.3.310.0050.00316.61
7.3.300.0030.00316.52
7.3.290.0100.00616.59
7.3.280.0100.01016.54
7.3.270.0170.00717.40
7.3.260.0130.00416.89
7.3.250.0120.00516.71
7.3.240.0130.00716.83
7.3.230.0140.00416.71
7.3.210.0110.00616.93
7.3.200.0100.00616.91
7.3.190.0120.01216.68
7.3.180.0030.01317.00
7.3.170.0060.01116.78
7.3.160.0110.00616.95
7.2.330.0030.01516.92
7.2.320.0120.00616.89
7.2.310.0030.01416.75
7.2.300.0060.01716.98
7.2.290.0040.01316.79
7.2.60.0070.00717.00
7.1.200.0030.00615.88
7.1.70.0110.00017.14
7.1.60.0110.00717.51
7.1.50.0290.00734.91
7.1.00.0000.07722.50
7.0.200.0080.00814.43
7.0.130.0100.07722.07
7.0.120.0230.06722.21
7.0.110.0030.07022.13
7.0.100.0030.06722.14
7.0.90.0070.06322.02
7.0.80.0000.06722.01
7.0.70.0100.06721.96
7.0.60.0070.06321.89
7.0.50.0230.04722.11
7.0.40.0200.06021.99
7.0.30.0100.06022.09
7.0.20.0130.07022.20
7.0.10.0100.07322.03
7.0.00.0000.08322.05
5.6.280.0130.05721.16
5.6.270.0030.08020.98
5.6.260.0170.05320.89
5.6.250.0030.06320.93
5.6.240.0100.06020.85
5.6.230.0070.06321.14
5.6.220.0030.09020.99
5.6.210.0070.07720.89
5.6.200.0100.05321.09
5.6.190.0170.07720.80
5.6.180.0100.06320.85
5.6.170.0030.06020.80
5.6.160.0170.04720.95
5.6.150.0070.06720.90
5.6.140.0030.06020.98
5.6.130.0030.05721.05
5.6.120.0100.05720.91
5.6.110.0100.05320.80
5.6.100.0000.06321.07
5.6.90.0130.05021.06
5.6.80.0070.05320.47
5.6.70.0070.05720.27
5.6.60.0100.05320.45
5.6.50.0100.05020.23
5.6.40.0130.04720.29
5.6.30.0100.05320.46
5.6.20.0130.05020.44
5.6.10.0100.05020.40
5.6.00.0100.05020.25

preferences:
88.22 ms | 1553 KiB | 5 Q