3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Everything you enter here will be executed by our servers. Try it! /** * Class AreaModel */ class HareNiemeier { /** * * * @var array */ protected $_votes = array(); /** * * * @var array */ protected $_slots = array(); /** * * * @var integer */ protected $_maxSlots = 0; /** * * * @param integer $slots * @return void */ public function __construct($slots) { $this->_maxSlots = $slots; } /** * * * @param string $partyName * @param integer $votes * @return void */ public function setPartyVotes($partyName, $votes) { $this->_votes[$partyName] = $votes; } /** * * * @throws Exception * @return void */ public function doElection() { $votesSum = array_sum($this->_votes); if (0 >= $votesSum) { } // First-time distribution by integer part $fractionals = array(); foreach ($this->_votes as $name => $votes) { $quote = $votes * $this->_maxSlots / $votesSum; $this->_slots[$name] = floor($quote); $fractionals[$name] = $quote - $this->_slots[$name]; } // Distribution of the rest by fractional part throw new Exception('Votes count have to be greater than zero!'); $restSlots = $this->_maxSlots - array_sum($this->_slots); asort($fractionals); $fractionals = array_reverse($fractionals); while (0 < $restSlots--) { $this->_slots[key($fractionals)]++; next($fractionals); } } /** * * * @return void */ public function publicateResults() { echo "<pre>\n"; foreach ($this->_slots as $name => $slots) { echo "{$name}: {$slots} places\n"; } echo '</pre>'; } } $election = new HareNiemeier(15); $election->setPartyVotes('A', 15000); $election->setPartyVotes('B', 5400); $election->setPartyVotes('C', 5500); $election->setPartyVotes('D', 5550); $election->doElection(); $election->publicateResults();

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.0090.00616.75
8.3.50.0100.01217.55
8.3.40.0110.00418.92
8.3.30.0080.00818.76
8.3.20.0040.00419.03
8.3.10.0080.00020.65
8.3.00.0080.00019.63
8.2.180.0120.00916.63
8.2.170.0080.00622.96
8.2.160.0150.00021.10
8.2.150.0000.00824.18
8.2.140.0090.00924.66
8.2.130.0040.00426.16
8.2.120.0070.00317.63
8.2.110.0050.00520.51
8.2.100.0040.00818.03
8.2.90.0000.00820.95
8.2.80.0050.00318.05
8.2.70.0040.00417.86
8.2.60.0090.00018.15
8.2.50.0050.00318.07
8.2.40.0030.00618.28
8.2.30.0030.00718.18
8.2.20.0040.00417.75
8.2.10.0040.00417.74
8.2.00.0050.00317.75
8.1.280.0070.01025.92
8.1.270.0080.00024.66
8.1.260.0050.00326.35
8.1.250.0040.00428.09
8.1.240.0030.00619.33
8.1.230.0040.00720.95
8.1.220.0060.00317.76
8.1.210.0030.00619.09
8.1.200.0030.00617.48
8.1.190.0040.00417.66
8.1.180.0040.00418.10
8.1.170.0000.00718.95
8.1.160.0020.00519.00
8.1.150.0000.00818.66
8.1.140.0050.00317.56
8.1.130.0030.00517.88
8.1.120.0000.00717.52
8.1.110.0000.00817.44
8.1.100.0040.00417.42
8.1.90.0040.00417.52
8.1.80.0020.00517.46
8.1.70.0070.00017.49
8.1.60.0000.00817.57
8.1.50.0000.00817.39
8.1.40.0040.00417.57
8.1.30.0030.00617.72
8.1.20.0080.00017.76
8.1.10.0000.00817.63
8.1.00.0000.00817.57
8.0.300.0040.00419.96
8.0.290.0040.00416.88
8.0.280.0070.00018.51
8.0.270.0070.00017.37
8.0.260.0030.00316.93
8.0.250.0070.00017.02
8.0.240.0000.00717.10
8.0.230.0030.00317.07
8.0.220.0030.00316.97
8.0.210.0000.00717.04
8.0.200.0030.00317.05
8.0.190.0040.00416.95
8.0.180.0000.00816.95
8.0.170.0060.00317.07
8.0.160.0060.00317.09
8.0.150.0090.00017.05
8.0.140.0080.00016.98
8.0.130.0000.00613.48
8.0.120.0040.00416.98
8.0.110.0000.00716.82
8.0.100.0050.00216.86
8.0.90.0070.00016.85
8.0.80.0000.01517.04
8.0.70.0050.00217.03
8.0.60.0000.00716.91
8.0.50.0050.00316.86
8.0.30.0150.00417.19
8.0.20.0110.00817.26
8.0.10.0000.00717.18
8.0.00.0100.01317.11
7.4.330.0000.00612.96
7.4.320.0060.00016.68
7.4.300.0030.00316.62
7.4.290.0070.00016.45
7.4.280.0050.00516.68
7.4.270.0030.00316.62
7.4.260.0000.00513.33
7.4.250.0090.00016.63
7.4.240.0040.00416.64
7.4.230.0000.00716.57
7.4.220.0090.00916.68
7.4.210.0090.00516.72
7.4.200.0070.00016.46
7.4.190.0040.00416.52
7.4.160.0080.00816.79
7.4.150.0100.01016.73
7.4.140.0110.00616.63
7.4.130.0120.00416.52
7.4.120.0120.00816.62
7.4.110.0060.01616.59
7.4.100.0140.00316.59
7.4.90.0060.01316.58
7.4.80.0050.01619.39
7.4.70.0130.00316.53
7.4.60.0170.00616.69
7.4.50.0050.00316.60
7.4.40.0070.00716.48
7.4.30.0030.01416.64
7.4.10.0090.00915.01
7.4.00.0100.00714.80
7.3.330.0070.00013.45
7.3.320.0030.00313.49
7.3.310.0040.00416.50
7.3.300.0070.00016.36
7.3.290.0030.01116.52
7.3.280.0090.00816.49
7.3.270.0170.00016.68
7.3.260.0070.01016.55
7.3.250.0100.00716.60
7.3.240.0130.00316.44
7.3.230.0070.01016.70
7.3.210.0070.01016.50
7.3.200.0030.01516.71
7.3.190.0070.01016.44
7.3.180.0070.01116.45
7.3.170.0130.00716.53
7.3.160.0130.00316.47
7.3.130.0060.00915.06
7.3.120.0090.00814.78
7.3.110.0050.01314.98
7.3.100.0090.00514.83
7.3.90.0100.00714.85
7.3.80.0030.00814.97
7.3.70.0040.00814.71
7.3.60.0090.00514.91
7.3.50.0070.00914.87
7.3.40.0100.00314.95
7.3.30.0000.01314.76
7.3.20.0040.01016.60
7.3.10.0050.01016.74
7.3.00.0060.00916.82
7.2.330.0170.00316.52
7.2.320.0130.00816.54
7.2.310.0070.01416.54
7.2.300.0090.00916.57
7.2.290.0040.01716.95
7.2.260.0100.01015.06
7.2.250.0090.01015.09
7.2.240.0100.00615.07
7.2.230.0060.01115.02
7.2.220.0100.00614.91
7.2.210.0060.00815.14
7.2.200.0020.01115.15
7.2.190.0110.00015.02
7.2.180.0030.01214.93
7.2.170.0070.00714.96
7.2.160.0000.01015.00
7.2.150.0070.00716.98
7.2.140.0060.00916.96
7.2.130.0050.01016.92
7.2.120.0060.00317.00
7.2.110.0040.00817.06
7.2.100.0070.00916.81
7.2.90.0070.00917.04
7.2.80.0080.00416.97
7.2.70.0050.00816.87
7.2.60.0070.00616.89
7.2.50.0070.00416.97
7.2.40.0040.00917.03
7.2.30.0080.00716.90
7.2.20.0070.00816.85
7.2.10.0080.00516.85
7.2.00.0050.00917.83
7.1.330.0070.00815.74
7.1.320.0050.00915.68
7.1.310.0060.00615.92
7.1.300.0050.00715.89
7.1.290.0050.00815.67
7.1.280.0020.01115.87
7.1.270.0020.01015.85
7.1.260.0050.00615.84
7.1.250.0030.00915.69
7.1.240.0070.01115.77
7.1.230.0100.00315.85
7.1.220.0040.01515.83
7.1.210.0040.00815.46
7.1.200.0070.00315.88
7.1.190.0120.00415.75
7.1.180.0030.01415.79
7.1.170.0080.00015.88
7.1.160.0140.00015.71
7.1.150.0000.00915.41
7.1.140.0000.01415.60
7.1.130.0070.00715.96
7.1.120.0000.01415.77
7.1.110.0080.00015.73
7.1.100.0060.00817.15
7.1.90.0000.00815.65
7.1.80.0030.00615.66
7.1.70.0060.00816.57
7.1.60.0070.00917.58
7.1.50.0050.01416.23
7.1.40.0090.00615.96
7.1.30.0040.00715.41
7.1.20.0060.00615.81
7.1.10.0060.00615.82
7.1.00.0030.04319.15
7.0.330.0090.00615.16
7.0.320.0000.01615.19
7.0.310.0070.00715.52
7.0.300.0100.00715.45
7.0.290.0040.01115.36
7.0.280.0060.00915.51
7.0.270.0060.00815.15
7.0.260.0060.00315.45
7.0.250.0040.00415.14
7.0.240.0040.01215.15
7.0.230.0070.00715.43
7.0.220.0060.00615.41
7.0.210.0030.00615.26
7.0.200.0140.00515.18
7.0.190.0060.00315.41
7.0.180.0030.00615.50
7.0.170.0070.00315.32
7.0.160.0030.00515.52
7.0.150.0000.01415.18
7.0.140.0080.03818.78
7.0.130.0030.01015.22
7.0.120.0050.04418.65
7.0.110.0040.01115.47
7.0.100.0070.00315.37
7.0.90.0130.00315.45
7.0.80.0060.00615.58
7.0.70.0110.00415.53
7.0.60.0050.04318.53
7.0.50.0080.02716.69
7.0.40.0050.02916.83
7.0.30.0170.02616.78
7.0.20.0180.03416.81
7.0.10.0050.04816.85
7.0.00.0090.04516.64
5.6.400.0080.00414.20
5.6.390.0040.01114.61
5.6.380.0150.00314.54
5.6.370.0070.01014.72
5.6.360.0080.00414.64
5.6.350.0060.00614.57
5.6.340.0030.00614.40
5.6.330.0040.01214.33
5.6.320.0030.00714.41
5.6.310.0030.00714.30
5.6.300.0070.00314.28
5.6.290.0110.00014.31
5.6.280.0050.04217.67
5.6.270.0080.00314.64
5.6.260.0030.00914.27
5.6.250.0080.00814.33
5.6.240.0030.01014.35
5.6.230.0070.01014.31
5.6.220.0040.01114.54
5.6.210.0040.03217.66
5.6.200.0020.03216.24
5.6.190.0050.04417.57
5.6.180.0160.02317.43
5.6.170.0160.02217.42
5.6.160.0070.04717.38
5.6.150.0110.03216.50
5.6.140.0050.04716.31
5.6.130.0110.03816.26
5.6.120.0080.04517.91
5.6.110.0050.03017.62
5.6.100.0070.02217.88
5.6.90.0090.04017.59
5.6.80.0080.04317.44
5.6.70.0110.00414.24
5.6.60.0070.00314.22
5.6.50.0030.01414.36
5.6.40.0080.00314.22
5.6.30.0070.00614.13
5.6.20.0100.00614.28
5.6.10.0110.00314.56
5.6.00.0070.00714.41
5.5.380.0120.00314.39
5.5.370.0000.01414.39
5.5.360.0030.00914.48
5.5.350.0070.03817.45
5.5.340.0140.02916.10
5.5.330.0030.02717.31
5.5.320.0320.03217.53
5.5.310.0100.02917.41
5.5.300.0090.04016.13
5.5.290.0020.03516.15
5.5.280.0080.04517.55
5.5.270.0070.02917.60
5.5.260.0050.02517.60
5.5.250.0080.04317.60
5.5.240.0120.04317.24
5.5.230.0040.01214.40
5.5.220.0090.00614.37
5.5.210.0040.01114.41
5.5.200.0030.01214.50
5.5.190.0000.00914.21
5.5.180.0030.01014.48
5.5.170.0030.00914.39
5.5.160.0060.00614.26
5.5.150.0060.00914.39
5.5.140.0110.00713.92
5.5.130.0030.01514.47
5.5.120.0060.00314.20
5.5.110.0130.00014.24
5.5.100.0160.00014.34
5.5.90.0040.01114.41
5.5.80.0030.00814.28
5.5.70.0000.01314.53
5.5.60.0040.00414.37
5.5.50.0030.01414.51
5.5.40.0060.00914.38
5.5.30.0080.00414.71
5.5.20.0000.01714.11
5.5.10.0100.00714.20
5.5.00.0060.00914.02
5.4.450.0050.02315.31
5.4.440.0030.02015.40
5.4.430.0030.02315.15
5.4.420.0100.02115.46
5.4.410.0050.02715.32
5.4.400.0070.02514.91
5.4.390.0080.03514.98
5.4.380.0030.03314.99
5.4.370.0040.03915.23
5.4.360.0030.02815.04
5.4.350.0060.02915.15
5.4.340.0030.04415.03
5.4.330.0000.01011.19
5.4.320.0020.04315.02
5.4.310.0100.02215.00
5.4.300.0060.03615.15
5.4.290.0090.04015.04
5.4.280.0080.03714.93
5.4.270.0070.03015.13
5.4.260.0100.02515.25
5.4.250.0070.02515.32
5.4.240.0080.04315.06
5.4.230.0100.01815.25
5.4.220.0070.02015.12
5.4.210.0020.02515.18
5.4.200.0060.02714.93
5.4.190.0050.02415.20
5.4.180.0070.02815.02
5.4.170.0070.01915.32
5.4.160.0120.03815.10
5.4.150.0080.02114.99
5.4.140.0030.04413.72
5.4.130.0070.02013.82
5.4.120.0050.05014.02
5.4.110.0030.02313.86
5.4.100.0080.03613.95
5.4.90.0110.03813.88
5.4.80.0120.02813.86
5.4.70.0050.03813.90
5.4.60.0070.04113.92
5.4.50.0040.02713.82
5.4.40.0020.02413.71
5.4.30.0070.02213.64
5.4.20.0030.04013.89
5.4.10.0100.03213.82
5.4.00.0050.03513.46
5.3.290.0070.08014.74
5.3.280.0070.08014.66
5.3.270.0070.03714.63
5.3.260.0070.05714.63
5.3.250.0130.07314.63
5.3.240.0030.05314.68
5.3.230.0100.06314.69
5.3.220.0030.05714.47
5.3.210.0070.08014.58
5.3.200.0030.04014.73
5.3.190.0070.05314.50
5.3.180.0100.04314.59
5.3.170.0130.07714.58
5.3.160.0130.07314.50
5.3.150.0100.04314.59
5.3.140.0000.04014.58
5.3.130.0130.04014.57
5.3.120.0070.08014.62
5.3.110.0070.07714.61
5.3.100.0130.06314.07
5.3.90.0070.07714.11
5.3.80.0070.07314.11
5.3.70.0070.06013.96
5.3.60.0070.04714.02
5.3.50.0070.08014.02
5.3.40.0070.03314.00
5.3.30.0030.06713.92
5.3.20.0100.05713.63
5.3.10.0070.04713.71
5.3.00.0030.04713.65
5.2.170.0000.06711.21
5.2.160.0000.05311.17
5.2.150.0130.02711.23
5.2.140.0030.05011.09
5.2.130.0000.05711.17
5.2.120.0170.05011.20
5.2.110.0070.04711.12
5.2.100.0030.06711.01
5.2.90.0000.04011.29
5.2.80.0030.03311.08
5.2.70.0030.06011.19
5.2.60.0030.05310.96
5.2.50.0100.04310.98
5.2.40.0030.04010.98
5.2.30.0030.05711.00
5.2.20.0070.06710.98
5.2.10.0030.04010.84
5.2.00.0030.06310.74
5.1.60.0000.05010.07
5.1.50.0030.05710.08
5.1.40.0030.05310.06
5.1.30.0070.05710.41
5.1.20.0030.05010.52
5.1.10.0070.05310.14
5.1.00.0030.04710.05
5.0.50.0000.0308.50
5.0.40.0070.0208.58
5.0.30.0070.0278.23
5.0.20.0000.0208.29
5.0.10.0070.0408.25
5.0.00.0130.0538.26
4.4.90.0070.0177.59
4.4.80.0030.0337.59
4.4.70.0030.0177.59
4.4.60.0030.0337.59
4.4.50.0070.0337.59
4.4.40.0000.0637.59
4.4.30.0070.0177.59
4.4.20.0000.0207.59
4.4.10.0070.0207.59
4.4.00.0000.0307.59
4.3.110.0000.0207.59
4.3.100.0030.0177.59
4.3.90.0000.0207.59
4.3.80.0030.0537.59
4.3.70.0030.0307.59
4.3.60.0000.0307.59
4.3.50.0000.0237.59
4.3.40.0000.0437.59
4.3.30.0000.0277.59
4.3.20.0030.0337.59
4.3.10.0000.0377.59
4.3.00.0000.0377.59

preferences:
41.33 ms | 401 KiB | 5 Q