3v4l.org

run code in 300+ PHP versions simultaneously
<?php function consistsOfTheSameValues(array $A, array $B, $strict = false, $assumeEqual = false) { // check size of both arrays if (count($A) !== count($B)) { return false; } // optional pre-test that increases performance for most unequal arrays, but is worse for equal arrays if (! $assumeEqual) { foreach ($A as $a) { // check that expected value exists in the array if (! in_array($a, $B, $strict)) { return false; } } } foreach ($A as $a) { // check that expected value occurs the same amount of times in both arrays if (count(array_keys($A, $a, $strict)) !== count(array_keys($B, $a, $strict))) { return false; } } return true; } // A unit testing framework in a tweet. https://gist.github.com/mathiasverraes/9046427 function it($m,$p){echo ($p?'✔︎':'✘')." It $m\n"; if(!$p){$GLOBALS['f']=1;}}function done(){if(@$GLOBALS['f'])die(1);} // create two big arrays $big1 = []; for ($i = 0; $i < 999; $i++) { $big1[] = rand(); } $big2 = $big1; $big1[] = 0; $big2[] = 1; foreach ([false, true] as $ae) { foreach ([true, false] as $st) { echo '### ' . ($st ? 'strict (===)' : 'loose (==)' ) . ' - ' . ($ae ? 'skip' : 'use') . " in_array\n"; // positive tests it('consists of the same values', consistsOfTheSameValues([1], [1], $st, $ae) === true ); it('consists of the same values', consistsOfTheSameValues([1, 1], [1, 1], $st, $ae) === true ); it('consists of the same values', consistsOfTheSameValues(['1', 1], ['1', 1], $st, $ae) === true ); it('consists of the same values', consistsOfTheSameValues(['1', 1], [1, '1'], $st, $ae) === true ); it('consists of the same values', consistsOfTheSameValues([1, '1'], ['1', 1], $st, $ae) === true ); it('consists of the same values', consistsOfTheSameValues([1, '1'], [1, '1'], $st, $ae) === true ); it('consists of the same values with key', consistsOfTheSameValues(['x' => 1], ['x' => 1], $st, $ae) === true ); it('consists of the same values with key', consistsOfTheSameValues(['x' => 1], ['y' => 1], $st, $ae) === true ); it('consists of the same values with key', consistsOfTheSameValues(['y' => 1], ['x' => 1], $st, $ae) === true ); it('consists of the same values with key', consistsOfTheSameValues(['x' => 1, 'y' => 1], ['x' => 1, 'y' => 1], $st, $ae) === true ); it('consists of the same values with key', consistsOfTheSameValues(['y' => 1, 'x' => 1], ['x' => 1, 'y' => 1], $st, $ae) === true ); it('consists of the same values with key', consistsOfTheSameValues(['x' => 1, 'y' => 1], ['y' => 1, 'x' => 1], $st, $ae) === true ); it('consists of the same values with key', consistsOfTheSameValues(['y' => 1, 'x' => 1], ['y' => 1, 'x' => 1], $st, $ae) === true ); it('consists of the same values with key', consistsOfTheSameValues(['x' => 2, 'y' => 1], ['x' => 1, 'y' => 2], $st, $ae) === true ); it('consists of the same values for big1 and big1', consistsOfTheSameValues($big1, $big1, $st, $ae) === true ); it('consists of the same values for big2 and big2', consistsOfTheSameValues($big2, $big2, $st, $ae) === true ); // negative tests it('does not consist of the same values', consistsOfTheSameValues([1], [2], $st, $ae) === false ); it('does not consist of the same values', consistsOfTheSameValues([1], [1, 1], $st, $ae) === false ); it('does not consist of the same values', consistsOfTheSameValues([1, 1], [1], $st, $ae) === false ); it('does not consist of the same values', consistsOfTheSameValues([1], [1, 2], $st, $ae) === false ); it('does not consist of the same values', consistsOfTheSameValues([1], [2, 1], $st, $ae) === false ); it('does not consist of the same values', consistsOfTheSameValues([1, 2], [1], $st, $ae) === false ); it('does not consist of the same values', consistsOfTheSameValues([2, 1], [1], $st, $ae) === false ); it('does not consist of the same values with key', consistsOfTheSameValues(['x' => 1], ['x' => 2], $st, $ae) === false ); it('does not consist of the same values with key', consistsOfTheSameValues(['x' => 1, 'y' => 1], ['x' => 1, 'y' => 2], $st, $ae) === false ); it('does not consist of the same values with key', consistsOfTheSameValues(['x' => 1, 'y' => 1], ['x' => 2, 'y' => 1], $st, $ae) === false ); it('does not consist of the same values with key', consistsOfTheSameValues(['x' => 2, 'y' => 1], ['x' => 1, 'y' => 1], $st, $ae) === false ); it('does not consist of the same values for big1 and big2', consistsOfTheSameValues($big1, $big2, $st, $ae) === false ); it('does not consist of the same values for big2 and big1', consistsOfTheSameValues($big2, $big1, $st, $ae) === false ); // test strictness $consists_of = ($st ? 'does not consist of the same strict values' : 'consists of the same loose values'); it($consists_of, consistsOfTheSameValues(['1'], [1], $st, $ae) !== $st ); it($consists_of, consistsOfTheSameValues([1], ['1'], $st, $ae) !== $st ); it($consists_of, consistsOfTheSameValues(['1', 1], [1, 1], $st, $ae) !== $st ); it($consists_of, consistsOfTheSameValues([1, '1'], [1, 1], $st, $ae) !== $st ); it($consists_of, consistsOfTheSameValues([1, 1], ['1', 1], $st, $ae) !== $st ); it($consists_of, consistsOfTheSameValues([1, 1], [1, '1'], $st, $ae) !== $st ); it($consists_of, consistsOfTheSameValues(['1', '1'], [1, 1], $st, $ae) !== $st ); it($consists_of, consistsOfTheSameValues(['1', '1'], ['1', 1], $st, $ae) !== $st ); it($consists_of, consistsOfTheSameValues(['1', '1'], [1, '1'], $st, $ae) !== $st ); it($consists_of, consistsOfTheSameValues([1, 1], ['1', '1'], $st, $ae) !== $st ); it($consists_of, consistsOfTheSameValues(['1', 1], ['1', '1'], $st, $ae) !== $st ); it($consists_of, consistsOfTheSameValues([1, '1'], ['1', '1'], $st, $ae) !== $st ); } }

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.4.00.0050.13615.27
7.3.120.0080.14515.12
7.3.110.0100.13615.26
7.3.100.0080.11515.11
7.3.90.0050.08315.10
7.3.80.0030.10914.84
7.3.70.0080.11015.08
7.3.60.0030.08415.03
7.3.50.0080.11215.08
7.3.40.0020.12315.08
7.3.30.0080.11614.92
7.3.20.0070.09416.69
7.3.10.0030.10316.64
7.3.00.0020.09616.72
7.2.250.0070.11415.34
7.2.240.0070.12915.04
7.2.230.0030.09815.38
7.2.220.0050.10315.14
7.2.210.0070.11815.14
7.2.200.0000.09015.23
7.2.190.0030.09615.17
7.2.180.0030.12615.27
7.2.170.0070.11515.25
7.2.160.0100.08415.36
7.2.150.0030.08617.00
7.2.140.0000.13116.96
7.2.130.0000.08117.05
7.2.120.0030.08817.02
7.2.110.0070.14316.67
7.2.100.0070.12917.00
7.2.90.0070.12716.98
7.2.80.0070.12416.69
7.2.70.0030.09317.01
7.2.60.0030.10016.74
7.2.50.0100.12316.62
7.2.40.0070.08317.09
7.2.30.0030.08217.05
7.2.20.0100.08716.84
7.2.10.0030.08117.00
7.2.00.0000.13117.09
7.1.330.0080.11115.69
7.1.320.0080.09915.66
7.1.310.0050.10915.83
7.1.300.0080.12515.79
7.1.290.0030.11115.94
7.1.280.0030.09815.81
7.1.270.0030.10615.87
7.1.260.0030.09215.78
7.1.250.0030.08915.83
7.1.240.0030.09215.82
7.1.230.0000.15015.84
7.1.220.0030.14015.64
7.1.210.0000.12015.78
7.1.200.0030.08715.54
7.1.190.0030.08915.82
7.1.180.0030.10315.62
7.1.170.0030.14315.88
7.1.160.0000.10115.79
7.1.150.0030.13915.79
7.1.140.0070.08915.88
7.1.130.0030.11715.92
7.1.120.0000.13215.81
7.1.110.0070.11015.93
7.1.100.0030.11215.68
7.1.90.0070.12615.55
7.1.80.0070.08015.82
7.1.70.0050.10016.65
7.1.60.0020.09116.57
7.1.50.0070.08415.86
7.1.40.0030.09715.92
7.1.30.0070.12015.60
7.1.20.0070.08515.62
7.1.10.0070.07515.63
7.1.00.0050.14319.07
7.0.330.0030.08315.62
7.0.320.0030.13115.63
7.0.310.0030.09115.19
7.0.300.0100.08715.24
7.0.290.0070.10515.44
7.0.280.0030.09115.46
7.0.270.0030.10915.27
7.0.260.0030.08915.46
7.0.250.0060.08715.18
7.0.240.0070.10715.51
7.0.230.0070.10215.29
7.0.220.0030.11815.66
7.0.210.0000.12715.48
7.0.200.0130.08615.18
7.0.190.0000.14115.50
7.0.180.0030.13715.54
7.0.170.0030.08915.44
7.0.160.0030.10915.50
7.0.150.0070.08015.33
7.0.140.0070.08315.38
7.0.130.0030.13615.34
7.0.120.0000.10515.35
7.0.110.0030.09015.56
7.0.100.3970.14617.75
7.0.90.2950.15817.87
7.0.80.0120.15417.81
7.0.70.0130.13817.84
7.0.60.0230.15117.86
7.0.50.0180.13618.06
7.0.40.0080.14417.13
7.0.30.0130.16417.08
7.0.20.0180.15317.06
7.0.10.0200.13817.06
7.0.00.0200.16117.02
5.6.400.0030.41215.02
5.6.390.0030.40714.89
5.6.380.0070.40515.02
5.6.370.0000.35814.64
5.6.360.0070.40615.03
5.6.350.0030.54314.78
5.6.340.0030.50015.13
5.6.330.0100.38615.00
5.6.320.0030.38014.98
5.6.310.0070.39814.74
5.6.300.0030.38915.05
5.6.290.0100.51114.84
5.6.280.0100.54314.83
5.6.270.0070.35614.89
5.6.260.0070.39214.53
5.6.250.0100.45917.75
5.6.240.0100.53217.83
5.6.230.0080.49717.96
5.6.220.0130.50917.88
5.6.210.0130.55118.08
5.6.200.0100.51218.12
5.6.190.0020.48718.28
5.6.180.0120.58118.18
5.6.170.0120.54218.01
5.6.160.0080.48018.12
5.6.150.0030.48218.07
5.6.140.0120.56118.21
5.6.130.0050.55018.00
5.6.120.0120.55718.20
5.6.110.0070.59118.04
5.6.100.0080.61118.09
5.6.90.0100.57118.15
5.6.80.0130.48917.76
5.6.70.0050.54117.90
5.6.60.0080.60617.78
5.6.50.0200.55317.88
5.6.40.0070.47717.68
5.6.30.0070.48217.70
5.6.20.0130.46817.74
5.6.10.0100.54817.79
5.6.00.0100.48417.69

preferences:
49.88 ms | 403 KiB | 5 Q