3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Str { /** PHPの組み込み関数の第一引数に使う値をプロパティとしてセット */ public function __construct( public string $str ){} /** * このクラスで外部に公開していない名前のメソッドが呼ばれた場合に動作するマジックメソッド * @see https://www.php.net/manual/ja/language.oop5.overloading.php#object.call */ public function __call($name, $arguments) { // 呼ばれたメソッド名の関数を第一引数を最初に与えたプロパティ、 // 第二引数以降を呼ばれた際の引数として実行 $result = $name($this->str, ...$arguments); // 関数の返り値が文字列ならば返り値を元に自身のインスタンスを生成して返却 // 関数の返り値が文字列でないならば返り値をそのまま返却 return is_string($result) ? new self($result) : $result; } /** __call に処理を渡さず、第二引数にプロパティの値を渡して explode 関数を実行するメソッドを用意する */ public function explode(string $separator, ?int $limit = PHP_INT_MAX) { return explode($separator, $this->str, $limit); } } $s = new Str('hoge'); $res = $s->substr(0, 2) ->strtoupper() ->str_pad(4, '0', STR_PAD_LEFT) ->explode('H'); var_dump($res); /* array(2) { [0]=> string(2) "00" [1]=> string(1) "O" } */

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.4.20.0170.00019.55
8.4.10.0060.00322.00
8.3.150.0100.01016.71
8.3.140.0080.00018.95
8.3.130.0090.00018.59
8.3.120.0090.00020.72
8.3.110.0100.00020.94
8.3.100.0040.00424.06
8.3.90.0080.00026.77
8.3.80.0000.01016.38
8.3.70.0070.00716.58
8.3.60.0070.00716.48
8.3.50.0090.00619.90
8.3.40.0100.00318.79
8.3.30.0120.00319.47
8.3.20.0040.00424.18
8.3.10.0090.00024.66
8.3.00.0040.00426.16
8.2.260.0070.00716.61
8.2.250.0040.00416.83
8.2.240.0030.00617.41
8.2.230.0080.00022.58
8.2.220.0000.00837.54
8.2.210.0110.00926.77
8.2.200.0030.00616.50
8.2.190.0210.00018.29
8.2.180.0070.00725.92
8.2.170.0130.00718.85
8.2.160.0100.00722.96
8.2.150.0040.00425.66
8.2.140.0070.00024.66
8.2.130.0080.00026.16
8.2.120.0080.00021.00
8.2.110.0200.00720.95
8.2.100.0040.00817.91
8.2.90.0080.00017.75
8.2.80.0080.00018.59
8.2.70.0050.00317.63
8.2.60.0060.00317.50
8.2.50.0040.00417.98
8.2.40.0040.00418.09
8.2.30.0020.00517.95
8.2.20.0000.00720.52
8.2.10.0000.00717.93
8.2.00.0030.00719.31
8.1.310.0070.01018.43
8.1.300.0030.00618.66
8.1.290.0050.00530.84
8.1.280.0070.01025.92
8.1.270.0020.00523.99
8.1.260.0080.00026.35
8.1.250.0080.00028.09
8.1.240.0110.01119.00
8.1.230.0060.00621.10
8.1.220.0040.00418.47
8.1.210.0040.00418.77
8.1.200.0000.00917.38
8.1.190.0060.00317.22
8.1.180.0030.00618.10
8.1.170.0040.00417.62
8.1.160.0040.00418.86
8.1.150.0000.00818.51
8.1.140.0040.00417.35
8.1.130.0050.00217.41
8.1.120.0070.00017.36
8.1.110.0040.00417.30
8.1.100.0000.00717.31
8.1.90.0000.00917.35
8.1.80.0060.00317.35
8.1.70.0040.00417.39
8.1.60.0000.00817.48
8.1.50.0090.00517.41
8.1.40.0160.00517.55
8.1.30.0100.00717.48
8.1.20.0090.00217.65
8.1.10.0050.00817.57
8.1.00.0110.00017.50
8.0.300.0040.00419.77
8.0.290.0040.00416.63
8.0.280.0030.00318.40
8.0.270.0000.00716.82
8.0.260.0000.00816.80
8.0.250.0070.00016.83
8.0.240.0000.00716.93
8.0.230.0030.00616.83
8.0.220.0000.00816.75
8.0.210.0080.00016.87
8.0.200.0000.00816.82
8.0.190.0040.00416.88
8.0.180.0130.00416.91
8.0.170.0140.00416.74
8.0.160.0170.00316.82
8.0.150.0130.00816.80
8.0.140.0150.00516.75
8.0.130.0130.00616.87
8.0.120.0100.01016.90
8.0.110.0140.00716.89
8.0.100.0220.00316.81
8.0.90.0190.00516.74
8.0.80.0240.00016.89
8.0.70.0220.00416.76
8.0.60.0220.00316.75
8.0.50.0220.00016.69
8.0.30.0150.00616.81
8.0.20.0130.00816.94
8.0.10.0030.01116.99
7.4.330.0050.00015.55
7.4.320.0000.00816.45
7.4.300.0030.00316.37
7.4.290.0090.00516.46
7.4.280.0140.00316.37
7.4.270.0190.00016.41
7.4.260.0170.00616.35
7.4.250.0160.00516.41
7.4.240.0170.00316.46
7.4.230.0170.00416.45
7.4.220.0140.00316.44
7.4.210.0160.00316.40
7.4.200.0150.00416.40
7.4.190.0140.00316.47
7.4.180.0140.00316.51
7.4.160.0140.00516.50
7.4.150.0110.00716.35
7.4.140.0160.00316.31
7.4.130.0160.00316.25
7.4.120.0110.00716.16
7.4.110.0140.00516.23
7.4.100.0160.00316.45
7.4.90.0150.00416.16
7.4.80.0040.00716.21
7.4.70.0090.00316.28
7.4.60.0000.01016.28
7.4.50.0100.00316.15
7.4.40.0070.00716.23
7.4.30.0090.00416.29
7.4.20.0050.00916.27
7.4.10.0120.00316.27
7.4.00.0130.00316.16

preferences:
67.35 ms | 403 KiB | 5 Q