3v4l.org

run code in 300+ PHP versions simultaneously
<?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;

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.10.0060.01015.02
7.4.00.0070.01114.62
7.3.130.0110.00714.70
7.3.120.0000.01415.05
7.3.110.0120.00615.03
7.3.100.0110.00314.89
7.3.90.0030.01715.00
7.3.80.0070.00714.93
7.3.70.0090.00314.75
7.3.60.0000.01314.72
7.3.50.0090.00414.88
7.3.40.0070.00714.93
7.3.30.0060.00314.83
7.3.20.0090.00616.59
7.3.10.0060.00616.76
7.3.00.0070.01016.39
7.2.260.0030.01314.75
7.2.250.0110.00714.99
7.2.240.0000.01615.10
7.2.230.0040.01115.20
7.2.220.0060.01015.00
7.2.210.0060.00914.85
7.2.200.0090.00615.09
7.2.190.0060.00615.02
7.2.180.0090.00015.09
7.2.170.0060.00915.05
7.2.160.0070.01014.90
7.2.150.0140.00316.80
7.2.140.0000.01916.89
7.2.130.0030.01016.86
7.2.120.0110.00716.99
7.2.110.0040.01216.88
7.2.100.0070.00716.83
7.2.90.0100.00316.68
7.2.80.0000.01217.02
7.2.70.0100.00716.89
7.2.60.0090.00316.86
7.2.50.0040.01116.84
7.2.40.0030.00716.83
7.2.30.0030.01416.93
7.2.20.0060.00616.59
7.2.10.0030.01016.55
7.2.00.0650.17439.23
7.1.330.0030.00915.64
7.1.320.0100.01015.87
7.1.310.0060.00315.82
7.1.300.0140.00015.39
7.1.290.0030.00715.77
7.1.280.0000.01115.70
7.1.270.0090.00615.68
7.1.260.0070.01015.41
7.1.250.0030.01315.58
7.1.240.0080.00515.68
7.1.230.0060.01015.63
7.1.220.0040.00715.73
7.1.210.0040.01115.50
7.1.200.0030.01015.64
7.1.190.0000.01315.70
7.1.180.0060.00615.67
7.1.170.0060.00315.80
7.1.160.0110.00315.75
7.1.150.0090.00615.69
7.1.140.0090.00015.75
7.1.130.0080.00815.62
7.1.120.0110.00315.49
7.1.110.0100.00615.78
7.1.100.0110.00415.64
7.1.90.0000.00815.71
7.1.80.0080.00815.60
7.1.70.0100.17636.53
7.1.60.0450.18536.53
7.1.50.0300.19536.54
7.1.40.0040.00715.57
7.1.30.0060.00615.49
7.1.20.0070.00715.77
7.1.10.0000.01415.60
7.1.00.0030.30139.16
7.0.330.0030.01015.04
7.0.320.0070.00315.38
7.0.310.0090.00015.14
7.0.300.0090.00615.35
7.0.290.0070.00715.14
7.0.280.0030.01315.09
7.0.270.0070.01015.24
7.0.260.0030.01015.34
7.0.250.0060.00615.32
7.0.240.0030.00715.25
7.0.230.0040.00815.46
7.0.220.0030.00515.58
7.0.210.0000.00815.52
7.0.200.2060.20733.53
7.0.190.0000.01115.34
7.0.180.0060.00615.22
7.0.170.0000.00915.20
7.0.160.0030.00715.15
7.0.150.0040.00715.36
7.0.140.0170.19838.76
7.0.130.0040.00715.09
7.0.120.0060.00915.07
7.0.110.0030.00515.39
7.0.100.0050.00515.16
7.0.90.0090.00315.22
7.0.80.0030.00715.12
7.0.70.0070.00715.14
7.0.60.0130.18935.97
7.0.50.0160.15634.87
7.0.40.0180.16827.43
7.0.30.0530.16127.35
7.0.20.0550.17527.48
7.0.10.0130.19227.34
7.0.00.0200.18927.38
5.6.400.0140.00314.69
5.6.390.0040.00714.33
5.6.380.0050.00514.00
5.6.370.0060.00914.29
5.6.360.0000.01614.23
5.6.350.0040.01114.69
5.6.340.0100.00714.46
5.6.330.0060.00314.16
5.6.320.0040.00814.39
5.6.310.0060.00914.39
5.6.300.0060.00314.53
5.6.290.0000.00814.42
5.6.280.0200.24749.97
5.6.270.0000.00914.38
5.6.260.0030.00614.13
5.6.250.0000.01014.40
5.6.240.0060.00314.50
5.6.230.0060.00614.51
5.6.220.0030.00814.18
5.6.210.0170.22849.59
5.6.200.0100.20248.23
5.6.190.0090.20349.24
5.6.180.0280.19549.30
5.6.170.0300.23449.30
5.6.160.0140.18849.24
5.6.150.0170.20148.06
5.6.140.0230.22348.07
5.6.130.0110.19148.17
5.6.120.0170.19049.68
5.6.110.0170.20549.47
5.6.100.0220.24749.70
5.6.90.0170.22849.64
5.6.80.0230.24049.33
5.6.70.0060.00613.96
5.6.60.0040.00413.97
5.6.50.0060.00914.21
5.6.40.0120.00314.31
5.6.30.0000.01114.13
5.6.20.0030.01214.18
5.6.10.0060.00614.21
5.6.00.0060.00614.16
5.5.380.0060.00914.09
5.5.370.0030.00614.06
5.5.360.0080.00314.12
5.5.350.0100.17649.52
5.5.340.0200.22648.06
5.5.330.0130.22249.21
5.5.320.0180.21049.25
5.5.310.0300.22549.13
5.5.300.0090.23548.12
5.5.290.0160.23948.08
5.5.280.0230.23249.41
5.5.270.0550.20649.49
5.5.260.0220.21149.53
5.5.250.0220.21849.50
5.5.240.1740.19049.31
5.5.230.0030.00614.13
5.5.220.0030.01214.14
5.5.210.0040.00814.14
5.5.200.0030.01013.84
5.5.190.0120.00013.86
5.5.180.0060.00614.05
5.5.170.0060.01014.27
5.5.160.0130.00013.99
5.5.150.0030.01213.97
5.5.140.0080.00814.18
5.5.130.0060.00313.93
5.5.120.0030.01214.28
5.5.110.0090.00614.10
5.5.100.0070.00414.18
5.5.90.0040.00714.00
5.5.80.0030.01013.91
5.5.70.0060.00613.98
5.5.60.0040.01114.21
5.5.50.0100.00313.79
5.5.40.0040.00714.09
5.5.30.0040.00814.18
5.5.20.0090.00313.78
5.5.10.0030.01513.75
5.5.00.0030.01414.15
5.4.450.0520.32446.42
5.4.440.0350.30846.59
5.4.430.0360.33346.37
5.4.420.0320.29946.50
5.4.410.0390.30146.44
5.4.400.0350.29546.23
5.4.390.0380.28346.28
5.4.380.0500.30745.98
5.4.370.0460.32246.13
5.4.360.0580.34746.01
5.4.350.0540.31545.99
5.4.340.0450.32546.06
5.4.330.0100.00311.27
5.4.320.0080.01811.89
5.4.310.0040.02911.89
5.4.300.0040.02011.89
5.4.290.0040.02511.88
5.4.280.0080.02311.83
5.4.270.0080.03111.83
5.4.260.0070.02211.83
5.4.250.0080.02711.83
5.4.240.0080.01811.83
5.4.230.0090.02411.83
5.4.220.0040.02511.83
5.4.210.0060.01811.83
5.4.200.0060.02111.83
5.4.190.0080.02011.83
5.4.180.0050.02311.83
5.4.170.0060.02311.83
5.4.160.0030.02511.83
5.4.150.0060.03011.83
5.4.140.0070.02511.67
5.4.130.0050.02211.67
5.4.120.0030.02311.64
5.4.110.0020.02411.64
5.4.100.0070.01911.64
5.4.90.0060.02011.64
5.4.80.0040.02311.64
5.4.70.0090.01811.64
5.4.60.0030.02211.64
5.4.50.0040.02311.64
5.4.40.0080.02611.63
5.4.30.0070.02211.63
5.4.20.0050.02311.63
5.4.10.0110.04311.63
5.4.00.0090.03011.38
5.3.290.0060.03012.03
5.3.280.0060.02311.99
5.3.270.0040.02711.99
5.3.260.0060.02211.99
5.3.250.0060.02611.99
5.3.240.0080.03211.99
5.3.230.0040.02711.99
5.3.220.0040.02911.97
5.3.210.0090.02411.97
5.3.200.0080.04411.97
5.3.190.0100.03111.97
5.3.180.0030.03111.97
5.3.170.0100.02511.96
5.3.160.0090.02711.97
5.3.150.0120.03411.97
5.3.140.0090.03711.96
5.3.130.0080.03011.96
5.3.120.0100.02811.96
5.3.110.0040.02411.96
5.3.100.0080.02311.69
5.3.90.0120.02811.67
5.3.80.0090.04811.67
5.3.70.0090.02611.67
5.3.60.0080.02311.66
5.3.50.0070.02211.63
5.3.40.0060.02911.63
5.3.30.0080.04211.61
5.3.20.0100.02711.50
5.3.10.0080.02811.48
5.3.00.0090.02911.47
5.2.170.0150.0559.18
5.2.160.0070.0369.19
5.2.150.0100.0419.19
5.2.140.0060.0469.18
5.2.130.0210.0569.14
5.2.120.0210.0649.14
5.2.110.0110.0419.15
5.2.100.0270.0549.15
5.2.90.0080.0529.14
5.2.80.0210.0569.14
5.2.70.0360.1449.14
5.2.60.0200.0929.09
5.2.50.0150.0829.06
5.2.40.0240.0659.04
5.2.30.0160.0579.01
5.2.20.0150.0729.01
5.2.10.0080.0648.93
5.2.00.0080.0468.79
5.1.60.0080.0518.07
5.1.50.0080.0308.06
5.1.40.0070.0418.05
5.1.30.0120.0588.40
5.1.20.0150.0558.42
5.1.10.0170.0718.14
5.1.00.0190.0688.14
5.0.50.0050.0246.63
5.0.40.0060.0226.48
5.0.30.0070.0456.30
5.0.20.0090.0216.26
5.0.10.0080.0216.25
5.0.00.0060.0336.24
4.4.90.0030.0194.78
4.4.80.0170.0464.75
4.4.70.0240.0724.75
4.4.60.0080.0314.76
4.4.50.0070.0294.77
4.4.40.0050.0334.71
4.4.30.0180.0174.76
4.4.20.0080.0164.84
4.4.10.0040.0204.85
4.4.00.0100.0544.76
4.3.110.0080.0354.67
4.3.100.0200.0354.66
4.3.90.0020.0214.64
4.3.80.0200.0354.58
4.3.70.0120.0354.63
4.3.60.0180.0244.63
4.3.50.0080.0224.63
4.3.40.0200.0324.54
4.3.30.0020.0173.29
4.3.20.0070.0213.27
4.3.10.0040.0253.22
4.3.00.0030.0278.63

preferences:
38.61 ms | 400 KiB | 5 Q