3v4l.org

run code in 300+ PHP versions simultaneously
<?php $test1 = [ "blah1", "blah1", "blah2", "blah4", "blah5" ]; $test2 = [ "blah1", // under-represented "blah2", // equally found "blah3", // not found "blah4", // over-represented "blah4", // " ]; function removeBValuesFromA(array $a, array $b): array { foreach ($b as $bVal) { $k = array_search($bVal, $a); if ($k !== false) { unset($a[$k]); } } return array_values($a); } function bidirectionalDiff(array $a, array $b): array { foreach ($b as $bKey => $bVal) { $aKey = array_search($bVal, $a); if ($aKey !== false) { unset($a[$aKey], $b[$bKey]); } } return array_merge($a, $b); } function removeBValuesFromAViaCounts(array $a, array $b): array { $toRemove = array_count_values($b); $result = []; foreach (array_count_values($a) as $k => $count) { array_push( $result, ...array_fill( 0, max(0, $count - ($toRemove[$k] ?? 0)), $k ) ); } return $result; } function bidirectionalDiffViaCounts(array $a, array $b): array { $bCounts = array_count_values($b); $result = []; foreach (array_count_values($a) as $k => $count) { array_push( $result, ...array_fill( 0, abs($count - ($bCounts[$k] ?? 0)), $k ) ); unset($bCounts[$k]); } foreach ($bCounts as $k => $count) { array_push( $result, ...array_fill(0, $count, $k) ); } return $result; } var_export([ 'removeBValuesFromA' => removeBValuesFromA($test1, $test2), 'bidirectionalDiff' => bidirectionalDiff($test1, $test2), 'removeBValuesFromAViaCounts' => removeBValuesFromAViaCounts($test1, $test2), 'bidirectionalDiffViaCounts' => bidirectionalDiffViaCounts($test1, $test2), ]);

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.00.0140.00720.03
8.4.150.0020.00014.05
8.4.140.0100.01117.65
8.4.130.0090.01118.89
8.4.120.0120.00724.22
8.4.110.0150.00522.32
8.4.100.0080.01017.64
8.4.90.0120.00920.59
8.4.80.0090.00918.89
8.4.70.0070.00920.61
8.4.60.0100.00720.77
8.4.50.0140.00618.66
8.4.40.0060.01317.52
8.4.30.0040.01122.17
8.4.20.0130.00717.91
8.4.10.0030.00619.39
8.3.280.0130.00718.18
8.3.270.0100.01016.59
8.3.260.0100.00916.56
8.3.250.0110.00818.86
8.3.240.0080.01117.20
8.3.230.0070.00416.72
8.3.220.0060.00218.85
8.3.210.0120.00816.65
8.3.200.0070.00216.76
8.3.190.0040.00417.08
8.3.180.0150.00416.38
8.3.170.0100.01017.16
8.3.160.0000.01818.34
8.3.150.0030.01319.04
8.3.140.0040.00416.54
8.3.130.0040.00416.49
8.3.120.0120.00419.30
8.3.110.0050.00520.94
8.3.100.0080.00018.44
8.3.90.0080.00026.77
8.3.80.0060.00317.97
8.3.70.0190.00316.63
8.3.60.0100.01016.50
8.3.50.0110.00716.68
8.3.40.0100.01021.72
8.3.30.0140.00018.98
8.3.20.0030.00624.18
8.3.10.0050.00224.66
8.3.00.0120.00521.87
8.2.290.0140.00520.21
8.2.280.0120.00818.48
8.2.270.0090.00917.29
8.2.260.0140.00319.23
8.2.250.0040.00418.57
8.2.240.0100.00618.80
8.2.230.0060.00322.58
8.2.220.0160.00024.06
8.2.210.0080.00426.77
8.2.200.0040.00718.17
8.2.190.0070.00716.70
8.2.180.0200.00016.50
8.2.170.0040.01119.13
8.2.160.0100.00322.96
8.2.150.0070.00025.66
8.2.140.0080.00024.66
8.2.130.0050.00326.16
8.2.120.0030.00619.54
8.2.110.0030.00722.08
8.2.100.0270.00317.66
8.2.90.0220.00917.57
8.2.80.0300.00017.62
8.2.70.0250.00317.57
8.2.60.0260.00617.57
8.2.50.0260.00417.57
8.2.40.0260.00317.57
8.2.30.0240.00317.57
8.2.20.0300.00017.75
8.2.10.0200.00817.63
8.2.00.0210.00717.57
8.1.330.0100.00820.29
8.1.320.0090.01116.42
8.1.310.0070.00716.67
8.1.300.0160.00315.91
8.1.290.0090.00030.84
8.1.280.0090.00625.92
8.1.270.0030.00624.66
8.1.260.0070.00726.35
8.1.250.0050.00328.09
8.1.240.0100.00022.52
8.1.230.0100.00320.97
8.1.220.0250.00817.57
8.1.210.0300.00317.57
8.1.200.0200.01117.57
8.1.190.0260.00817.57
8.1.180.0260.00417.57
8.1.170.0240.00317.57
8.1.160.0190.00617.57
8.1.150.0160.01217.57
8.1.140.0180.01017.57
8.1.130.0250.00317.57
8.1.120.0220.00517.57
8.1.110.0270.00017.57
8.1.100.0270.00017.57
8.1.90.0180.00917.57
8.1.80.0290.00017.57
8.1.70.0180.00917.57
8.1.60.0210.00717.57
8.1.50.0210.00917.57
8.1.40.0140.01417.63
8.1.30.0160.01217.57
8.1.20.0260.00417.57
8.1.10.0250.00417.57
8.1.00.0270.00517.57
8.0.300.0220.00617.57
8.0.290.0210.00717.57
8.0.280.0200.00717.57
8.0.270.0240.00417.57
8.0.260.0230.00517.57
8.0.250.0220.00617.57
8.0.240.0260.00417.57
8.0.230.0150.01217.57
8.0.220.0240.00817.57
8.0.210.0250.00617.57
8.0.200.0310.00017.57
8.0.190.0200.01017.57
8.0.180.0290.00317.57
8.0.170.0220.00817.57
8.0.160.0230.00517.57
8.0.150.0240.00317.57
8.0.140.0210.00617.57
8.0.130.0240.00417.57
8.0.120.0160.01317.57
8.0.110.0160.01017.57
8.0.100.0230.00317.57
8.0.90.0240.00517.57
8.0.80.0230.00717.57
8.0.70.0280.00317.57
8.0.60.0270.00417.57
8.0.50.0260.00617.57
8.0.30.0270.00317.57
8.0.20.0260.00317.57
8.0.10.0210.01017.57

preferences:
37.5 ms | 403 KiB | 5 Q