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; } 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.0100.00716.88
8.3.50.0130.01022.84
8.3.40.0110.00418.83
8.3.30.0030.01019.04
8.3.20.0070.00020.25
8.3.10.0040.00423.63
8.3.00.0040.00419.38
8.2.180.0070.00716.75
8.2.170.0110.01122.96
8.2.160.0110.00320.45
8.2.150.0000.00824.18
8.2.140.0080.00024.66
8.2.130.0110.00726.16
8.2.120.0080.00019.61
8.2.110.0060.00320.56
8.2.100.0070.00417.91
8.2.90.0040.00418.08
8.2.80.0080.00017.97
8.2.70.0000.00817.63
8.2.60.0000.00817.93
8.2.50.0050.00518.07
8.2.40.0060.00318.22
8.2.30.0040.00418.01
8.2.20.0030.00617.88
8.2.10.0070.00018.13
8.2.00.0000.00817.71
8.1.280.0060.01025.92
8.1.270.0000.00823.78
8.1.260.0000.00726.35
8.1.250.0070.00028.09
8.1.240.0040.00422.14
8.1.230.0070.00420.83
8.1.220.0000.00817.74
8.1.210.0050.00318.98
8.1.200.0060.00317.34
8.1.190.0040.00417.35
8.1.180.0080.00018.10
8.1.170.0040.00418.45
8.1.160.0040.00421.94
8.1.150.0000.00718.80
8.1.140.0030.00617.46
8.1.130.0030.00317.75
8.1.120.0040.00417.44
8.1.110.0050.00217.36
8.1.100.0050.00217.53
8.1.90.0030.00317.41
8.1.80.0000.00717.50
8.1.70.0070.00017.36
8.1.60.0060.00317.53
8.1.50.0060.00317.44
8.1.40.0040.00417.44
8.1.30.0000.00817.70
8.1.20.0040.00417.54
8.1.10.0070.00017.54
8.1.00.0030.00617.49
8.0.300.0030.00520.07
8.0.290.0050.00216.63
8.0.280.0040.00418.46
8.0.270.0030.00317.14
8.0.260.0000.00717.18
8.0.250.0070.00017.03
8.0.240.0030.00316.90
8.0.230.0000.00717.01
8.0.220.0000.00716.88
8.0.210.0030.00316.85
8.0.200.0040.00417.01
8.0.190.0000.00817.04
8.0.180.0040.00416.86
8.0.170.0000.00817.01
8.0.160.0040.00416.87
8.0.150.0040.00416.91
8.0.140.0040.00416.95
8.0.130.0030.00513.47
8.0.120.0000.00716.89
8.0.110.0000.00716.87
8.0.100.0000.00716.84
8.0.90.0000.00716.96
8.0.80.0040.01816.92
8.0.70.0070.00016.85
8.0.60.0000.00817.03
8.0.50.0040.00416.99
8.0.30.0120.00616.96
8.0.20.0150.00417.40
8.0.10.0030.00417.13
8.0.00.0070.01016.88
7.4.330.0020.00215.09
7.4.320.0030.00316.50
7.4.300.0030.00316.50
7.4.290.0030.00316.58
7.4.280.0000.00716.63
7.4.270.0030.00316.66
7.4.260.0030.00416.46
7.4.250.0040.00416.48
7.4.240.0000.00716.58
7.4.230.0000.00716.68
7.4.220.0090.00916.53
7.4.210.0000.01616.55
7.4.200.0000.00716.39
7.4.160.0080.00816.45
7.4.150.0070.01117.40
7.4.140.0100.00717.86
7.4.130.0090.00916.47
7.4.120.0100.00716.63
7.4.110.0040.01416.58
7.4.100.0110.00716.53
7.4.90.0100.01016.66
7.4.80.0080.01119.39
7.4.70.0100.01316.66
7.4.60.0030.01316.61
7.4.50.0030.00516.56
7.4.40.0150.00316.70
7.4.30.0060.01016.42
7.4.00.0070.00714.81
7.3.330.0000.00713.35
7.3.320.0000.00513.42
7.3.310.0030.00316.52
7.3.300.0000.00716.47
7.3.290.0030.01216.46
7.3.280.0070.00816.41
7.3.270.0170.00617.40
7.3.260.0140.00416.43
7.3.250.0100.00816.48
7.3.240.0090.00616.54
7.3.230.0100.00716.62
7.3.210.0110.00616.52
7.3.200.0030.01419.39
7.3.190.0110.01216.60
7.3.180.0090.00616.46
7.3.170.0090.00816.42
7.3.160.0090.00916.57
7.2.330.0140.00316.72
7.2.320.0060.01516.60
7.2.310.0080.00816.75
7.2.300.0100.00716.63
7.2.290.0130.00716.73
7.2.80.0230.00016.27
7.2.60.0040.00416.92
7.2.00.0030.01219.59
7.1.200.0030.01215.94
7.1.100.0000.01118.06
7.1.70.0000.00717.12
7.1.60.0040.02219.40
7.1.50.0070.01717.05
7.1.00.0070.07322.31
7.0.200.0080.00016.79
7.0.140.0070.07021.95
7.0.60.0130.07720.06
7.0.50.0130.08317.89
7.0.40.0100.05720.20
7.0.30.0270.07020.07
7.0.20.0270.08320.23
7.0.10.0370.07720.23
7.0.00.0130.07320.23
5.6.280.0030.07020.82
5.6.210.0130.07020.47
5.6.200.0100.06318.29
5.6.190.0030.04720.65
5.6.180.0070.08020.49
5.6.170.0370.05020.54
5.6.160.0270.06320.46
5.6.150.0000.09018.28
5.6.140.0000.07318.26
5.6.130.0000.06718.23
5.6.120.0130.03321.12
5.6.110.0030.08321.14
5.6.100.0200.07320.99
5.6.90.0100.05020.99
5.6.80.0130.07320.52
5.6.70.0030.06320.42
5.5.350.0270.07320.39
5.5.340.0030.05018.05
5.5.330.0100.03720.27
5.5.320.0300.03020.21
5.5.310.0270.05020.38
5.5.300.0000.04017.95
5.5.290.0030.06017.95
5.5.280.0100.03720.66
5.5.270.0070.04020.96
5.5.260.0130.08020.79
5.5.250.0070.08020.61
5.5.240.0030.05320.29
5.4.450.0070.06719.63
5.4.440.0900.07319.58
5.4.430.0170.05019.63
5.4.420.0830.05719.28
5.4.410.0170.04718.64
5.4.400.1100.05318.75
5.4.390.1100.04318.73
5.4.380.0070.05318.72
5.4.370.0130.04018.75
5.4.360.0070.04018.63
5.4.350.0120.05912.02
5.4.340.0050.03812.02
5.4.320.0060.03712.50
5.4.310.0050.04012.50
5.4.300.0050.03812.50
5.4.290.0090.03512.50
5.4.280.0050.03612.40
5.4.270.0080.03512.39
5.4.260.0110.03812.39
5.4.250.0060.03912.40
5.4.240.0080.03512.40
5.4.230.0090.03512.39
5.4.220.0090.03612.39
5.4.210.0070.03512.39
5.4.200.0070.03712.39
5.4.190.0040.03812.38
5.4.180.0080.03512.39
5.4.170.0080.03612.39
5.4.160.0090.03312.39
5.4.150.0060.03612.38
5.4.140.0050.03912.07
5.4.130.0030.03812.06
5.4.120.0040.03612.02
5.4.110.0040.03712.01
5.4.100.0050.03612.01
5.4.90.0050.03812.01
5.4.80.0080.03912.01
5.4.70.0050.03512.01
5.4.60.0070.04112.01
5.4.50.0080.03612.01
5.4.40.0060.03512.00
5.4.30.0090.03211.99
5.4.20.0030.03712.00
5.4.10.0040.03511.99
5.4.00.0050.03511.48
5.3.290.0070.03812.80
5.3.280.0090.03512.70
5.3.270.0070.03812.72
5.3.260.0060.03812.72
5.3.250.0050.03812.71
5.3.240.0090.03412.72
5.3.230.0060.04112.71
5.3.220.0070.04612.68
5.3.210.0050.04012.68
5.3.200.0040.03812.68
5.3.190.0060.03812.68
5.3.180.0060.03912.67
5.3.170.0080.04112.67
5.3.160.0040.03812.67
5.3.150.0040.04012.68
5.3.140.0050.03812.66
5.3.130.0090.03612.66
5.3.120.0070.03712.66
5.3.110.0040.04012.66
5.3.100.0030.04012.13
5.3.90.0060.03512.11
5.3.80.0080.03412.09
5.3.70.0060.03612.09
5.3.60.0080.03412.09
5.3.50.0060.03512.02
5.3.40.0040.03912.02
5.3.30.0070.03611.98
5.3.20.0060.04011.77
5.3.10.0070.04011.73
5.3.00.0040.03911.71
5.2.170.0090.0269.22
5.2.160.0010.0329.22
5.2.150.0070.0279.23
5.2.140.0040.0309.22
5.2.130.0030.0309.18
5.2.120.0070.0259.18
5.2.110.0040.0319.19
5.2.100.0050.0289.19
5.2.90.0040.0299.18
5.2.80.0050.0299.18
5.2.70.0070.0279.18
5.2.60.0020.0329.13
5.2.50.0050.0309.10
5.2.40.0050.0289.07
5.2.30.0090.0259.05
5.2.20.0040.0299.04
5.2.10.0060.0278.96
5.2.00.0030.0308.81
5.1.60.0040.0238.09
5.1.50.0020.0278.09
5.1.40.0060.0228.07
5.1.30.0080.0228.42
5.1.20.0060.0258.44
5.1.10.0050.0258.16
5.1.00.0060.0248.16
5.0.50.0020.0236.66
5.0.40.0030.0226.52
5.0.30.0050.0326.32
5.0.20.0010.0226.29
5.0.10.0030.0206.28
5.0.00.0030.0306.28
4.4.90.0020.0154.78
4.4.80.0020.0154.76
4.4.70.0030.0154.75
4.4.60.0030.0154.76
4.4.50.0040.0134.77
4.4.40.0070.0214.71
4.4.30.0010.0174.76
4.4.20.0040.0144.84
4.4.10.0020.0164.85
4.4.00.0030.0244.76
4.3.110.0030.0154.67
4.3.100.0020.0164.66
4.3.90.0020.0174.63
4.3.80.0010.0254.58
4.3.70.0030.0144.63
4.3.60.0020.0154.63
4.3.50.0010.0174.62
4.3.40.0030.0264.54
4.3.30.0020.0193.32
4.3.20.0020.0183.30
4.3.10.0010.0163.25
4.3.00.0030.0207.06

preferences:
45.44 ms | 401 KiB | 5 Q