3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * 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) { throw new Exception('Votes count have to be greater than zero!'); } // 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 $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.70.0120.00916.63
8.3.60.0110.01116.49
8.3.50.0120.00422.01
8.3.40.0110.00419.02
8.3.30.0090.00619.17
8.3.20.0080.00020.29
8.3.10.0080.00023.65
8.3.00.0030.00619.32
8.2.180.0040.01416.88
8.2.170.0040.01122.96
8.2.160.0070.00720.52
8.2.150.0060.00324.18
8.2.140.0050.00324.66
8.2.130.0150.00326.16
8.2.120.0080.00022.21
8.2.110.0070.00322.26
8.2.100.0080.00417.97
8.2.90.0000.00819.17
8.2.80.0000.00818.05
8.2.70.0000.01017.63
8.2.60.0050.00517.92
8.2.50.0000.00818.07
8.2.40.0040.00418.41
8.2.30.0040.00418.07
8.2.20.0000.01117.87
8.2.10.0040.00417.69
8.2.00.0000.00717.73
8.1.280.0130.00725.92
8.1.270.0060.00323.95
8.1.260.0040.00426.35
8.1.250.0070.00028.09
8.1.240.0030.00623.79
8.1.230.0070.00419.14
8.1.220.0040.00417.74
8.1.210.0040.00418.77
8.1.200.0050.00517.35
8.1.190.0040.00417.53
8.1.180.0080.00018.10
8.1.170.0040.00418.64
8.1.160.0040.00421.99
8.1.150.0050.00318.74
8.1.140.0000.00717.51
8.1.130.0040.00417.86
8.1.120.0050.00317.55
8.1.110.0000.00717.55
8.1.100.0040.00417.42
8.1.90.0060.00317.56
8.1.80.0030.00317.41
8.1.70.0000.00717.41
8.1.60.0000.00817.55
8.1.50.0000.00717.57
8.1.40.0040.00417.49
8.1.30.0030.00517.71
8.1.20.0000.00817.72
8.1.10.0040.00417.61
8.1.00.0050.00517.62
8.0.300.0070.00018.77
8.0.290.0040.00417.29
8.0.280.0070.00018.43
8.0.270.0050.00217.38
8.0.260.0000.00716.89
8.0.250.0050.00317.07
8.0.240.0000.00816.99
8.0.230.0000.00717.05
8.0.220.0000.00716.97
8.0.210.0070.00317.02
8.0.200.0000.00717.04
8.0.190.0020.00516.89
8.0.180.0000.00716.87
8.0.170.0050.00216.91
8.0.160.0040.00416.98
8.0.150.0040.00317.03
8.0.140.0070.00016.95
8.0.130.0000.00613.41
8.0.120.0000.00816.88
8.0.110.0070.00016.80
8.0.100.0070.00016.83
8.0.90.0040.00416.81
8.0.80.0000.01516.98
8.0.70.0000.00716.96
8.0.60.0030.00516.84
8.0.50.0080.00017.02
8.0.30.0120.00717.07
8.0.20.0140.00917.40
8.0.10.0040.00417.04
8.0.00.0140.00816.79
7.4.330.0000.00515.03
7.4.320.0060.00016.66
7.4.300.0000.00616.71
7.4.290.0000.00716.67
7.4.280.0000.00716.55
7.4.270.0030.00316.58
7.4.260.0040.00516.55
7.4.250.0000.00716.49
7.4.240.0020.00516.56
7.4.230.0000.00716.45
7.4.220.0100.01016.68
7.4.210.0080.00916.68
7.4.200.0080.00016.42
7.4.190.0030.00316.63
7.4.160.0090.00916.39
7.4.150.0150.00617.40
7.4.140.0070.01117.86
7.4.130.0060.01116.61
7.4.120.0090.00916.64
7.4.110.0080.01216.39
7.4.100.0090.00916.56
7.4.90.0070.01016.40
7.4.80.0210.00319.39
7.4.70.0030.01216.54
7.4.60.0060.01016.53
7.4.50.0050.00016.43
7.4.40.0080.00422.77
7.4.30.0030.01316.78
7.4.00.0070.01015.09
7.3.330.0030.00313.44
7.3.320.0000.00513.43
7.3.310.0000.00716.33
7.3.300.0000.00716.27
7.3.290.0090.00716.45
7.3.280.0080.00916.41
7.3.270.0140.00317.40
7.3.260.0030.02016.64
7.3.250.0120.00816.71
7.3.240.0100.01416.45
7.3.230.0090.00916.54
7.3.210.0100.00716.42
7.3.200.0120.00919.39
7.3.190.0160.00316.59
7.3.180.0090.00616.66
7.3.170.0060.01016.46
7.3.160.0130.00316.43
7.3.120.0040.00814.88
7.3.00.0120.00316.22
7.2.330.0090.00916.75
7.2.320.0090.00916.96
7.2.310.0170.00616.91
7.2.300.0100.00516.77
7.2.290.0160.00016.87
7.2.130.0090.00617.01
7.2.120.0090.00616.75
7.2.110.0060.00616.94
7.2.100.0060.01017.00
7.2.90.0030.01316.87
7.2.80.0080.00417.07
7.2.70.0060.00917.02
7.2.60.0070.00916.88
7.2.50.0090.00616.85
7.2.40.0120.00617.07
7.2.30.0110.00416.90
7.2.20.0070.01016.99
7.2.10.0100.00616.91
7.2.00.0040.00917.99
7.1.250.0060.00815.63
7.1.240.0100.00315.66
7.1.230.0070.01015.71
7.1.220.0050.00515.55
7.1.210.0040.01115.44
7.1.200.0060.00615.53
7.1.190.0100.00315.88
7.1.180.0090.00315.94
7.1.170.0120.00415.47
7.1.160.0120.00315.61
7.1.150.0130.00315.94
7.1.140.0110.00315.87
7.1.130.0080.00815.66
7.1.120.0120.00315.64
7.1.110.0090.00615.93
7.1.100.0050.00817.22
7.1.90.0040.01115.94
7.1.80.0120.00615.78
7.1.70.0110.00216.42
7.1.60.0120.00717.44
7.1.50.0080.00816.39
7.1.40.0100.00315.86
7.1.30.0080.00815.68
7.1.20.0110.00015.78
7.1.10.0070.00715.70
7.1.00.0040.04419.10
7.0.330.0130.00315.08
7.0.320.0080.00415.09
7.0.310.0100.00315.42
7.0.300.0140.00015.43
7.0.290.0080.00815.34
7.0.280.0090.00615.41
7.0.270.0060.00915.37
7.0.260.0090.00615.14
7.0.250.0130.00015.53
7.0.240.0160.00015.24
7.0.230.0160.00015.54
7.0.220.0100.00315.46
7.0.210.0120.00315.19
7.0.200.0080.00416.06
7.0.190.0100.00315.43
7.0.180.0130.00015.24
7.0.170.0050.00515.18
7.0.160.0070.00715.56
7.0.150.0080.00815.29
7.0.140.0060.04018.66
7.0.130.0070.01015.52
7.0.120.0070.01015.49
7.0.110.0120.00415.41
7.0.100.0070.04117.52
7.0.90.0060.03517.49
7.0.80.0050.03217.59
7.0.70.0070.04317.53
7.0.60.0200.04517.69
7.0.50.0090.02217.80
7.0.40.0070.03116.66
7.0.30.0070.04616.64
7.0.20.0050.04616.64
7.0.10.0080.03316.73
7.0.00.0050.04916.70
5.6.380.0030.00714.25
5.6.370.0070.01014.44
5.6.360.0070.00614.36
5.6.350.0120.00214.19
5.6.340.0090.00914.80
5.6.330.0080.00814.18
5.6.320.0050.01014.50
5.6.310.0080.00814.51
5.6.300.0060.01214.26
5.6.290.0030.01314.31
5.6.280.0100.03617.59
5.6.270.0060.00614.80
5.6.260.0090.00614.70
5.6.250.0130.03817.20
5.6.240.0140.02217.58
5.6.230.0020.05317.29
5.6.220.0100.02317.42
5.6.210.0070.04417.29
5.6.200.0120.02717.76
5.6.190.0200.02917.74
5.6.180.0110.03217.60
5.6.170.0140.04417.76
5.6.160.0100.04317.84
5.6.150.0180.03717.72
5.6.140.0080.02917.81
5.6.130.0070.04417.79
5.6.120.0170.04117.78
5.6.110.0110.02817.71
5.6.100.0140.03317.69
5.6.90.0090.04617.80
5.6.80.0120.04117.43
5.6.70.0050.03017.24
5.6.60.0080.04517.34
5.6.50.0100.04317.41
5.6.40.0080.04617.44
5.6.30.0110.04117.39
5.6.20.0100.02817.28
5.6.10.0050.02417.38
5.6.00.0030.03317.26
5.5.380.0030.03015.74
5.5.370.0100.03815.84
5.5.360.0110.04015.79
5.5.350.0050.04515.67
5.5.340.0030.04715.90
5.5.330.0130.04116.01
5.5.320.0100.03016.06
5.5.310.0140.04116.01
5.5.300.0020.03216.25
5.5.290.0100.04115.98
5.5.280.0100.04316.01
5.5.270.0070.04516.03
5.5.260.0130.03416.19
5.5.250.0120.01816.08
5.5.240.0170.03315.77
5.5.230.0070.04115.73
5.5.220.0130.03815.74
5.5.210.0090.04215.68
5.5.200.0110.04015.75
5.5.190.0120.03815.79
5.5.180.0060.03615.76
5.5.170.0060.00611.09
5.5.160.0050.02915.57
5.5.150.0030.04015.70
5.5.140.0070.04315.65
5.5.130.0070.05015.67
5.5.120.0080.03315.60
5.5.110.0070.03915.73
5.5.100.0080.03915.57
5.5.90.0070.04315.62
5.5.80.0060.02215.63
5.5.70.0050.02415.51
5.5.60.0040.02515.74
5.5.50.0080.03715.65
5.5.40.0050.02115.41
5.5.30.0020.04315.68
5.5.20.0050.03515.71
5.5.10.0080.04015.54
5.5.00.0110.04015.59
5.4.450.0110.03015.33
5.4.440.0060.04115.37
5.4.430.0080.03215.17
5.4.420.0030.03115.19
5.4.410.0080.04315.25
5.4.400.0080.03514.88
5.4.390.0050.02715.10
5.4.380.0100.03215.12
5.4.370.0030.04315.11
5.4.360.0050.04215.16
5.4.350.0040.04114.96
5.4.340.0070.03915.02
5.4.330.0050.00310.82
5.4.320.0080.03915.13
5.4.310.0100.03814.97
5.4.300.0070.03014.99
5.4.290.0030.04015.12
5.4.280.0110.03615.00
5.4.270.0090.03715.21
5.4.260.0030.04215.08
5.4.250.0100.03315.11
5.4.240.0100.04015.02
5.4.230.0030.02715.02
5.4.220.0070.02515.21
5.4.210.0070.02515.05
5.4.200.0080.02715.00
5.4.190.0080.03515.04
5.4.180.0070.03815.14
5.4.170.0030.03314.81
5.4.160.0000.04615.08
5.4.150.0060.03914.94
5.4.140.0050.03813.68
5.4.130.0030.03913.72
5.4.120.0050.02513.65
5.4.110.0110.03513.78
5.4.100.0050.03913.81
5.4.90.0070.03313.77
5.4.80.0110.03513.86
5.4.70.0080.03313.85
5.4.60.0060.04013.74
5.4.50.0030.03913.73
5.4.40.0020.02713.77
5.4.30.0080.03713.65
5.4.20.0020.04413.79
5.4.10.0050.03513.80
5.4.00.0090.03713.54
5.3.290.0060.04012.73
5.3.280.0000.03812.62
5.3.270.0050.04012.60
5.3.260.0070.03812.58
5.3.250.0080.03312.55
5.3.240.0030.04212.64
5.3.230.0050.03312.60
5.3.220.0030.04312.60
5.3.210.0080.04112.50
5.3.200.0030.04112.51
5.3.190.0050.03812.65
5.3.180.0070.03012.76
5.3.170.0000.03312.68
5.3.160.0080.03512.67
5.3.150.0080.03712.66
5.3.140.0080.03612.68
5.3.130.0070.03812.61
5.3.120.0050.03712.64
5.3.110.0030.03012.57
5.3.100.0060.03012.22
5.3.90.0030.03512.38
5.3.80.0060.04312.17
5.3.70.0060.03812.25
5.3.60.0090.03012.33
5.3.50.0040.04212.36
5.3.40.0080.03812.32
5.3.30.0070.03812.30
5.3.20.0050.02512.11
5.3.10.0070.02512.06
5.3.00.0080.03612.00
5.2.170.0120.02711.15
5.2.160.0030.03411.15
5.2.150.0020.03311.15
5.2.140.0050.03411.15
5.2.130.0030.03111.15
5.2.120.0100.01911.15
5.2.110.0030.02511.15
5.2.100.0080.02611.15
5.2.90.0000.02611.15
5.2.80.0020.03011.15
5.2.70.0030.03311.15
5.2.60.0030.02811.15
5.2.50.0030.03311.15
5.2.40.0050.02811.15
5.2.30.0030.02511.15
5.2.20.0040.02711.15
5.2.10.0040.03211.15
5.2.00.0030.02811.15
5.1.60.0030.02811.15
5.1.50.0080.02011.15
5.1.40.0030.02811.15
5.1.30.0070.02511.15
5.1.20.0030.02311.15
5.1.10.0020.03111.15
5.1.00.0030.02911.15
5.0.50.0030.02611.15
5.0.40.0060.02111.15
5.0.30.0030.02611.15
5.0.20.0000.02411.15
5.0.10.0050.02111.15
5.0.00.0070.02811.15
4.4.90.0030.01811.15
4.4.80.0050.01311.15
4.4.70.0010.02111.15
4.4.60.0000.01911.15
4.4.50.0030.01511.15
4.4.40.0020.02011.15
4.4.30.0030.01811.15
4.4.20.0010.01311.15
4.4.10.0020.02011.15
4.4.00.0020.02311.15
4.3.110.0060.01411.15
4.3.100.0020.01911.15
4.3.90.0040.01811.15
4.3.80.0020.02511.15
4.3.70.0000.01711.15
4.3.60.0040.01011.15
4.3.50.0040.01711.15
4.3.40.0030.02711.15
4.3.30.0050.01711.15
4.3.20.0000.02011.15
4.3.10.0030.01811.15
4.3.00.0020.01111.15

preferences:
66.24 ms | 401 KiB | 5 Q