3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $iterations = 100000; $strings = []; for ($i = 0; $i < $iterations; $i++) { $strings[] = openssl_random_pseudo_bytes(rand(16, 50)); } echo 'String size: ', round(strlen(serialize($strings))/ 1024, 2), 'kb', PHP_EOL; $hashes_md5 = array(); $hashes_crc32 = array(); $t_md5 = microtime(true); foreach ($strings as $s) { $hashes_md5['x'.(crc32($s) >> 8)] = 0; } $t_md5 = microtime(true) - $t_md5; //$max = bindec('111111111111111111111111111111'); //$max = 0xFFFFFFF; //F; +5% size boost, collision: 0.1689%, time boost: 0% $max = 0xFFFFFF; //FF; +14% size boost, collision: 2.908%, time boost: -9% //$max = 0xFFFFF; //FFF; +47% size boost, collision: 35.5696%, time boost: 0% // modify 10% of data for ($i = 0; $i < $iterations; $i++) { if (rand(1,100) > 90) { $strings[$i] = openssl_random_pseudo_bytes(rand(16, 50)); } } $t_crc32 = microtime(true); foreach ($strings as $s) { $hashes_crc32['x'.(crc32($s) >> 8)] = 0; } $t_crc32 = microtime(true) - $t_crc32; function compareShingles(array $first, array $second) { $t_crc32 = microtime(true); echo 'func intersect: ', count(array_intersect_key($first, $second)), PHP_EOL; echo ' func unique: ', count(array_merge($first, $second)), PHP_EOL; $t_crc32 = microtime(true) - $t_crc32; echo ' time: ', $t_crc32, PHP_EOL; $t_crc32 = microtime(true); $diff_count = count(array_diff_key($first, $second)); $intersect_count = count($first) - $diff_count;// count(array_intersect_key($first, $second)); $unique_count = count($second) + $diff_count; echo 'calculated intersect: ', $intersect_count, PHP_EOL; echo ' calculated unique: ', $unique_count, PHP_EOL; $t_crc32 = microtime(true) - $t_crc32; echo ' time: ', $t_crc32, PHP_EOL; //return round(($intersect_count / $unique_count) / 0.01, 2); } $hashes_md5_flip = $hashes_md5; //array_flip($hashes_md5); $hashes_crc32_flip = $hashes_crc32; //array_flip($hashes_crc32); //ksort($hashes_md5_flip); //ksort($hashes_crc32_flip); $t_merge = microtime(true); $hashes_diff = array_diff_key($hashes_md5_flip, $hashes_crc32_flip); $t_merge = microtime(true) - $t_merge; $t_diff = microtime(true); $hashes_merge = array_merge($hashes_md5_flip, $hashes_crc32_flip); $t_diff = microtime(true) - $t_diff; $t_intersect = microtime(true); $hashes_intersect = array_intersect_key($hashes_md5_flip, $hashes_crc32_flip); $t_intersect = microtime(true) - $t_intersect; echo PHP_EOL; echo ' merge time: ', $t_merge, PHP_EOL; echo ' merge count: ', count($hashes_merge), PHP_EOL; echo ' diff time: ', $t_merge, PHP_EOL; echo ' diff count: ', count($hashes_diff), PHP_EOL; echo ' intersect time: ', $t_intersect, PHP_EOL; echo 'intersect count: ', count($hashes_intersect), PHP_EOL; echo ' md5 count: ', count($hashes_md5_flip), ' with diff:', count($hashes_md5_flip)+count($hashes_diff), ' intersect: ', count($hashes_md5_flip)-count($hashes_diff), PHP_EOL; echo ' crc32 count: ', count($hashes_crc32_flip), ' with diff:', count($hashes_crc32_flip)+count($hashes_diff), ' intersect: ', count($hashes_crc32_flip)-count($hashes_diff), PHP_EOL; echo PHP_EOL; compareShingles($hashes_md5_flip, $hashes_crc32_flip); echo PHP_EOL;
Output for 7.1.0
String size: 4770.75kb merge time: -0.0072219371795654 merge count: 109625 diff time: -0.0072219371795654 diff count: 9935 intersect time: -0.013489007949829 intersect count: 89778 md5 count: 99713 with diff:109648 intersect: 89778 crc32 count: 99690 with diff:109625 intersect: 89755 func intersect: 89778 func unique: 109625 time: -0.023374080657959 calculated intersect: 89778 calculated unique: 109625 time: -0.0080029964447021
Output for 7.0.14
String size: 4774.84kb merge time: 0.0054261684417725 merge count: 109568 diff time: 0.0054261684417725 diff count: 9855 intersect time: 0.011003971099854 intersect count: 89840 md5 count: 99695 with diff:109550 intersect: 89840 crc32 count: 99713 with diff:109568 intersect: 89858 func intersect: 89840 func unique: 109568 time: 0.018630981445312 calculated intersect: 89840 calculated unique: 109568 time: 0.0058968067169189
Output for 7.0.6
String size: 4782.6kb merge time: 0.0061891078948975 merge count: 109666 diff time: 0.0061891078948975 diff count: 9983 intersect time: 0.012224912643433 intersect count: 89719 md5 count: 99702 with diff:109685 intersect: 89719 crc32 count: 99683 with diff:109666 intersect: 89700 func intersect: 89719 func unique: 109666 time: 0.020292043685913 calculated intersect: 89719 calculated unique: 109666 time: 0.0065348148345947
Output for 7.0.5
String size: 4777.09kb merge time: 0.0058720111846924 merge count: 109750 diff time: 0.0058720111846924 diff count: 10059 intersect time: 0.011473894119263 intersect count: 89638 md5 count: 99697 with diff:109756 intersect: 89638 crc32 count: 99691 with diff:109750 intersect: 89632 func intersect: 89638 func unique: 109750 time: 0.019199848175049 calculated intersect: 89638 calculated unique: 109750 time: 0.0066518783569336
Output for 7.0.4
String size: 4774.32kb merge time: 0.0064198970794678 merge count: 109576 diff time: 0.0064198970794678 diff count: 9845 intersect time: 0.012510061264038 intersect count: 89877 md5 count: 99722 with diff:109567 intersect: 89877 crc32 count: 99731 with diff:109576 intersect: 89886 func intersect: 89877 func unique: 109576 time: 0.022439956665039 calculated intersect: 89877 calculated unique: 109576 time: 0.0070099830627441
Output for 7.0.3
String size: 4779.15kb merge time: 0.0064690113067627 merge count: 109531 diff time: 0.0064690113067627 diff count: 9798 intersect time: 0.019837141036987 intersect count: 89922 md5 count: 99720 with diff:109518 intersect: 89922 crc32 count: 99733 with diff:109531 intersect: 89935 func intersect: 89922 func unique: 109531 time: 0.032609224319458 calculated intersect: 89922 calculated unique: 109531 time: 0.0068280696868896
Output for 7.0.2
String size: 4771.82kb merge time: 0.0062150955200195 merge count: 109573 diff time: 0.0062150955200195 diff count: 9867 intersect time: 0.021491050720215 intersect count: 89821 md5 count: 99688 with diff:109555 intersect: 89821 crc32 count: 99706 with diff:109573 intersect: 89839 func intersect: 89821 func unique: 109573 time: 0.035926103591919 calculated intersect: 89821 calculated unique: 109573 time: 0.0067508220672607
Output for 7.0.1
String size: 4774.47kb merge time: 0.0063440799713135 merge count: 109645 diff time: 0.0063440799713135 diff count: 9936 intersect time: 0.012496948242188 intersect count: 89776 md5 count: 99712 with diff:109648 intersect: 89776 crc32 count: 99709 with diff:109645 intersect: 89773 func intersect: 89776 func unique: 109645 time: 0.02103590965271 calculated intersect: 89776 calculated unique: 109645 time: 0.0067710876464844
Output for 7.0.0
String size: 4774.68kb merge time: 0.006417989730835 merge count: 109607 diff time: 0.006417989730835 diff count: 9885 intersect time: 0.012708902359009 intersect count: 89837 md5 count: 99722 with diff:109607 intersect: 89837 crc32 count: 99722 with diff:109607 intersect: 89837 func intersect: 89837 func unique: 109607 time: 0.021271944046021 calculated intersect: 89837 calculated unique: 109607 time: 0.0069270133972168
Output for 5.6.28
String size: 4773.6kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 82 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.6.21
String size: 4775.84kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.6.20
String size: 4772.53kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.6.19
String size: 4772.79kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.6.18
String size: 4774.36kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.6.17
String size: 4772.67kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.6.16
String size: 4781.04kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.6.15
String size: 4779.25kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.6.14
String size: 4778.08kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.6.13
String size: 4773.27kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.6.12
String size: 4775.93kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.6.11
String size: 4771.44kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.6.10
String size: 4770.91kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.6.9
String size: 4770.37kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.6.8
String size: 4778.46kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.5.35
String size: 4773.31kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.5.34
String size: 4773.63kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.5.33
String size: 4773.48kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.5.32
String size: 4776.72kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.5.31
String size: 4773.86kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.5.30
String size: 4768.06kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.5.29
String size: 4773.84kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.5.28
String size: 4772.58kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.5.27
String size: 4777.45kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.5.26
String size: 4771.9kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.5.25
String size: 4772.83kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.5.24
String size: 4773.21kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 131072 bytes) in /in/a9YVH on line 77
Process exited with code 255.
Output for 5.4.45
String size: 4771.32kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 1048576 bytes) in /in/a9YVH on line 73
Process exited with code 255.
Output for 5.4.44
String size: 4776.51kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 1048576 bytes) in /in/a9YVH on line 73
Process exited with code 255.
Output for 5.4.43
String size: 4772.53kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 1048576 bytes) in /in/a9YVH on line 73
Process exited with code 255.
Output for 5.4.42
String size: 4777.88kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 1048576 bytes) in /in/a9YVH on line 73
Process exited with code 255.
Output for 5.4.41
String size: 4769.75kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 1048576 bytes) in /in/a9YVH on line 73
Process exited with code 255.
Output for 5.4.40
String size: 4770.27kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 1048576 bytes) in /in/a9YVH on line 73
Process exited with code 255.
Output for 5.4.39
String size: 4776.5kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 1048576 bytes) in /in/a9YVH on line 73
Process exited with code 255.
Output for 5.4.38
String size: 4775.11kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 1048576 bytes) in /in/a9YVH on line 73
Process exited with code 255.
Output for 5.4.37
String size: 4772.24kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 1048576 bytes) in /in/a9YVH on line 73
Process exited with code 255.
Output for 5.4.36
String size: 4776.01kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 1048576 bytes) in /in/a9YVH on line 73
Process exited with code 255.
Output for 5.4.35
String size: 4770.19kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 1048576 bytes) in /in/a9YVH on line 73
Process exited with code 255.
Output for 5.4.34
String size: 4771.41kb Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 1048576 bytes) in /in/a9YVH on line 73
Process exited with code 255.
Output for 5.4.0 - 5.4.32
Fatal error: Call to undefined function openssl_random_pseudo_bytes() in /in/a9YVH on line 8
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/a9YVH on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/a9YVH on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/a9YVH on line 5
Process exited with code 255.