3v4l.org

run code in 300+ PHP versions simultaneously
<?php $iterations = 100000; function str_random($length=16) { $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; return substr(str_shuffle(str_repeat($pool, 5)), 0, $length); } $strings = array(); for ($i = 0; $i < $iterations; $i++) { $strings[] = str_random(rand(16, 64)); } 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;

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.0460.69932.22
7.3.120.0250.70032.50
7.3.110.0180.70732.39
7.3.100.0100.63432.43
7.3.90.0180.68132.25
7.3.80.0200.64932.33
7.3.70.0230.59932.39
7.3.60.0170.67132.38
7.3.50.0170.65432.30
7.3.40.0130.68132.34
7.3.30.0200.62832.24
7.3.20.0120.68135.22
7.3.10.0120.69334.95
7.3.00.0080.68635.03
7.2.250.0171.01932.02
7.2.240.0230.87432.07
7.2.230.0200.80232.05
7.2.220.0220.80632.19
7.2.210.0170.83332.05
7.2.200.0220.77631.98
7.2.190.0180.83332.11
7.2.180.0100.90731.97
7.2.170.0230.76332.15
7.2.160.0120.84432.27
7.2.150.0170.74335.26
7.2.140.0070.85335.15
7.2.130.0180.72135.08
7.2.120.0150.85035.20
7.2.110.0170.85635.25
7.2.100.0120.89735.11
7.2.90.0200.81535.10
7.2.80.0080.88135.18
7.2.70.0170.87435.15
7.2.60.0200.79735.21
7.2.50.0100.87135.12
7.2.40.0150.83435.20
7.2.30.0170.81035.17
7.2.20.0120.79035.21
7.2.10.0130.72035.18
7.2.00.0230.74544.72
7.1.330.0161.05833.97
7.1.320.0131.03034.09
7.1.310.0231.02534.04
7.1.300.0181.15334.05
7.1.290.0080.98133.90
7.1.280.0171.19334.09
7.1.270.0151.16734.09
7.1.260.0231.10434.20
7.1.250.0151.18333.84
7.1.70.0401.05959.48
7.1.60.0371.04859.90
7.1.50.0271.05359.40
7.1.00.0301.01364.65
7.0.200.4010.47752.82
7.0.140.0030.54064.35
7.0.60.0230.45757.37
7.0.50.0370.53055.17
7.0.40.0300.48041.18
7.0.30.0730.47741.36
7.0.20.0770.50341.43
7.0.10.0070.54741.38
7.0.00.0200.64741.18
5.6.280.0070.64085.05
5.6.210.0330.62384.54
5.6.200.0230.63082.18
5.6.190.0230.62784.40
5.6.180.0470.56384.50
5.6.170.0500.62784.28
5.6.160.0370.59784.68
5.6.150.0500.71382.09
5.6.140.0300.63781.94
5.6.130.0230.58782.19
5.6.120.0100.65085.03
5.6.110.0330.65085.49
5.6.100.0270.59784.96
5.6.90.0400.57084.96
5.6.80.0170.63784.35
5.5.350.0200.64384.39
5.5.340.0230.56082.01
5.5.330.0300.67784.77
5.5.320.0570.64384.27
5.5.310.0630.63784.29
5.5.300.0330.58081.96
5.5.290.0270.69081.98
5.5.280.0330.61784.89
5.5.270.0530.57084.84
5.5.260.0870.62384.63
5.5.250.0300.64384.69
5.5.240.0270.62084.20
5.4.450.0370.61082.27
5.4.440.0370.55782.28
5.4.430.0530.54382.24
5.4.420.0400.60082.02
5.4.410.0400.63382.24
5.4.400.0400.54781.87
5.4.390.0630.54782.13
5.4.380.0600.69782.06
5.4.370.0430.58081.93
5.4.360.0400.61081.75
5.4.350.0470.63081.93
5.4.340.0530.51781.93
5.4.320.0500.57081.84
5.4.310.0500.59381.92
5.4.300.0400.53782.09
5.4.290.0690.94748.76
5.4.280.0470.93948.64
5.4.270.0250.63748.65
5.4.260.0490.65348.64
5.4.250.0270.64648.64
5.4.240.0280.59648.64
5.4.230.0260.62848.64
5.4.220.0490.79148.64
5.4.210.0370.61348.64
5.4.200.0430.97448.64
5.4.190.0330.93548.63
5.4.180.0480.80948.63
5.4.170.0340.78748.64
5.4.160.0480.66848.64
5.4.150.0340.83548.63
5.4.140.0410.83148.32
5.4.130.0450.68648.31
5.4.120.0570.73748.27
5.4.110.0410.72248.27
5.4.100.0360.61448.26
5.4.90.0390.88748.25
5.4.80.0350.66748.25
5.4.70.0450.77248.25
5.4.60.0360.58648.26
5.4.50.0320.63348.26
5.4.40.0240.56648.25
5.4.30.0320.55448.25
5.4.20.0390.88548.23
5.4.10.0400.61348.25
5.4.00.0370.66847.73
5.3.290.3500.47349.64
5.3.280.0400.63147.72
5.3.270.0340.74247.73
5.3.260.0220.57747.73
5.3.250.0200.62247.73
5.3.240.0390.61047.72
5.3.230.0440.84747.72
5.3.220.0580.94747.69
5.3.210.0701.29347.70
5.3.200.0761.20947.69
5.3.190.0520.87647.70
5.3.180.0350.56847.69
5.3.170.0420.78147.69
5.3.160.0400.88347.68
5.3.150.0360.72247.68
5.3.140.0390.76447.68
5.3.130.0420.92547.67
5.3.120.0370.92547.67
5.3.110.0470.89047.67
5.3.100.0430.87347.16
5.3.90.0530.94447.15
5.3.80.0420.94947.13
5.3.70.0481.12747.14
5.3.60.0511.13147.12
5.3.50.0520.78847.07
5.3.40.0811.16947.07
5.3.30.0910.90047.03
5.3.20.0370.58446.81
5.3.10.0260.57446.77
5.3.00.0270.53146.75
5.2.170.0270.60543.48
5.2.160.0420.76343.48
5.2.150.0460.82843.49
5.2.140.0350.90543.48
5.2.130.0360.92943.45
5.2.120.0561.00443.44
5.2.110.0360.67243.45
5.2.100.0200.56343.45
5.2.90.0300.63443.44
5.2.80.0410.73143.43
5.2.70.0280.74743.43
5.2.60.0370.89144.43
5.2.50.0300.67643.65
5.2.40.0320.75543.38
5.2.30.0830.83743.35
5.2.20.0390.79743.59
5.2.10.0570.83372.12
5.2.00.5431.167782.55
5.1.60.0371.03051.70
5.1.50.0330.82351.70
5.1.40.0370.72151.68
5.1.30.0310.64352.03
5.1.20.0300.62552.05
5.1.10.0370.78651.79
5.1.00.0320.88551.78
5.0.50.0060.0246.66
5.0.40.0070.0176.52
5.0.30.0030.0336.34
5.0.20.0060.0186.31
5.0.10.0080.0176.28
5.0.00.0040.0326.28
4.4.90.0040.0154.78
4.4.80.0020.0174.75
4.4.70.0040.0154.76
4.4.60.0080.0124.75
4.4.50.0040.0184.77
4.4.40.0000.0274.71
4.4.30.0030.0164.76
4.4.20.0020.0174.85
4.4.10.0020.0174.85
4.4.00.0040.0244.76
4.3.110.0020.0164.66
4.3.100.0030.0154.67
4.3.90.0040.0194.63
4.3.80.0070.0244.58
4.3.70.0030.0204.63
4.3.60.0040.0154.63
4.3.50.0010.0184.63
4.3.40.0030.0264.53
4.3.30.0000.0193.33
4.3.20.0020.0173.31
4.3.10.0030.0203.26
4.3.00.0070.01713.91

preferences:
35.88 ms | 400 KiB | 5 Q