3v4l.org

run code in 300+ PHP versions simultaneously
<?php $runs = 1000; $agree = array('count' => 0, 'To Mom' => 0, 'To Dad' => 0, 'Joint' => 0); $disagree = array('count' => 0, 'Sole Fight' => 0, 'FsMj' => 0, 'MsFj' => 0, 'MfFm' => 0, 'other' => 0); $dadSole = 0; $momSole = 0; $fChk = array('f' => 0, 'm' => 0, 'j' => 0); $mChk = array('f' => 0, 'm' => 0, 'j' => 0, 'o' => 0); for ($i=0; $i < $runs ; $i++) { $mPref = rand(1,100); $fPref = rand(1,100); #### checking random chooser #### switch(fChoice($fPref)){ case 'f': $fChk['f']++; break; case 'm': $fChk['m']++; break; case 'joint': $fChk['j']++; break; } switch(mChoice($mPref)){ case 'f': $mChk['f']++; break; case 'm': $mChk['m']++; break; case 'joint': $mChk['j']++; break; case 'other': $mChk['o']++; break; } #### ####### ####### ####### #### if(fChoice($fPref) == mChoice($mPref) ) { // if in agreement $agree['count']++; // increment counter switch (fChoice($fPref)) { // increment specific choice agreed upon case 'f': $agree['To Mom']++; break; case 'm': $agree['To Dad']++; break; case 'joint': $agree['Joint']++; break; } } else { // calculate stats for disagreements if(mChoice($mPref) == 'other') { continue; } // toss out Dad wants other cases $disagree['count']++; if(fChoice($fPref) == 'f') { // mom wants sole $momSole++; } if(mChoice($mPref) == 'm'){ // dad wants sole $dadSole++; } if(fChoice($fPref) == 'f' && mChoice($mPref) == 'm') { // both want sole $disagree['Sole Fight']++; } elseif(fChoice($fPref) == 'f' && mChoice($mPref) == 'joint') { // Mom Sole - Dad Joint $disagree['FsMj']++; } elseif(fChoice($fPref) == 'joint' && mChoice($mPref) == 'm') { // Mom Joint - Dad Sole $disagree['MsFj']++; } elseif(fChoice($fPref) == 'm' && mChoice($mPref) == 'f') { // hot potato $disagree['MfFm']++; } else { $disagree['other']++; // echo 'Dad wants '.mChoice($mPref).' and Mom wants '.fChoice($fPref).'<br>'; } } } $sigDigits = 2; $percentAgree = $agree['count'] / $runs * 100; $percentDisagree = $disagree['count'] / $runs * 100; $agreeMom = round($agree['To Mom'] / $agree['count'] * 100, $sigDigits); $agreeDad = round($agree['To Dad'] / $agree['count'] * 100, $sigDigits); $agreeJnt = round($agree['Joint'] / $agree['count'] * 100, $sigDigits); $disagreeSole = round($disagree['Sole Fight'] / $disagree['count'] * 100, $sigDigits); $disagreeFsMj = round($disagree['FsMj'] / $disagree['count'] * 100, $sigDigits); $disagreeMsFj = round($disagree['MsFj'] / $disagree['count'] * 100, $sigDigits); $disagreeNone = round($disagree['MfFm'] / $disagree['count'] * 100, $sigDigits); $disagreeOther = round($disagree['other'] / $disagree['count'] * 100, $sigDigits); $dadPercent = round($dadSole / $disagree['count'] * 100, $sigDigits); $momPercent = round($momSole / $disagree['count'] * 100, $sigDigits); // 'Sole Fight' => 0, 'FsMj' => 0, 'MsFj' => 0, 'other' => 0 echo "From {$runs} runs there were {$percentAgree}% agreements and {$percentDisagree}% disagreements."; echo "From the agreements <ul> <li>{$agreeMom}% go to Mom</li> <li>{$agreeDad}% go to Dad</li> <li>{$agreeJnt}% joint custody</li> </ul>"; echo "From the disagreements <ul> <li> {$momPercent}% of Mom's want sole custody</li> <li> {$dadPercent}% of Dad's want sole custody</li> <br><br> <li>{$disagreeSole}% both want Sole Custody</li> <li>{$disagreeFsMj}% of cases: Mom wants Sole; Dad joint</li> <li>{$disagreeMsFj}% of cases: Dad wants Sole; Mom joint</li> <li>{$disagreeNone}% of cases: Hot Potato the Kids!</li> <li>{$disagreeOther}% are in another configuration of disagreement</li> </ul>"; foreach ($fChk as &$optionCount) { $optionCount = round($optionCount / $runs * 100, $sigDigits); } foreach ($mChk as &$optionCount) { $optionCount = round($optionCount / $runs * 100, $sigDigits); } echo "<br><br>"; print_r($fChk); echo "<br><br>"; print_r($mChk); function fChoice ($num) { if($num <= 82) { return 'f'; } if($num <= 85) { return 'm'; } else { return 'joint'; } } function mChoice ($num) { if($num <= 29) { return 'f'; } if($num <= 62) { return 'm'; } if ($num <= 97) { return 'joint'; } else { return 'other'; } }

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)
7.2.00.0060.00319.54
7.1.70.0000.00916.89
7.1.60.0070.02019.33
7.1.50.0060.00916.91
7.1.00.0000.08322.48
7.0.200.0230.00915.18
7.0.140.0070.07022.09
7.0.100.0130.03720.03
7.0.90.0070.06720.09
7.0.80.0070.07720.09
7.0.70.0170.05720.06
7.0.60.0170.07720.07
7.0.50.0030.04720.46
7.0.40.0100.04720.14
7.0.30.0130.08020.04
7.0.20.0070.09020.14
7.0.10.0070.07019.95
7.0.00.0070.06320.07
5.6.280.0070.09320.96
5.6.250.0100.08020.78
5.6.240.0130.07720.81
5.6.230.0100.09320.77
5.6.220.0070.07020.63
5.6.210.0000.08720.79
5.6.200.0130.09021.09
5.6.190.0170.07321.23
5.6.180.0100.08321.12
5.6.170.0170.07321.06
5.6.160.0030.07021.07
5.6.150.0070.06721.22
5.6.140.0170.07721.11
5.6.130.0200.07321.14
5.6.120.0100.07721.11
5.6.110.0100.05721.17
5.6.100.0030.09020.98
5.6.90.0030.08721.14
5.6.80.0070.08320.46
5.6.70.0130.08320.57
5.6.60.0070.08020.56
5.6.50.0070.08320.46
5.6.40.0100.07320.46
5.6.30.0100.07720.55
5.6.20.0100.05020.54
5.6.10.0070.08320.41
5.6.00.0000.09020.47
5.5.380.0170.09020.45
5.5.370.0200.07320.45
5.5.360.0070.09020.59
5.5.350.0100.08020.42
5.5.340.0170.06320.85
5.5.330.0100.07720.86
5.5.320.0070.07320.93
5.5.310.0100.07720.81
5.5.300.0130.08020.95
5.5.290.0100.05320.94
5.5.280.0070.06720.86
5.5.270.0130.05320.98
5.5.260.0130.05320.86
5.5.250.0100.07720.61
5.5.240.0030.06020.24
5.5.230.0070.08720.32
5.5.220.0070.08020.34
5.5.210.0100.06020.32
5.5.200.0070.07720.33
5.5.190.0100.09020.23
5.5.180.0070.07020.14
5.5.160.0030.07020.27
5.5.150.0070.08320.16
5.5.140.0100.07720.27
5.5.130.0230.07320.21
5.5.120.0100.06720.21
5.5.110.0100.08320.29
5.5.100.0170.07020.07
5.5.90.0100.04320.18
5.5.80.0030.08320.12
5.5.70.0070.05320.12
5.5.60.0070.08020.16
5.5.50.0200.08320.11
5.5.40.0070.08020.17
5.5.30.0100.07719.98
5.5.20.0070.08720.11
5.5.10.0100.07320.07
5.5.00.0130.07020.11
5.4.450.0200.07019.24
5.4.440.0030.05319.24
5.4.430.0070.08319.50
5.4.420.0070.06019.54
5.4.410.0070.07319.13
5.4.400.0100.07319.25
5.4.390.0030.08319.14
5.4.380.0000.07719.22
5.4.370.0070.08018.99
5.4.360.0100.07719.04
5.4.350.0070.08318.94
5.4.340.0070.07719.21
5.4.320.0070.08319.03
5.4.310.0130.04319.30
5.4.300.0070.08019.09
5.4.290.0030.09319.04
5.4.280.0130.07018.93
5.4.270.0070.07719.22
5.4.260.0070.08319.22
5.4.250.0030.06719.03
5.4.240.0070.08319.08
5.4.230.0030.08319.29
5.4.220.0100.08319.21
5.4.210.0000.07719.20
5.4.200.0130.04719.03
5.4.190.0030.06319.10
5.4.180.0000.08719.05
5.4.170.0030.08019.19
5.4.160.0100.07718.92
5.4.150.0070.05718.92
5.4.140.0130.06316.48
5.4.130.0130.06716.52
5.4.120.0030.07016.44
5.4.110.0000.04716.38
5.4.100.0070.06316.54
5.4.90.0130.04316.39
5.4.80.0100.04716.30
5.4.70.0030.04016.30
5.4.60.0070.04316.54
5.4.50.0100.03316.43
5.4.40.0030.08316.42
5.4.30.0100.07716.29
5.4.20.0170.06016.35
5.4.10.0000.05016.43
5.4.00.0070.07315.76
5.3.290.0070.07714.71
5.3.280.0070.07714.77
5.3.270.0030.09014.67
5.3.260.0170.07714.68
5.3.250.0070.07314.75
5.3.240.0130.05314.75
5.3.230.0030.06314.79
5.3.220.0030.05314.67
5.3.210.0100.04714.75
5.3.200.0100.06314.75
5.3.190.0030.08014.74
5.3.180.0130.07014.71
5.3.170.0030.08314.73
5.3.160.0070.04714.61
5.3.150.0030.04014.73
5.3.140.0230.05014.73
5.3.130.0070.07014.59
5.3.120.0170.04014.63
5.3.110.0100.06714.73
5.3.100.0170.04714.22
5.3.90.0130.04014.20
5.3.80.0000.06014.19
5.3.70.0030.07714.18
5.3.60.0100.06714.17
5.3.50.0030.04013.92
5.3.40.0070.03714.00
5.3.30.0000.04013.91
5.3.20.0070.03713.68
5.3.10.0070.03313.72
5.3.00.0030.04313.71

preferences:
38.1 ms | 400 KiB | 5 Q