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,99,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.00316.75
8.3.50.0070.01022.91
8.3.40.0070.00718.88
8.3.30.0100.00319.11
8.3.20.0080.00020.34
8.3.10.0080.00023.66
8.3.00.0050.00319.50
8.2.180.0040.01116.63
8.2.170.0110.00422.96
8.2.160.0030.01020.52
8.2.150.0070.00024.18
8.2.140.0070.00024.66
8.2.130.0110.00326.16
8.2.120.0040.00420.94
8.2.110.0060.00322.25
8.2.100.0060.00622.08
8.2.90.0000.00719.20
8.2.80.0040.00417.97
8.2.70.0060.00317.63
8.2.60.0030.00617.93
8.2.50.0040.00418.07
8.2.40.0060.00320.01
8.2.30.0000.00718.14
8.2.20.0030.00617.74
8.2.10.0020.00518.02
8.2.00.0000.00817.69
8.1.280.0150.00925.92
8.1.270.0060.00323.95
8.1.260.0070.00026.35
8.1.250.0040.00428.09
8.1.240.0000.00923.77
8.1.230.0000.01119.21
8.1.220.0040.00417.78
8.1.210.0050.00318.77
8.1.200.0030.00717.36
8.1.190.0040.00417.23
8.1.180.0080.00018.10
8.1.170.0000.00818.50
8.1.160.0000.00722.03
8.1.150.0020.00518.95
8.1.140.0030.00517.45
8.1.130.0030.00317.81
8.1.120.0000.00817.39
8.1.110.0040.00417.51
8.1.100.0000.00717.46
8.1.90.0050.00217.51
8.1.80.0000.00717.39
8.1.70.0000.00717.45
8.1.60.0030.00617.56
8.1.50.0050.00317.55
8.1.40.0040.00417.50
8.1.30.0030.00517.52
8.1.20.0030.00617.67
8.1.10.0040.00417.61
8.1.00.0040.00417.53
8.0.300.0000.00818.77
8.0.290.0080.00016.75
8.0.280.0000.00718.45
8.0.270.0000.00717.19
8.0.260.0030.00317.27
8.0.250.0070.00016.95
8.0.240.0030.00317.03
8.0.230.0040.00416.83
8.0.220.0020.00516.92
8.0.210.0030.00316.95
8.0.200.0000.00616.86
8.0.190.0060.00317.03
8.0.180.0060.00316.85
8.0.170.0040.00416.96
8.0.160.0000.00716.90
8.0.150.0040.00416.80
8.0.140.0000.00816.79
8.0.130.0030.00313.38
8.0.120.0060.00316.88
8.0.110.0000.00716.96
8.0.100.0000.00716.85
8.0.90.0050.00316.76
8.0.80.0030.01316.88
8.0.70.0000.00716.74
8.0.60.0000.00816.87
8.0.50.0000.00716.80
8.0.30.0140.00516.90
8.0.20.0100.00717.40
8.0.10.0080.00016.82
8.0.00.0120.00616.80
7.4.330.0000.00515.20
7.4.320.0000.00716.55
7.4.300.0030.00316.70
7.4.290.0030.00316.61
7.4.280.0040.00416.51
7.4.270.0040.00416.62
7.4.260.0030.00316.66
7.4.250.0040.00416.61
7.4.240.0020.00516.61
7.4.230.0000.00716.38
7.4.220.0140.01016.50
7.4.210.0000.01516.56
7.4.200.0070.00016.66
7.4.160.0100.00616.54
7.4.150.0180.01617.40
7.4.140.0090.01117.86
7.4.130.0130.00616.60
7.4.120.0120.00416.58
7.4.110.0070.01016.50
7.4.100.0100.00716.60
7.4.90.0050.01416.53
7.4.80.0030.01819.39
7.4.70.0160.00616.68
7.4.60.0090.00916.51
7.4.50.0000.00816.54
7.4.40.0030.01516.71
7.4.30.0000.01716.36
7.4.10.0060.01314.94
7.4.00.0080.00914.88
7.3.330.0000.00613.33
7.3.320.0060.00013.25
7.3.310.0070.00016.42
7.3.300.0060.00016.21
7.3.290.0080.00616.44
7.3.280.0100.00516.39
7.3.270.0060.01017.40
7.3.260.0120.00916.35
7.3.250.0120.00516.59
7.3.240.0080.00816.62
7.3.230.0040.01416.43
7.3.210.0040.01316.68
7.3.200.0060.01219.39
7.3.190.0120.00916.41
7.3.180.0080.00816.57
7.3.170.0090.00616.40
7.3.160.0130.00316.33
7.3.130.0040.01515.19
7.3.120.0050.01214.97
7.3.110.0040.01114.91
7.3.100.0080.00614.80
7.3.90.0050.01014.82
7.3.80.0050.00914.81
7.3.70.0100.00214.83
7.3.60.0070.00714.86
7.3.50.0020.01214.84
7.3.40.0030.00714.74
7.3.30.0030.01114.72
7.3.20.0050.00916.74
7.3.10.0050.00716.79
7.3.00.0010.01016.72
7.2.330.0070.01116.81
7.2.320.0130.00316.59
7.2.310.0030.01416.78
7.2.300.0110.01116.78
7.2.290.0100.01016.70
7.2.260.0070.01015.24
7.2.250.0060.01114.97
7.2.240.0100.00615.21
7.2.230.0080.00615.15
7.2.220.0000.01114.96
7.2.210.0080.00614.94
7.2.200.0060.00815.07
7.2.190.0080.00614.86
7.2.180.0020.01015.06
7.2.170.0020.01015.06
7.2.160.0110.00615.30
7.2.150.0060.00916.96
7.2.140.0030.01016.93
7.2.130.0020.01416.85
7.2.120.0030.00917.13
7.2.110.0080.00416.87
7.2.100.0100.00516.95
7.2.90.0040.00817.05
7.2.80.0060.00917.06
7.2.70.0050.00716.64
7.2.60.0050.01116.99
7.2.50.0050.00816.80
7.2.40.0050.00616.98
7.2.30.0040.00817.05
7.2.20.0080.01017.09
7.2.10.0050.00717.03
7.2.00.0050.00817.05
7.1.330.0050.01215.63
7.1.320.0060.00715.73
7.1.310.0100.00415.89
7.1.300.0030.01015.76
7.1.290.0080.00615.80
7.1.280.0070.00515.79
7.1.270.0050.00815.79
7.1.260.0030.00715.65
7.1.250.0030.00815.73
7.1.240.0070.00715.61
7.1.230.0040.00815.80
7.1.220.0040.01115.83
7.1.210.0030.01415.88
7.1.200.0090.00315.82
7.1.190.0000.01015.52
7.1.180.0030.00615.71
7.1.170.0060.00315.95
7.1.160.0040.00815.94
7.1.150.0030.00916.01
7.1.140.0130.00315.95
7.1.130.0040.01415.96
7.1.120.0060.01215.73
7.1.110.0070.01015.74
7.1.100.0030.01015.84
7.1.90.0070.00315.88
7.1.80.0000.00916.00
7.1.70.0030.00916.38
7.1.60.0060.01317.57
7.1.50.0050.01316.55
7.1.40.0030.00615.61
7.1.30.0060.00615.69
7.1.20.0030.01215.79
7.1.10.0100.00015.94
7.1.00.0070.03819.13
7.0.330.0040.00715.37
7.0.320.0000.01115.46
7.0.310.0060.00615.34
7.0.300.0100.00315.54
7.0.290.0030.01015.38
7.0.280.0090.00015.45
7.0.270.0070.01015.57
7.0.260.0030.00615.46
7.0.250.0030.00715.54
7.0.240.0060.00915.11
7.0.230.0070.00315.29
7.0.220.0090.00615.45
7.0.210.0040.01115.40
7.0.200.0070.00416.09
7.0.190.0040.00415.62
7.0.180.0070.00715.49
7.0.170.0060.00915.41
7.0.160.0090.00615.54
7.0.150.0030.00915.24
7.0.140.0090.03318.72
7.0.130.0110.00715.48
7.0.120.0110.00715.30
7.0.110.0030.01415.35
7.0.100.0030.01415.43
7.0.90.0040.00815.25
7.0.80.0060.01015.24
7.0.70.0030.01615.54
7.0.60.0110.03317.59
7.0.50.0050.04316.64
7.0.40.0050.04416.83
7.0.30.0120.03016.87
7.0.20.0150.03616.85
7.0.10.0080.03416.81
7.0.00.0070.03216.83
5.6.400.0090.00614.26
5.6.390.0070.00714.61
5.6.380.0070.00714.41
5.6.370.0070.00714.27
5.6.360.0030.00914.46
5.6.350.0060.00314.41
5.6.340.0000.01814.80
5.6.330.0070.00714.56
5.6.320.0040.00814.21
5.6.310.0070.00714.39
5.6.300.0060.00314.64
5.6.290.0080.00414.27
5.6.280.0080.03717.75
5.6.270.0130.00714.28
5.6.260.0070.01114.54
5.6.250.0040.00814.34
5.6.240.0030.01014.37
5.6.230.0100.00714.27
5.6.220.0070.01114.18
5.6.210.0080.04117.54
5.6.200.0070.03516.36
5.6.190.0050.04617.64
5.6.180.0110.03117.54
5.6.170.0100.04417.64
5.6.160.0070.03417.36
5.6.150.0120.04216.29
5.6.140.0020.03216.21
5.6.130.0050.02316.43
5.6.120.0100.03517.78
5.6.110.0030.04917.77
5.6.100.0130.04317.77
5.6.90.0120.04017.83
5.6.80.0050.02517.31
5.6.70.0080.01014.27
5.6.60.0080.00814.15
5.6.50.0000.01614.36
5.6.40.0070.00714.49
5.6.30.0080.00314.38
5.6.20.0070.00714.35
5.6.10.0090.00914.34
5.6.00.0000.01614.18
5.5.380.0000.01114.70
5.5.370.0140.00714.48
5.5.360.0070.00714.13
5.5.350.0180.03817.55
5.5.340.0110.02916.35
5.5.330.0070.03317.33
5.5.320.0220.03817.34
5.5.310.0170.03817.55
5.5.300.0100.04116.34
5.5.290.0070.02816.14
5.5.280.0130.04317.49
5.5.270.0100.04317.60
5.5.260.0120.03517.62
5.5.250.0150.03817.21
5.5.240.0070.04217.24
5.5.230.0080.00614.47
5.5.220.0080.00414.32
5.5.210.0030.00614.09
5.5.200.0000.01414.51
5.5.190.0030.00614.18
5.5.180.0090.00014.49
5.5.170.0030.01114.40
5.5.160.0030.00914.23
5.5.150.0050.00514.17
5.5.140.0060.00914.51
5.5.130.0040.01114.24
5.5.120.0080.00414.39
5.5.110.0030.01014.54
5.5.100.0070.00714.51
5.5.90.0030.01014.19
5.5.80.0100.00314.46
5.5.70.0070.00714.33
5.5.60.0090.00313.98
5.5.50.0090.00613.86
5.5.40.0030.00614.43
5.5.30.0070.01014.18
5.5.20.0040.01114.45
5.5.10.0030.00614.39
5.5.00.0030.00914.43
5.4.450.0050.03215.37
5.4.440.0290.03415.34
5.4.430.0420.03215.41
5.4.420.0350.03015.42
5.4.410.0090.02615.15
5.4.400.0220.02814.84
5.4.390.0230.03214.99
5.4.380.0070.02714.73
5.4.370.0100.02614.94
5.4.360.0070.01914.98
5.4.350.0050.02711.61
5.4.340.0030.02711.41
5.4.330.0070.00711.11
5.4.320.0030.02311.70
5.4.310.0090.01911.72
5.4.300.0060.02111.75
5.4.290.0040.02411.71
5.4.280.0070.02311.70
5.4.270.0030.02311.73
5.4.260.0070.02211.61
5.4.250.0060.02011.86
5.4.240.0080.02111.74
5.4.230.0060.02211.63
5.4.220.0060.02011.73
5.4.210.0060.02311.74
5.4.200.0080.02511.64
5.4.190.0080.02011.76
5.4.180.0070.02111.80
5.4.170.0030.02611.67
5.4.160.0040.02411.79
5.4.150.0050.02311.83
5.4.140.0040.02311.47
5.4.130.0040.02111.69
5.4.120.0090.02211.68
5.4.110.0050.02311.50
5.4.100.0020.02811.61
5.4.90.0050.02911.52
5.4.80.0040.02311.44
5.4.70.0050.01911.44
5.4.60.0060.02011.63
5.4.50.0050.01911.53
5.4.40.0030.02511.59
5.4.30.0060.02011.57
5.4.20.0100.01911.59
5.4.10.0040.02411.54
5.4.00.0050.02311.38
5.3.290.0080.03712.80
5.3.280.0100.03412.71
5.3.270.0050.04012.73
5.3.260.0060.03912.72
5.3.250.0070.03712.72
5.3.240.0060.03812.72
5.3.230.0100.03412.71
5.3.220.0100.04612.68
5.3.210.0070.03812.68
5.3.200.0050.03912.68
5.3.190.0070.04612.68
5.3.180.0060.03712.68
5.3.170.0040.03812.67
5.3.160.0060.03712.67
5.3.150.0030.04012.68
5.3.140.0080.03412.66
5.3.130.0050.04012.65
5.3.120.0080.03612.66
5.3.110.0030.04212.66
5.3.100.0070.03612.12
5.3.90.0050.03812.10
5.3.80.0040.03812.09
5.3.70.0020.04012.09
5.3.60.0040.03912.08
5.3.50.0060.03612.03
5.3.40.0040.03912.02
5.3.30.0050.04011.98
5.3.20.0060.03911.77
5.3.10.0090.03511.73
5.3.00.0030.04011.71
5.2.170.0060.0299.22
5.2.160.0060.0279.22
5.2.150.0060.0289.22
5.2.140.0060.0299.22
5.2.130.0020.0319.18
5.2.120.0040.0289.18
5.2.110.0040.0299.19
5.2.100.0070.0319.18
5.2.90.0040.0299.18
5.2.80.0070.0279.18
5.2.70.0040.0319.18
5.2.60.0040.0309.13
5.2.50.0060.0289.10
5.2.40.0050.0289.07
5.2.30.0050.0339.05
5.2.20.0070.0269.04
5.2.10.0060.0268.95
5.2.00.0050.0288.82
5.1.60.0050.0238.09
5.1.50.0020.0278.08
5.1.40.0040.0248.07
5.1.30.0000.0318.42
5.1.20.0050.0268.44
5.1.10.0040.0268.16
5.1.00.0040.0308.17
5.0.50.0030.0216.66
5.0.40.0040.0196.52
5.0.30.0040.0316.32
5.0.20.0050.0186.30
5.0.10.0040.0196.28
5.0.00.0030.0306.27
4.4.90.0040.0144.77
4.4.80.0020.0154.75
4.4.70.0040.0144.75
4.4.60.0010.0164.75
4.4.50.0030.0154.77
4.4.40.0020.0264.71
4.4.30.0020.0164.75
4.4.20.0030.0154.85
4.4.10.0020.0164.85
4.4.00.0030.0244.76
4.3.110.0020.0164.67
4.3.100.0030.0144.67
4.3.90.0040.0134.64
4.3.80.0010.0264.59
4.3.70.0030.0144.63
4.3.60.0030.0144.63
4.3.50.0040.0144.63
4.3.40.0020.0244.54
4.3.30.0010.0173.32
4.3.20.0020.0163.30
4.3.10.0030.0153.26
4.3.00.0130.0207.13

preferences:
47.14 ms | 401 KiB | 5 Q