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[$j] = $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.0260.00620.13
8.3.50.0150.00617.95
8.3.40.0130.00718.74
8.3.30.0320.00818.82
8.3.20.0000.01123.48
8.3.10.0140.00723.46
8.3.00.0040.00821.73
8.2.180.0290.00818.16
8.2.170.0230.00022.96
8.2.160.0220.00619.07
8.2.150.0110.00624.18
8.2.140.0060.01124.66
8.2.130.0140.00519.66
8.2.120.0160.01626.35
8.2.110.0190.00019.25
8.2.100.0080.00817.72
8.2.90.0080.00517.63
8.2.80.0030.00617.97
8.2.70.0060.00318.03
8.2.60.0030.00618.09
8.2.50.0040.00818.10
8.2.40.0080.00821.21
8.2.30.0080.00419.48
8.2.20.0050.00518.17
8.2.10.0100.00319.66
8.2.00.0070.00219.51
8.1.280.0170.01025.92
8.1.270.0170.00018.78
8.1.260.0210.00026.35
8.1.250.0050.01028.09
8.1.240.0060.00622.69
8.1.230.0180.00519.61
8.1.220.0000.01117.74
8.1.210.0040.00718.77
8.1.200.0100.00217.38
8.1.190.0000.01217.25
8.1.180.0060.00618.10
8.1.170.0080.00418.48
8.1.160.0030.00619.00
8.1.150.0080.00418.93
8.1.140.0120.00023.93
8.1.130.0100.00520.24
8.1.120.0060.00617.50
8.1.110.0040.00817.56
8.1.100.0060.00317.42
8.1.90.0090.00317.58
8.1.80.0000.00917.61
8.1.70.0110.00417.53
8.1.60.0040.00817.70
8.1.50.0040.00817.61
8.1.40.0000.01417.51
8.1.30.0060.00617.70
8.1.20.0090.00017.59
8.1.10.0100.00317.73
8.1.00.0040.00817.62
8.0.300.0110.00018.77
8.0.290.0110.00016.63
8.0.280.0100.00318.45
8.0.270.0110.00517.15
8.0.260.0070.00318.43
8.0.250.0080.00417.02
8.0.240.0060.00616.93
8.0.230.0050.00316.98
8.0.220.0000.00816.95
8.0.210.0050.00516.83
8.0.200.0090.00316.98
8.0.190.0070.00417.04
8.0.180.0080.00416.97
8.0.170.0080.00816.93
8.0.160.0040.00816.88
8.0.150.0060.00616.74
8.0.140.0080.00416.79
8.0.130.0000.00913.52
8.0.120.0120.00016.78
8.0.110.0080.00416.89
8.0.100.0050.00516.86
8.0.90.0050.00516.76
8.0.80.0300.00616.93
8.0.70.0000.01316.94
8.0.60.0000.01216.74
8.0.50.0000.01216.72
8.0.30.0140.01417.04
8.0.20.0110.02217.41
8.0.10.0080.00417.07
8.0.00.0350.01816.85
7.4.330.0100.00016.68
7.4.320.0040.00816.56
7.4.300.0110.00016.53
7.4.290.0050.00516.54
7.4.280.0070.00716.42
7.4.270.0040.00716.44
7.4.260.0000.01116.41
7.4.250.0100.00516.48
7.4.240.0040.00816.48
7.4.230.0060.00616.43
7.4.220.0110.00016.63
7.4.210.0120.01816.46
7.4.200.0050.00516.42
7.4.160.0300.01316.46
7.4.140.0340.01117.86
7.4.130.0320.00316.40
7.4.120.0240.01616.51
7.4.110.0230.02316.53
7.4.100.0140.02116.54
7.4.90.0440.00516.46
7.4.80.0510.01719.39
7.4.70.1290.02216.33
7.4.60.0530.01116.47
7.4.50.0320.00616.50
7.4.40.0770.02416.40
7.4.00.0100.00714.52
7.3.330.0070.00313.38
7.3.320.0000.01013.21
7.3.310.0050.00516.25
7.3.300.0000.01116.34
7.3.290.0070.00416.22
7.3.280.0120.01716.35
7.3.260.0280.01016.39
7.3.240.0250.01316.44
7.3.230.0110.01816.28
7.3.210.0600.01116.48
7.3.200.0230.00816.57
7.3.190.0500.02216.59
7.3.180.0320.00616.44
7.3.170.0560.03316.56
7.3.160.0160.01216.48
7.3.00.0120.00516.12
7.2.330.0750.02416.55
7.2.320.0360.01016.38
7.2.310.0640.01016.53
7.2.300.0340.01216.49
7.2.290.0420.00816.74
7.2.130.0120.01016.46
7.2.120.0150.00716.43
7.2.110.0140.00616.52
7.2.100.0120.00816.64
7.2.90.0100.01116.54
7.2.80.0150.00416.48
7.2.70.0100.01116.72
7.2.60.0100.01116.80
7.2.50.0120.00816.86
7.2.40.0190.00316.79
7.2.30.2620.00616.85
7.2.20.0110.01116.83
7.2.10.0080.01316.81
7.2.00.0120.00916.93
7.1.250.0140.00915.60
7.0.330.0120.00815.61
5.6.380.0100.00513.98

preferences:
58.9 ms | 401 KiB | 5 Q