3v4l.org

run code in 300+ PHP versions simultaneously
<?php function stringMultiplicate($first, $second) { // Create array include result of 1 number in $second string * first $result = []; $strFirst = (string)$first; $strSecond = (string)$second; $maxLength = 0; for ($i = strlen($strSecond) - 1; $i >= 0; $i--) { $index = $i; $number = (int)$strSecond[$i]; $result[$index] = ''; $k = strlen($strSecond) - 1 - $i; $div = 0; for ($j = (strlen($strFirst) - 1); $j >= 0; $j--) { while ($k != 0) { $result[$index] .= '0'; $k--; } $next = ($number * $strFirst[$j] + $div); if (strlen($next) > 1 && $j != 0) { $result[$index] .= ((string)$next)[strlen($next) - 1]; $div = ((string)$next)[0]; } else { $result[$index] .= $number * $strFirst[$j] + $div; $div = 0; } } if (strlen($result[$index]) > $maxLength) { $maxLength = $result[$index]; } $result[$index] = strrev($result[$index]); } $multi = []; for ($j = 0; $j < $maxLength; $j++) { $sum = 0; for ($i = 0; $i < count($result); $i++) { var_dump($result[$i]); if (!isset($result[$i][$j])) { $result[$i][$j] = 0; } $sum += (int)$result[$i][$j]; } $multi[$i] = $sum; } return $multi; } var_dump(stringMultiplicate(12345, 123)); var_dump(12345*123);

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.0340.00020.14
8.3.50.0270.00918.07
8.3.40.0240.00819.75
8.3.30.0160.01319.26
8.2.180.0280.00518.04
8.2.170.0200.02020.64
8.2.160.0300.00620.14
8.1.280.0210.00425.92
7.4.90.0260.01416.38
7.4.80.0440.01517.88
7.4.70.0670.02616.33
7.4.60.0380.01816.56
7.4.50.0330.00916.33
7.4.40.0280.01216.46
7.4.30.0350.01416.36
7.4.20.0660.00616.55
7.4.10.0250.00816.32
7.4.00.0590.01015.45
7.3.210.0490.01516.24
7.3.200.0280.00916.44
7.3.190.0320.00616.52
7.3.180.0500.02916.46
7.3.170.0330.02416.61
7.3.160.0520.01616.32
7.3.150.0240.01116.23
7.3.140.0220.01316.60
7.3.130.0190.01616.36
7.3.120.0230.00816.55
7.3.110.0210.01216.12
7.3.100.0860.01516.56
7.3.90.1330.00016.24
7.3.80.0930.03216.25
7.3.70.0390.01516.20
7.3.60.0550.02616.38
7.3.50.0190.01616.34
7.3.40.0460.00916.32
7.3.30.0370.01616.30
7.3.20.0360.01316.44
7.3.10.0150.01516.48
7.3.00.1010.00916.35
7.2.330.0490.00416.48
7.2.320.0280.02516.52
7.2.310.0270.01716.64
7.2.300.0420.01716.62
7.2.290.0560.01516.60
7.2.280.0510.00416.30
7.2.270.0470.01116.71
7.2.260.0270.00816.47
7.2.250.0410.02616.45
7.2.240.0290.01816.80
7.2.230.0180.01416.70
7.2.220.0430.01816.50
7.2.210.0280.00816.58
7.2.200.0070.01316.74
7.2.190.0250.01316.61
7.2.180.0180.01916.58
7.2.170.0270.01816.58
7.2.160.0260.01816.48
7.2.150.0350.03716.45
7.2.140.0450.01216.49
7.2.130.0130.01616.33
7.2.120.0320.01115.66
7.2.110.0160.01215.67
7.2.100.0270.00715.75
7.2.90.0320.00815.62
7.2.80.0420.01215.72
7.2.70.0420.01415.84
7.2.60.0370.02015.83
7.2.50.0180.01715.96
7.2.40.0610.00815.89
7.2.30.0340.01415.96
7.2.20.0430.02015.84
7.2.10.0480.01515.79
7.2.00.1660.01315.77
7.1.330.0210.01415.43
7.1.320.0300.00315.60
7.1.310.0580.01915.74
7.1.300.0320.01515.57
7.1.290.0990.02015.49
7.1.280.0280.03415.70
7.1.270.0460.01515.50
7.1.260.0460.01115.50
7.1.250.0330.00715.52
7.1.240.0240.02315.61
7.1.230.0610.00015.61
7.1.220.0340.01315.37
7.1.210.0390.02015.57
7.1.200.0390.01615.47
7.1.190.0680.01815.54
7.1.180.0660.00815.34
7.1.170.0360.02115.41
7.1.160.0350.00815.59
7.1.150.0440.01215.71
7.1.140.1120.01115.34
7.1.130.0570.02215.48
7.1.120.0430.01715.65
7.1.110.0710.02415.53
7.1.100.0550.03715.37
7.1.90.0300.01415.55
7.1.80.0480.01615.44
7.1.70.0590.02215.65
7.1.60.0400.00415.60
7.1.50.0360.00615.40
7.1.40.0480.01615.70
7.1.30.0420.01515.47
7.1.20.0420.01315.77
7.1.10.0300.00715.41
7.1.00.0350.01715.55
7.0.330.0480.01214.35
7.0.320.0400.01815.09
7.0.310.0780.02414.94
7.0.300.0300.01314.98
7.0.290.0350.01715.39
7.0.280.0350.01515.43
7.0.270.0990.02515.27
7.0.260.0540.01515.35
7.0.250.1060.03415.30
7.0.240.0340.01315.23
7.0.230.0750.04315.26
7.0.220.0520.00414.98
7.0.210.0690.01515.20
7.0.200.0340.01515.39
7.0.190.0470.01115.32
7.0.180.0580.04315.42
7.0.170.0220.02115.40
7.0.160.0500.00715.08
7.0.150.0350.01115.17
7.0.140.1090.00515.44
7.0.130.0500.01215.12
7.0.120.0260.02215.43
7.0.110.0300.02215.29
7.0.100.1020.01715.40
7.0.90.0660.01215.36
7.0.80.0420.01215.28
7.0.70.0380.01115.37
7.0.60.0640.02415.39
7.0.50.0320.01315.32
7.0.40.0310.02215.23
7.0.30.0890.02415.29
7.0.20.0570.01015.33
7.0.10.0710.03115.37
7.0.00.0450.02715.35
5.6.400.0130.01315.58
5.6.390.0140.01415.96
5.6.380.0070.01214.77
5.6.370.0060.02015.63
5.6.360.0170.00915.45
5.6.350.0150.00815.47
5.6.340.0210.01115.55
5.6.330.0200.00715.54
5.6.320.0190.00815.72
5.6.310.0180.00915.61
5.6.300.0220.01515.81
5.6.290.0270.00615.96
5.6.280.0220.01015.65
5.6.270.0220.01015.76
5.6.260.0270.01015.59
5.6.250.0150.01515.79
5.6.240.0240.00815.71
5.6.230.0290.00415.75
5.6.220.0130.01915.69
5.6.210.0190.01215.74
5.6.200.0200.01715.72
5.6.190.0170.01415.65
5.6.180.0220.00815.73
5.6.170.0240.01215.75
5.6.160.0200.01015.90
5.6.150.0270.00415.60
5.6.140.0280.00615.82
5.6.130.0200.01415.50
5.6.120.0210.00915.52
5.6.110.0360.01115.64
5.6.100.0260.00715.63
5.6.90.0230.01015.63
5.6.80.0230.01415.42
5.6.70.0180.01215.46
5.6.60.0230.00815.55
5.6.50.0200.01015.57
5.6.40.0180.01115.38
5.6.30.0210.01215.68
5.6.20.0150.01215.50
5.6.10.0190.00915.59
5.6.00.0210.00815.66

preferences:
65.74 ms | 401 KiB | 5 Q