3v4l.org

run code in 300+ PHP versions simultaneously
<?php function similarity($w1,$w2) { //return cosine similarity of w1 and w2 using formula in the //definition here: http://en.wikipedia.org/wiki/Cosine_similarity //get numerator: $numerator = 0; for($i = 0, $l = count($w1); $i < $l; $i++) $numerator += $w1[$i]*$w2[$i]; //get abs(w1) and abs(w2) $abs_w1 = 0; $abs_w2 = 0; for($i = 0, $l = count($w1); $i < $l; $i++) { $abs_w1 += $w1[$i]*$w1[$i]; $abs_w2 += $w2[$i]*$w2[$i]; } $abs_w1 = sqrt($abs_w1); $abs_w2 = sqrt($abs_w2); //make denominator: $denominator = $abs_w1*$abs_w2; return $numerator/$denominator; } echo similarity([1,2,3,4,5,6,7,8,9],[1,2,3,4,5,6,7,8,88]);

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)
8.3.60.0140.00716.63
8.3.50.0140.00522.88
8.3.40.0000.01518.88
8.3.30.0070.00719.21
8.3.20.0070.00020.09
8.3.10.0080.00023.70
8.3.00.0080.00019.50
8.2.180.0090.00616.63
8.2.170.0070.00722.96
8.2.160.0070.00720.47
8.2.150.0080.00024.18
8.2.140.0070.00024.66
8.2.130.0060.01226.16
8.2.120.0000.00821.02
8.2.110.0060.00322.25
8.2.100.0090.00620.40
8.2.90.0060.00319.21
8.2.80.0050.00317.97
8.2.70.0060.00317.72
8.2.60.0000.00817.93
8.2.50.0000.00818.07
8.2.40.0030.00620.01
8.2.30.0070.00018.02
8.2.20.0030.00617.65
8.2.10.0040.00418.15
8.2.00.0000.00817.67
8.1.280.0120.00625.92
8.1.270.0120.00423.96
8.1.260.0080.00026.35
8.1.250.0000.00728.09
8.1.240.0040.00423.82
8.1.230.0030.00618.97
8.1.220.0000.00717.74
8.1.210.0000.00818.77
8.1.200.0090.00017.23
8.1.190.0030.00617.25
8.1.180.0090.00018.10
8.1.170.0000.00818.57
8.1.160.0040.00421.95
8.1.150.0040.00418.90
8.1.140.0040.00417.43
8.1.130.0030.00317.79
8.1.120.0040.00417.41
8.1.110.0000.00817.41
8.1.100.0000.00717.50
8.1.90.0000.00817.39
8.1.80.0000.00717.44
8.1.70.0000.00717.36
8.1.60.0080.00017.63
8.1.50.0030.00517.52
8.1.40.0040.00417.58
8.1.30.0080.00017.69
8.1.20.0040.00417.60
8.1.10.0040.00417.59
8.1.00.0050.00217.41
8.0.300.0000.00818.77
8.0.290.0040.00416.75
8.0.280.0040.00418.50
8.0.270.0080.00017.28
8.0.260.0080.00017.19
8.0.250.0030.00317.00
8.0.240.0030.00316.85
8.0.230.0080.00016.99
8.0.220.0070.00016.89
8.0.210.0000.00716.76
8.0.200.0000.00616.89
8.0.190.0040.00416.97
8.0.180.0040.00516.89
8.0.170.0070.00016.83
8.0.160.0070.00016.94
8.0.150.0000.00716.89
8.0.140.0000.00816.90
8.0.130.0030.00313.36
8.0.120.0000.00816.82
8.0.110.0040.00416.90
8.0.100.0050.00316.94
8.0.90.0000.00716.79
8.0.80.0030.01316.93
8.0.70.0030.00316.83
8.0.60.0040.00416.90
8.0.50.0000.00816.94
8.0.30.0110.01017.03
8.0.20.0120.00617.40
8.0.10.0000.00717.04
8.0.00.0140.00516.82
7.4.330.0000.00515.10
7.4.320.0050.00316.44
7.4.300.0030.00316.48
7.4.290.0030.00316.53
7.4.280.0000.00716.47
7.4.270.0070.00016.61
7.4.260.0030.00316.45
7.4.250.0000.00816.55
7.4.240.0040.00316.53
7.4.230.0000.00716.71
7.4.220.0170.00316.54
7.4.210.0070.01016.56
7.4.200.0040.00416.54
7.4.160.0120.00316.61
7.4.150.0090.00917.40
7.4.140.0050.01117.86
7.4.130.0150.00516.53
7.4.120.0140.00516.55
7.4.110.0100.00616.57
7.4.100.0060.01116.42
7.4.90.0150.00316.38
7.4.80.0070.01319.39
7.4.70.0120.00616.41
7.4.60.0100.00716.34
7.4.50.0040.00416.35
7.4.40.0070.01116.69
7.4.30.0040.01216.46
7.4.10.0110.00815.96
7.4.00.0040.01115.64
7.3.330.0060.00013.25
7.3.320.0000.00613.21
7.3.310.0040.00416.29
7.3.300.0030.00316.37
7.3.290.0120.00616.37
7.3.280.0060.01016.39
7.3.270.0130.00317.40
7.3.260.0100.00616.29
7.3.250.0100.01016.53
7.3.240.0120.00416.42
7.3.230.0060.01016.54
7.3.210.0100.00716.37
7.3.200.0150.00919.39
7.3.190.0050.01316.65
7.3.180.0030.01316.38
7.3.170.0110.00616.32
7.3.160.0080.00816.32
7.3.130.0050.00815.63
7.3.120.0050.00815.61
7.3.110.0050.01115.82
7.3.100.0080.00615.47
7.3.90.0090.00315.79
7.3.80.0080.00715.78
7.3.70.0040.00915.69
7.3.60.0050.00715.70
7.3.50.0060.00715.62
7.3.40.0070.00915.58
7.3.30.0030.00815.60
7.3.20.0090.00517.52
7.3.10.0040.01017.49
7.3.00.0080.00817.39
7.2.330.0150.00616.64
7.2.320.0070.01316.70
7.2.310.0040.01216.80
7.2.300.0090.01516.76
7.2.290.0080.01216.51
7.2.260.0090.01115.90
7.2.250.0100.00815.79
7.2.240.0070.00615.72
7.2.230.0070.00916.01
7.2.220.0050.01215.76
7.2.210.0090.00515.93
7.2.200.0080.00615.70
7.2.190.0100.00515.65
7.2.180.0060.00815.71
7.2.170.0090.00215.76
7.2.160.0090.00915.92
7.2.150.0050.01017.56
7.2.140.0070.00717.62
7.2.130.0070.00717.67
7.2.120.0020.01017.70
7.2.110.0050.00917.68
7.2.100.0070.00717.75
7.2.90.0050.01017.75
7.2.80.0050.00917.76
7.2.70.0060.00917.75
7.2.60.0060.00817.43
7.2.50.0050.00917.62
7.2.40.0070.00617.79
7.2.30.0070.01017.66
7.2.20.0080.00717.70
7.2.10.0050.00917.68
7.2.00.0050.00918.24
7.1.330.0050.00916.57
7.1.320.0060.00816.43
7.1.310.0040.01016.75
7.1.300.0050.00716.53
7.1.290.0090.00316.66
7.1.280.0070.00516.55
7.1.270.0080.00816.55
7.1.260.0080.00516.53
7.1.250.0030.00916.69
7.1.240.0060.00616.54
7.1.230.0030.00916.55
7.1.220.0050.00916.50
7.1.210.0060.00916.54
7.1.200.0070.00816.34
7.1.190.0080.00616.54
7.1.180.0090.00616.51
7.1.170.0060.00816.70
7.1.160.0090.00116.42
7.1.150.0050.01016.55
7.1.140.0090.00516.52
7.1.130.0070.00616.51
7.1.120.0090.00516.60
7.1.110.0070.00716.72
7.1.100.0040.00817.09
7.1.90.0090.00316.78
7.1.80.0060.00816.50
7.1.70.0060.00716.82
7.1.60.0080.00717.46
7.1.50.0080.00916.51
7.1.40.0030.00916.59
7.1.30.0050.00616.51
7.1.20.0050.00716.56
7.1.10.0050.00716.54
7.1.00.0100.02418.41
7.0.330.0060.01016.29
7.0.320.0040.00916.07
7.0.310.0020.01016.18
7.0.300.0050.00716.25
7.0.290.0020.01016.07
7.0.280.0030.01116.23
7.0.270.0060.00516.25
7.0.260.0050.00916.20
7.0.250.0030.00716.30
7.0.240.0060.00616.34
7.0.230.0080.00316.41
7.0.220.0050.01116.20
7.0.210.0060.00516.14
7.0.200.0040.00716.49
7.0.190.0070.00516.16
7.0.180.0030.00716.20
7.0.170.0050.00716.13
7.0.160.0020.01216.15
7.0.150.0040.01216.30
7.0.140.0110.02418.15
7.0.130.0050.00816.24
7.0.120.0060.00716.27
7.0.110.0050.00916.23
7.0.100.0050.01016.27
7.0.90.0040.00716.24
7.0.80.0020.01016.30
7.0.70.0050.01116.22
7.0.60.0070.02317.40
7.0.50.0060.03216.77
7.0.40.0090.03016.18
7.0.30.0160.01416.17
7.0.20.0090.03116.18
7.0.10.0050.02716.25
7.0.00.0040.02316.16
5.6.400.0090.00415.10
5.6.390.0000.00915.19
5.6.380.0030.00815.13
5.6.370.0050.00715.22
5.6.360.0030.01115.03
5.6.350.0090.00215.00
5.6.340.0120.00514.87
5.6.330.0040.01115.00
5.6.320.0030.01015.30
5.6.310.0050.00915.06
5.6.300.0070.00515.10
5.6.290.0070.00615.45
5.6.280.0020.03217.22
5.6.270.0060.00415.21
5.6.260.0050.01115.15
5.6.250.0070.00515.18
5.6.240.0030.01215.23
5.6.230.0050.01215.14
5.6.220.0050.00915.27
5.6.210.0030.03516.92
5.6.200.0050.02216.13
5.6.190.0020.03716.95
5.6.180.0150.02716.85
5.6.170.0120.02917.03
5.6.160.0040.03716.94
5.6.150.0070.03116.27
5.6.140.0050.02216.08
5.6.130.0090.01516.28
5.6.120.0080.03417.12
5.6.110.0040.02917.17
5.6.100.0070.03417.02
5.6.90.0040.02317.21
5.6.80.0050.01816.96
5.6.70.0060.00815.23
5.6.60.0020.01115.17
5.6.50.0090.00515.36
5.6.40.0090.00515.05
5.6.30.0060.00815.03
5.6.20.0100.00315.11
5.6.10.0060.01115.15
5.6.00.0090.00514.88
5.5.380.0040.00815.17
5.5.370.0100.00514.90
5.5.360.0120.00515.04
5.5.350.0120.02817.01
5.5.340.0050.02816.04
5.5.330.0040.02416.94
5.5.320.0120.01816.73
5.5.310.0100.02717.01
5.5.300.0080.02316.17
5.5.290.0070.03316.25
5.5.280.0060.02517.04
5.5.270.0100.03017.00
5.5.260.0060.03016.93
5.5.250.0080.02816.93
5.5.240.0070.02916.76
5.5.230.0080.00514.99
5.5.220.0060.00614.94
5.5.210.0060.00815.03
5.5.200.0060.00715.02
5.5.190.0000.01314.96
5.5.180.0100.00614.83
5.5.170.0000.01215.01
5.5.160.0040.01015.05
5.5.150.0020.01214.96
5.5.140.0080.00714.98
5.5.130.0090.00614.98
5.5.120.0060.00814.95
5.5.110.0090.00815.12
5.5.100.0060.00814.98
5.5.90.0090.00515.22
5.5.80.0080.00615.03
5.5.70.0090.00714.90
5.5.60.0100.00315.09
5.5.50.0040.01015.16
5.5.40.0040.01115.00
5.5.30.0020.01114.88
5.5.20.0040.00915.03
5.5.10.0050.00915.06
5.5.00.0040.00914.97
5.4.450.0090.02014.51
5.4.440.0240.02014.48
5.4.430.0270.01914.58
5.4.420.0310.02114.55
5.4.410.0060.02314.29
5.4.400.0100.02614.09
5.4.390.0140.02514.20
5.4.380.0090.01614.08
5.4.370.0070.01914.03
5.4.360.0070.02214.11
5.4.350.0030.01611.90
5.4.340.0100.01911.80
5.4.330.0060.00511.95
5.4.320.0060.01511.98
5.4.310.0060.01412.00
5.4.300.0060.01612.11
5.4.290.0030.01712.03
5.4.280.0050.01812.04
5.4.270.0050.01612.07
5.4.260.0050.01512.09
5.4.250.0050.01612.17
5.4.240.0050.01612.05
5.4.230.0070.01612.03
5.4.220.0050.01612.16
5.4.210.0020.01711.96
5.4.200.0060.01712.06
5.4.190.0050.01712.05
5.4.180.0050.01912.03
5.4.170.0040.01612.18
5.4.160.0070.01512.10
5.4.150.0050.01712.04
5.4.140.0050.01711.97
5.4.130.0020.01811.91
5.4.120.0060.01612.00
5.4.110.0050.01712.01
5.4.100.0080.01411.92
5.4.90.0040.01611.95
5.4.80.0040.01811.96
5.4.70.0070.01411.88
5.4.60.0060.01511.91
5.4.50.0040.01712.03
5.4.40.0040.01711.85
5.4.30.0040.01711.89
5.4.20.0050.01712.00
5.4.10.0080.01311.86
5.4.00.0020.01911.71
5.3.290.0090.03612.80
5.3.280.0070.03612.71
5.3.270.0090.03612.72
5.3.260.0050.04312.72
5.3.250.0050.03712.72
5.3.240.0040.03812.72
5.3.230.0050.03812.71
5.3.220.0080.03512.68
5.3.210.0070.03812.68
5.3.200.0020.04212.68
5.3.190.0070.04212.68
5.3.180.0070.03512.67
5.3.170.0080.03512.66
5.3.160.0070.03612.67
5.3.150.0040.03912.68
5.3.140.0060.03612.66
5.3.130.0080.03612.66
5.3.120.0040.04212.66
5.3.110.0050.03912.66
5.3.100.0040.03812.12
5.3.90.0030.03812.11
5.3.80.0050.03712.09
5.3.70.0080.03412.09
5.3.60.0090.03312.08
5.3.50.0090.03212.03
5.3.40.0050.03612.03
5.3.30.0060.03411.98
5.3.20.0070.03411.77
5.3.10.0040.03711.73
5.3.00.0050.03711.71
5.2.170.0070.0299.22
5.2.160.0040.0309.22
5.2.150.0040.0329.22
5.2.140.0070.0309.21
5.2.130.0070.0279.18
5.2.120.0090.0249.18
5.2.110.0040.0299.19
5.2.100.0050.0289.18
5.2.90.0050.0279.18
5.2.80.0050.0299.18
5.2.70.0040.0319.18
5.2.60.0050.0299.13
5.2.50.0040.0309.09
5.2.40.0040.0299.07
5.2.30.0050.0319.05
5.2.20.0060.0269.05
5.2.10.0030.0298.95
5.2.00.0050.0288.81
5.1.60.0050.0228.09
5.1.50.0030.0258.09
5.1.40.0050.0238.07
5.1.30.0050.0258.43
5.1.20.0020.0288.45
5.1.10.0020.0288.16
5.1.00.0050.0258.16
5.0.50.0010.0236.66
5.0.40.0040.0186.52
5.0.30.0020.0326.32
5.0.20.0030.0196.30
5.0.10.0030.0216.28
5.0.00.0020.0316.27
4.4.90.0040.0144.78
4.4.80.0030.0164.76
4.4.70.0020.0164.75
4.4.60.0040.0144.76
4.4.50.0020.0164.77
4.4.40.0040.0234.70
4.4.30.0040.0144.76
4.4.20.0030.0154.84
4.4.10.0040.0144.84
4.4.00.0040.0234.76
4.3.110.0030.0204.67
4.3.100.0030.0164.66
4.3.90.0050.0184.64
4.3.80.0040.0304.58
4.3.70.0040.0134.63
4.3.60.0020.0154.62
4.3.50.0010.0164.63
4.3.40.0030.0234.54
4.3.30.0020.0163.32
4.3.20.0010.0163.30
4.3.10.0010.0163.25
4.3.00.0130.0237.13

preferences:
47.13 ms | 401 KiB | 5 Q