3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getRandom($values, $weights) { $count = count($values); $i = 0; $n = 0; $num = mt_rand(0, array_sum($weights) * 100) / 100; while($i < $count) { $n += $weights[$i]; if($n >= $num) break; $i++; } return $values[$i]; } $values = [1,2,3,4]; $weights = [60.0000,30.0000,9.9800,.0200]; $counts = array_combine($values, array_fill(0, count($values), 0)); for ($i = 0; $i < 100000; $i++) { $counts[getRandom($values, $weights)]++; } echo "value\tweight\tcount\t%\n"; for ($i = 0; $i < count($values); $i++) { echo $values[$i] . "\t" . $weights[$i] . "\t" . $counts[$values[$i]] . "\t" . round($counts[$values[$i]]/array_sum($counts)*100, 2) . "\n"; }

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.90.0140.03326.77
8.2.30.0000.02618.95
8.2.20.0070.02018.86
8.2.10.0080.02118.47
8.2.00.0130.02118.37
8.1.160.0000.02818.58
8.1.150.0180.01418.71
8.1.140.0070.02318.18
8.1.130.0130.01718.07
8.1.120.0080.02318.09
8.1.110.0090.02318.09
8.1.100.0170.01518.06
8.1.90.0090.02318.09
8.1.80.0120.02018.19
8.1.70.0100.02018.11
8.1.60.0130.02018.33
8.1.50.0130.02018.17
8.1.40.0170.01418.20
8.1.30.0130.02218.29
8.1.20.0130.02018.30
8.1.10.0180.01518.15
8.1.00.0120.02218.15
8.0.280.0140.01418.07
8.0.270.0110.01917.42
8.0.260.0110.01917.44
8.0.250.0100.02017.51
8.0.240.0120.01817.52
8.0.230.0070.02517.47
8.0.220.0170.01517.36
8.0.210.0120.01817.45
8.0.200.0080.02017.11
8.0.190.0120.01917.48
8.0.180.0140.01717.50
8.0.170.0120.01917.38
8.0.160.0110.02017.52
8.0.150.0110.02017.32
8.0.140.0120.02017.49
8.0.130.0110.02017.41
8.0.120.0090.02217.43
8.0.110.0120.01817.40
8.0.100.0050.02117.22
8.0.90.0080.02017.27
8.0.80.0070.02217.25
8.0.70.0090.01917.22
8.0.60.0060.02117.23
8.0.50.0090.01817.32
8.0.30.0070.01917.75
8.0.20.0050.02117.31
8.0.10.0030.02317.97
8.0.00.0100.01818.11
7.4.330.0100.01916.43
7.4.320.0140.01817.17
7.4.300.0050.02817.15
7.4.290.0130.01917.06
7.4.280.0110.02217.09
7.4.270.0060.02717.06
7.4.260.0130.02317.08
7.4.250.0120.02117.10
7.4.240.0080.02417.16
7.4.230.0080.02216.90
7.4.220.0070.02116.92
7.4.210.0020.02717.01
7.4.200.0060.02216.99
7.4.190.0070.02117.03
7.4.180.0090.01916.91
7.4.160.0070.02217.03
7.4.150.0070.02216.90
7.4.140.0080.02216.81
7.4.130.0050.02516.93
7.4.120.0090.02016.80
7.4.110.0060.02316.92
7.4.100.0080.02216.94
7.4.90.0080.02216.85
7.4.80.0070.02216.84
7.4.70.0100.01916.82
7.4.60.0040.02516.85
7.4.50.0090.01916.77
7.4.40.0070.02316.82
7.4.30.0050.02416.86
7.4.20.0090.01916.89
7.4.10.0090.02016.88
7.4.00.0070.02716.36
7.3.330.0100.02216.92
7.3.320.0110.02116.79
7.3.310.0030.02816.79
7.3.300.0090.02016.75
7.3.290.0090.02116.62
7.3.280.0070.02416.66
7.3.270.0060.02716.75
7.3.260.0060.02516.63
7.3.250.0080.02316.75
7.3.240.0070.02316.70
7.3.230.0080.02216.68
7.3.220.0060.02516.59
7.3.210.0090.02216.54
7.3.200.0100.02016.69
7.3.190.0080.02216.64
7.3.180.0070.02316.68
7.3.170.0070.02416.56
7.3.160.0120.01716.69
7.3.150.0030.02716.73
7.3.140.0100.02016.60
7.3.130.0070.02416.64
7.3.120.0070.03316.23
7.3.110.0100.03116.20
7.3.100.0070.02916.20
7.3.90.0080.03016.03
7.3.80.0100.02715.89
7.3.70.0090.02615.85
7.3.60.0060.03015.95
7.3.50.0050.03516.03
7.3.40.0070.03016.00
7.3.30.0080.03315.91
7.3.20.0090.03117.86
7.3.10.0040.03817.85
7.3.00.0100.03217.79
7.2.340.0090.02116.88
7.2.330.0090.02216.84
7.2.320.0080.02416.77
7.2.310.0080.02416.84
7.2.300.0090.02416.79
7.2.290.0080.02516.80
7.2.280.0080.02316.74
7.2.270.0080.02316.74
7.2.260.0100.02116.75
7.2.250.0050.03716.34
7.2.240.0080.03416.32
7.2.230.0050.03016.41
7.2.220.0070.03116.11
7.2.210.0070.03016.14
7.2.200.0100.02916.27
7.2.190.0050.03516.17
7.2.180.0080.03216.23
7.2.170.0070.03216.25
7.2.160.0090.03316.53
7.2.150.0090.02618.34
7.2.140.0110.02818.31
7.2.130.0100.03318.35
7.2.120.0090.03018.35
7.2.110.0090.03218.36
7.2.100.0080.03518.29
7.2.90.0070.03318.28
7.2.80.0090.03218.29
7.2.70.0070.02618.37
7.2.60.0100.03218.33
7.2.50.0080.03318.44
7.2.40.0040.03418.37
7.2.30.0120.03018.26
7.2.20.0100.03018.40
7.2.10.0100.03318.42
7.2.00.0120.03018.44
7.1.330.0070.04017.30
7.1.320.0100.04216.90
7.1.310.0090.04216.88
7.1.300.0070.04516.88
7.1.290.0060.04816.93
7.1.280.0060.04516.97
7.1.270.0070.05016.95
7.1.260.0060.05216.97
7.1.250.0100.04117.21
7.1.240.0090.02817.54
7.1.230.0080.02917.72
7.1.220.0070.03117.64
7.1.210.0060.03017.71
7.1.200.0100.02817.63
7.1.190.0060.03317.63
7.1.180.0050.03217.75
7.1.170.0080.03117.61
7.1.160.0060.03217.62
7.1.150.0060.03117.63
7.1.140.0050.03217.68
7.1.130.0050.03417.66
7.1.120.0080.02917.62
7.1.110.0060.03217.63
7.1.100.0050.03317.67
7.1.90.0060.03117.56
7.1.80.0070.03017.64
7.1.70.0050.03417.46
7.1.60.0070.03217.71
7.1.50.0110.02717.73
7.1.40.0100.02917.68
7.1.30.0090.03017.76
7.1.20.0070.03317.61
7.1.10.0080.03017.65
7.1.00.0080.03017.62

preferences:
57.57 ms | 403 KiB | 5 Q