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] = 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; 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.2.00.0000.09425.08
7.1.70.0070.16820.99
7.1.60.0030.17621.20
7.1.50.0030.11320.70
7.1.00.0030.21326.36
7.0.200.0320.05520.20
7.0.140.0000.14026.18
7.0.100.0170.10024.17
7.0.90.0200.12024.20
7.0.80.0170.11324.07
7.0.70.0200.13324.14
7.0.60.0330.10323.94
7.0.50.0470.12324.45
7.0.40.0070.12320.11
7.0.30.0130.13720.12
7.0.20.0070.13720.16
7.0.10.0100.07720.20
7.0.00.0100.14720.04
5.6.280.0070.14329.75
5.6.250.0200.12729.52
5.6.240.0170.15029.32
5.6.230.0130.14729.48
5.6.220.0100.15029.18
5.6.210.0130.14729.29
5.6.200.0070.13729.79
5.6.190.0230.14029.76
5.6.180.0170.14029.86
5.6.170.0130.13029.94
5.6.160.0230.13029.57
5.6.150.0070.15029.57
5.6.140.0130.14329.73
5.6.130.0000.17329.75
5.6.120.0100.16329.92
5.6.110.0100.13329.76
5.6.100.0100.13729.97
5.6.90.0130.16329.72
5.6.80.0230.13029.03
5.6.70.0130.15328.87
5.6.60.0200.14329.03
5.6.50.0170.13328.93
5.6.40.0130.15329.25
5.6.30.0070.14329.31
5.6.20.0070.10329.24
5.6.10.0200.14029.18
5.6.00.0130.12029.17
5.5.380.0130.15729.17
5.5.370.0100.14729.21
5.5.360.0200.11029.17
5.5.350.0200.13028.96
5.5.340.0200.13729.68
5.5.330.0100.13729.57
5.5.320.0200.13029.66
5.5.310.0170.13029.43
5.5.300.0200.14729.61
5.5.290.0100.17029.67
5.5.280.0070.15029.29
5.5.270.0070.10029.51
5.5.260.0170.14029.69
5.5.250.0070.16729.48
5.5.240.0130.10329.08
5.5.230.0100.09329.11
5.5.220.0100.10328.84
5.5.210.0200.14028.65
5.5.200.0170.11729.01
5.5.190.0200.11729.00
5.5.180.0100.15728.74
5.5.160.0130.09028.75
5.5.150.0170.15328.45
5.5.140.0170.14029.03
5.5.130.0100.14728.76
5.5.120.0100.13729.02
5.5.110.0000.12028.71
5.5.100.0200.15328.96
5.5.90.0130.15028.80
5.5.80.0170.11028.54
5.5.70.0130.14028.55
5.5.60.0070.11328.90
5.5.50.0200.10330.92
5.5.40.0100.16330.75
5.5.30.0100.15730.95
5.5.20.0230.13330.94
5.5.10.0200.12330.89
5.5.00.0130.16330.94
5.4.450.0170.15330.30
5.4.440.0100.15030.00
5.4.430.0230.15330.13
5.4.420.0130.15030.16
5.4.410.0030.10730.23
5.4.400.0230.12729.86
5.4.390.0170.14029.85
5.4.380.0100.15029.77
5.4.370.0100.13329.71
5.4.360.0030.15329.84
5.4.350.0030.12329.72
5.4.340.0170.17329.77
5.4.320.0030.14729.87
5.4.310.0100.13730.00
5.4.300.0130.11029.98
5.4.290.0100.17029.82
5.4.280.0100.15329.76
5.4.270.0170.12029.78
5.4.260.0070.14729.82
5.4.250.0170.13729.93
5.4.240.0230.14329.95
5.4.230.0000.13329.82
5.4.220.0070.15729.81
5.4.210.0130.18329.86
5.4.200.0200.15029.78
5.4.190.0130.13029.75
5.4.180.0130.13729.95
5.4.170.0100.17029.71
5.4.160.0170.15729.70
5.4.150.0130.12329.79
5.4.140.0000.13319.91
5.4.130.0030.14319.89
5.4.120.0070.09319.76
5.4.110.0030.14020.09
5.4.100.0000.14320.12
5.4.90.0130.12320.07
5.4.80.0070.12320.02
5.4.70.0470.11320.06
5.4.60.0100.11719.89
5.4.50.0170.09719.94
5.4.40.0070.12720.11
5.4.30.0130.11019.96
5.4.20.0200.11320.02
5.4.10.0130.12019.89
5.4.00.0030.12019.33
5.3.290.0100.07718.20
5.3.280.0170.12018.12
5.3.270.0100.11718.09
5.3.260.0030.10017.99
5.3.250.0100.09318.09
5.3.240.0030.14318.02
5.3.230.0030.13318.13
5.3.220.0070.10717.99
5.3.210.0030.09318.05
5.3.200.0030.13717.99
5.3.190.0030.09317.95
5.3.180.0100.12018.07
5.3.170.0130.09018.07
5.3.160.0200.12717.95
5.3.150.0100.11018.10
5.3.140.0030.10717.89
5.3.130.0000.08717.97
5.3.120.0100.12718.06
5.3.110.0070.14318.08
5.3.100.0130.11717.41
5.3.90.0330.11017.42
5.3.80.0130.09717.39
5.3.70.0030.09717.43
5.3.60.0170.10717.35
5.3.50.0170.12717.34
5.3.40.0030.12717.25
5.3.30.0030.15317.27
5.3.20.0030.13017.20
5.3.10.0030.08016.96
5.3.00.0100.13717.07

preferences:
44.96 ms | 400 KiB | 5 Q