3v4l.org

run code in 300+ PHP versions simultaneously
<?php $iterations = 10000; 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] = str_random(rand(16, 64)); } } $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; exit; $s_md5 = strlen(serialize($hashes_md5)); $s_crc32 = strlen(serialize($hashes_crc32)); $u_hashes_md5 = array_unique($hashes_md5); $u_hashes_crc32 = array_unique($hashes_crc32); $su_md5 = strlen(serialize($u_hashes_md5)); $su_crc32 = strlen(serialize($u_hashes_crc32)); echo 'time md5: ', $t_md5, PHP_EOL; echo 'time crc32: ', $t_crc32, PHP_EOL; echo 'time boost: ', round(($t_md5 - $t_crc32) / $t_md5, 2) * 100, '%', PHP_EOL; echo PHP_EOL; echo 'size md5: ', $s_md5, PHP_EOL; echo 'size crc32: ', $s_crc32, PHP_EOL; echo 'size boost: ', round(($s_md5 - $s_crc32) / $s_md5, 2) * 100, '%', PHP_EOL; echo PHP_EOL; echo 'unique size md5: ', $su_md5, ' (', $cnt_hashes_md5 = count($u_hashes_md5), ')', PHP_EOL; echo 'unique size crc32: ', $su_crc32, ' (', $cnt_hashes_crc32 = count($u_hashes_crc32), ')', PHP_EOL; echo 'unique size boost: ', round(($su_md5 - $su_crc32) / $su_md5, 2) * 100, '%', PHP_EOL; echo ' collision: ', round(($cnt_hashes_md5 - $cnt_hashes_crc32) / $cnt_hashes_md5, 6) * 100, '%', 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.3.10.0070.08722.60
7.3.00.0030.08122.25
7.2.130.0030.09922.86
7.2.120.0000.10122.88
7.2.110.0070.10522.64
7.2.100.0030.10022.84
7.2.90.0130.09222.97
7.2.80.0070.09722.69
7.2.70.0000.10023.00
7.2.60.0030.10022.89
7.2.50.0070.09322.96
7.2.40.0030.09722.79
7.2.30.0130.09223.06
7.2.20.0100.09222.58
7.2.10.0130.08823.00
7.2.00.0050.09224.02
7.1.250.0070.13219.79
7.1.240.0130.12619.73
7.1.230.0030.13219.59
7.1.220.0070.15219.63
7.1.210.0000.13319.84
7.1.200.0070.13019.86
7.1.190.0030.12319.66
7.1.180.0030.12419.89
7.1.170.0030.12419.56
7.1.160.0100.11619.57
7.1.150.0030.13219.75
7.1.140.0030.12019.80
7.1.130.0030.12619.76
7.1.120.0070.12619.91
7.1.110.0100.11819.87
7.1.100.0130.12420.00
7.1.90.0070.13319.88
7.1.80.0000.12819.69
7.1.70.0050.12920.38
7.1.60.0080.15520.46
7.1.50.0050.15320.31
7.1.40.0070.12219.73
7.1.30.0030.12019.94
7.1.20.0000.13419.86
7.1.10.0070.11719.41
7.1.00.0020.16923.01
7.0.330.0000.11819.44
7.0.320.0100.10919.32
7.0.310.0000.11019.30
7.0.300.0130.09919.63
7.0.290.0030.10419.06
7.0.280.0070.10319.35
7.0.270.0030.10619.30
7.0.260.0030.10619.38
7.0.250.0070.10319.61
7.0.240.0070.10119.48
7.0.230.0070.11919.39
7.0.220.0030.11019.51
7.0.210.0130.09419.48
7.0.200.0350.08119.78
7.0.190.0130.10019.31
7.0.180.0130.09719.31
7.0.170.0070.10619.39
7.0.160.0030.10519.48
7.0.150.0070.10019.40
7.0.140.0030.12122.74
7.0.130.0100.10319.45
7.0.120.0030.11319.33
7.0.110.0030.11019.53
7.0.100.0270.11821.80
7.0.90.0100.12121.85
7.0.80.0120.11721.83
7.0.70.0100.09921.69
7.0.60.0050.10421.63
7.0.50.0170.11522.08
7.0.40.0050.09716.84
7.0.30.0100.11016.80
7.0.20.0080.09316.82
7.0.10.0120.09616.84
7.0.00.0070.12816.77
5.6.380.0030.12723.14
5.6.370.0100.12022.79
5.6.360.0070.12822.97
5.6.350.0130.11723.23
5.6.340.0030.13022.97
5.6.330.0230.10822.56
5.6.320.0100.12323.14
5.6.310.0100.12223.32
5.6.300.0100.11923.05
5.6.290.0070.12722.90
5.6.280.0050.13426.12
5.6.270.0030.12723.31
5.6.260.0130.13022.99
5.6.250.0130.14926.11
5.6.240.0120.12825.94
5.6.230.0180.12926.07
5.6.220.0180.13726.05
5.6.210.0080.11925.88
5.6.200.0050.14226.44
5.6.190.0130.14626.39
5.6.180.0080.12626.44
5.6.170.0100.13626.62
5.6.160.0170.14626.46
5.6.150.0100.14426.25
5.6.140.0170.12626.64
5.6.130.0070.15126.44
5.6.120.0110.10826.34
5.6.110.0100.11526.57
5.6.100.0050.13826.44
5.6.90.0120.13126.20
5.6.80.0100.11825.93
5.6.70.0100.13826.11
5.6.60.0180.12426.16
5.6.50.0080.13726.02
5.6.40.0120.10926.05
5.6.30.0180.11026.04
5.6.20.0120.12826.01
5.6.10.0130.13525.87
5.6.00.0150.11026.09
5.5.380.0100.13524.29
5.5.370.0070.13324.39
5.5.360.0100.11124.39
5.5.350.0080.14224.55
5.5.340.0120.11124.49
5.5.330.0050.13924.73
5.5.320.0150.15024.93
5.5.310.0130.13524.79
5.5.300.0130.14224.80
5.5.290.0130.12024.58
5.5.280.0070.14424.52
5.5.270.0170.11924.53
5.5.260.0100.14124.78
5.5.250.0150.11324.63
5.5.240.0080.12824.28
5.5.230.0130.13624.18
5.5.220.0030.15324.49
5.5.210.0030.13424.23
5.5.200.0080.13924.31
5.5.190.0130.13424.43
5.5.180.0100.14124.44
5.5.170.0000.14119.54
5.5.160.0150.11824.21
5.5.150.0080.12224.19
5.5.140.0100.13924.04
5.5.130.0150.12624.48
5.5.120.0070.12624.34
5.5.110.0130.12924.33
5.5.100.0070.11524.25
5.5.90.0100.11424.27
5.5.80.0030.13524.05
5.5.70.0080.12624.32
5.5.60.0080.14424.30
5.5.50.0080.14026.52
5.5.40.0220.11526.67
5.5.30.0160.14026.47
5.5.20.0030.13526.55
5.5.10.0100.12626.42
5.5.00.0120.13726.46
5.4.450.0200.12126.07
5.4.440.0100.13026.23
5.4.430.0100.13726.06
5.4.420.0080.13425.98
5.4.410.0080.13126.03
5.4.400.0080.12925.73
5.4.390.0070.14425.88
5.4.380.0150.12225.88
5.4.370.0080.14125.90
5.4.360.0120.12825.93
5.4.350.0150.12125.83
5.4.340.0150.13225.82
5.4.330.0070.12421.96
5.4.320.0080.14525.95
5.4.310.0180.13325.85
5.4.300.0120.14625.89
5.4.290.0100.13725.89
5.4.280.0130.13425.97
5.4.270.0080.12825.77
5.4.260.0170.12825.74
5.4.250.0130.11225.84
5.4.240.0130.12925.79
5.4.230.0100.14225.86
5.4.220.0100.13525.96
5.4.210.0070.12625.84
5.4.200.0120.12825.81
5.4.190.0070.12425.78
5.4.180.0100.14426.05
5.4.170.0070.12225.76
5.4.160.0080.12325.83
5.4.150.0130.11125.74
5.4.140.0100.12924.54
5.4.130.0130.13024.63
5.4.120.0210.12324.66
5.4.110.0120.12624.57
5.4.100.0030.13224.63
5.4.90.0150.10624.63
5.4.80.0120.13524.61
5.4.70.0100.12024.73
5.4.60.0050.14224.67
5.4.50.0080.13524.63
5.4.40.0120.13324.62
5.4.30.0080.12724.60
5.4.20.0080.11224.61
5.4.10.0080.15124.67
5.4.00.0150.12124.26
5.3.290.0080.13723.10
5.3.280.0070.14023.28
5.3.270.0080.15323.17
5.3.260.0120.13323.23
5.3.250.0050.13023.07
5.3.240.0080.12523.13
5.3.230.0050.11922.97
5.3.220.0080.14223.04
5.3.210.0080.14923.10
5.3.200.0120.14023.07
5.3.190.0080.15323.08
5.3.180.0050.14223.07
5.3.170.0100.13623.10
5.3.160.0100.14323.04
5.3.150.0080.14923.23
5.3.140.0130.14222.94
5.3.130.0120.13723.06
5.3.120.0070.15022.96
5.3.110.0100.14923.16
5.3.100.0080.13322.85
5.3.90.0100.12522.85
5.3.80.0070.12022.72
5.3.70.0030.15522.80
5.3.60.0070.12922.65
5.3.50.0150.14222.80
5.3.40.0150.12022.78
5.3.30.0120.14222.83
5.3.20.0100.14222.60
5.3.10.0080.13322.56
5.3.00.0050.11420.38

preferences:
34 ms | 401 KiB | 5 Q