@ 2016-09-08T12:57:02Z <?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
);
}
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
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).
Version System time (s) User time (s) Memory (MiB) 7.4.0 0.005 0.136 15.27 7.3.12 0.008 0.145 15.12 7.3.11 0.010 0.136 15.26 7.3.10 0.008 0.115 15.11 7.3.9 0.005 0.083 15.10 7.3.8 0.003 0.109 14.84 7.3.7 0.008 0.110 15.08 7.3.6 0.003 0.084 15.03 7.3.5 0.008 0.112 15.08 7.3.4 0.002 0.123 15.08 7.3.3 0.008 0.116 14.92 7.3.2 0.007 0.094 16.69 7.3.1 0.003 0.103 16.64 7.3.0 0.002 0.096 16.72 7.2.25 0.007 0.114 15.34 7.2.24 0.007 0.129 15.04 7.2.23 0.003 0.098 15.38 7.2.22 0.005 0.103 15.14 7.2.21 0.007 0.118 15.14 7.2.20 0.000 0.090 15.23 7.2.19 0.003 0.096 15.17 7.2.18 0.003 0.126 15.27 7.2.17 0.007 0.115 15.25 7.2.16 0.010 0.084 15.36 7.2.15 0.003 0.086 17.00 7.2.14 0.000 0.131 16.96 7.2.13 0.000 0.081 17.05 7.2.12 0.003 0.088 17.02 7.2.11 0.007 0.143 16.67 7.2.10 0.007 0.129 17.00 7.2.9 0.007 0.127 16.98 7.2.8 0.007 0.124 16.69 7.2.7 0.003 0.093 17.01 7.2.6 0.003 0.100 16.74 7.2.5 0.010 0.123 16.62 7.2.4 0.007 0.083 17.09 7.2.3 0.003 0.082 17.05 7.2.2 0.010 0.087 16.84 7.2.1 0.003 0.081 17.00 7.2.0 0.000 0.131 17.09 7.1.33 0.008 0.111 15.69 7.1.32 0.008 0.099 15.66 7.1.31 0.005 0.109 15.83 7.1.30 0.008 0.125 15.79 7.1.29 0.003 0.111 15.94 7.1.28 0.003 0.098 15.81 7.1.27 0.003 0.106 15.87 7.1.26 0.003 0.092 15.78 7.1.25 0.003 0.089 15.83 7.1.24 0.003 0.092 15.82 7.1.23 0.000 0.150 15.84 7.1.22 0.003 0.140 15.64 7.1.21 0.000 0.120 15.78 7.1.20 0.003 0.087 15.54 7.1.19 0.003 0.089 15.82 7.1.18 0.003 0.103 15.62 7.1.17 0.003 0.143 15.88 7.1.16 0.000 0.101 15.79 7.1.15 0.003 0.139 15.79 7.1.14 0.007 0.089 15.88 7.1.13 0.003 0.117 15.92 7.1.12 0.000 0.132 15.81 7.1.11 0.007 0.110 15.93 7.1.10 0.003 0.112 15.68 7.1.9 0.007 0.126 15.55 7.1.8 0.007 0.080 15.82 7.1.7 0.005 0.100 16.65 7.1.6 0.002 0.091 16.57 7.1.5 0.007 0.084 15.86 7.1.4 0.003 0.097 15.92 7.1.3 0.007 0.120 15.60 7.1.2 0.007 0.085 15.62 7.1.1 0.007 0.075 15.63 7.1.0 0.005 0.143 19.07 7.0.33 0.003 0.083 15.62 7.0.32 0.003 0.131 15.63 7.0.31 0.003 0.091 15.19 7.0.30 0.010 0.087 15.24 7.0.29 0.007 0.105 15.44 7.0.28 0.003 0.091 15.46 7.0.27 0.003 0.109 15.27 7.0.26 0.003 0.089 15.46 7.0.25 0.006 0.087 15.18 7.0.24 0.007 0.107 15.51 7.0.23 0.007 0.102 15.29 7.0.22 0.003 0.118 15.66 7.0.21 0.000 0.127 15.48 7.0.20 0.013 0.086 15.18 7.0.19 0.000 0.141 15.50 7.0.18 0.003 0.137 15.54 7.0.17 0.003 0.089 15.44 7.0.16 0.003 0.109 15.50 7.0.15 0.007 0.080 15.33 7.0.14 0.007 0.083 15.38 7.0.13 0.003 0.136 15.34 7.0.12 0.000 0.105 15.35 7.0.11 0.003 0.090 15.56 7.0.10 0.397 0.146 17.75 7.0.9 0.295 0.158 17.87 7.0.8 0.012 0.154 17.81 7.0.7 0.013 0.138 17.84 7.0.6 0.023 0.151 17.86 7.0.5 0.018 0.136 18.06 7.0.4 0.008 0.144 17.13 7.0.3 0.013 0.164 17.08 7.0.2 0.018 0.153 17.06 7.0.1 0.020 0.138 17.06 7.0.0 0.020 0.161 17.02 5.6.40 0.003 0.412 15.02 5.6.39 0.003 0.407 14.89 5.6.38 0.007 0.405 15.02 5.6.37 0.000 0.358 14.64 5.6.36 0.007 0.406 15.03 5.6.35 0.003 0.543 14.78 5.6.34 0.003 0.500 15.13 5.6.33 0.010 0.386 15.00 5.6.32 0.003 0.380 14.98 5.6.31 0.007 0.398 14.74 5.6.30 0.003 0.389 15.05 5.6.29 0.010 0.511 14.84 5.6.28 0.010 0.543 14.83 5.6.27 0.007 0.356 14.89 5.6.26 0.007 0.392 14.53 5.6.25 0.010 0.459 17.75 5.6.24 0.010 0.532 17.83 5.6.23 0.008 0.497 17.96 5.6.22 0.013 0.509 17.88 5.6.21 0.013 0.551 18.08 5.6.20 0.010 0.512 18.12 5.6.19 0.002 0.487 18.28 5.6.18 0.012 0.581 18.18 5.6.17 0.012 0.542 18.01 5.6.16 0.008 0.480 18.12 5.6.15 0.003 0.482 18.07 5.6.14 0.012 0.561 18.21 5.6.13 0.005 0.550 18.00 5.6.12 0.012 0.557 18.20 5.6.11 0.007 0.591 18.04 5.6.10 0.008 0.611 18.09 5.6.9 0.010 0.571 18.15 5.6.8 0.013 0.489 17.76 5.6.7 0.005 0.541 17.90 5.6.6 0.008 0.606 17.78 5.6.5 0.020 0.553 17.88 5.6.4 0.007 0.477 17.68 5.6.3 0.007 0.482 17.70 5.6.2 0.013 0.468 17.74 5.6.1 0.010 0.548 17.79 5.6.0 0.010 0.484 17.69
preferences:dark mode live preview ace vim emacs key bindings
49.88 ms | 403 KiB | 5 Q