3v4l.org

run code in 300+ PHP versions simultaneously
<?php $body = <<<HTML <body class="old_attr"> <div>(content)</div> </body> HTML; $new_class = "new_class_attr"; $body = preg_replace('~<body[^>]*class *= *["\']\K~', "$new_class ", $body, 1, $count); if (!$count) { $body = preg_replace('~<body\K~', " class=\"$new_class\"", $body, 1); } echo $body;

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.1.20.0090.00017.83
8.1.10.0060.00317.70
8.1.00.0040.00417.60
8.0.150.0030.00717.13
8.0.140.0040.00417.14
8.0.130.0050.00013.66
8.0.120.0050.00317.31
8.0.110.0040.00417.29
8.0.100.0050.00217.14
8.0.90.0070.00017.13
8.0.80.0100.00617.22
8.0.70.0040.00417.30
8.0.60.0040.00417.14
8.0.50.0000.00717.24
8.0.30.0130.00717.42
8.0.20.0090.00917.48
8.0.10.0000.00717.26
8.0.00.0070.01016.88
7.4.270.0030.00316.90
7.4.260.0040.00416.75
7.4.250.0040.00416.85
7.4.240.0070.00016.91
7.4.230.0030.00316.93
7.4.220.0060.00316.54
7.4.210.0030.01016.86
7.4.200.0000.00716.63
7.4.160.0090.00916.77
7.4.140.0130.00717.86
7.4.130.0120.00616.72
7.4.120.0100.00816.78
7.4.110.0150.00916.97
7.4.100.0000.01916.75
7.4.90.0110.00616.96
7.4.80.0120.00619.39
7.4.70.0000.01816.57
7.4.60.0030.01316.79
7.4.50.0050.00816.55
7.4.40.0100.00616.83
7.4.00.0110.00415.13
7.3.330.0030.00313.39
7.3.320.0060.00013.38
7.3.310.0040.00416.48
7.3.300.0000.00616.54
7.3.290.0000.00616.50
7.3.280.0070.00916.49
7.3.260.0120.00716.77
7.3.240.0060.01316.69
7.3.230.0200.00016.76
7.3.210.0120.00916.73
7.3.200.0070.01016.66
7.3.190.0090.01316.60
7.3.180.0090.00616.48
7.3.170.0070.01016.63
7.3.160.0120.00316.80
7.3.10.0170.00716.49
7.3.00.0130.00616.48
7.2.330.0110.01116.82
7.2.320.0030.01416.86
7.2.310.0120.01216.84
7.2.300.0100.00616.85
7.2.290.0100.00716.67
7.2.130.0120.00516.61
7.2.120.0920.00515.75
7.2.110.0390.00915.84
7.2.100.0410.00415.78
7.2.90.0470.01415.72
7.2.80.0340.00615.61
7.2.70.0470.01016.17
7.2.60.0420.00916.08
7.2.50.0360.00616.02
7.2.40.0450.00815.79
7.2.30.0710.00615.82
7.2.20.0540.00315.73
7.2.10.0400.00516.07
7.2.00.0430.00815.98
7.1.250.0130.00515.70
7.1.240.0860.01014.08
7.1.230.0740.01414.14
7.1.220.0770.00714.08
7.1.210.0890.01014.20
7.1.200.0560.00614.20
7.1.190.0850.00313.96
7.1.180.0810.00314.11
7.1.170.0800.00713.89
7.1.160.0810.01114.06
7.1.150.0780.01214.16
7.1.140.0900.00314.12
7.1.130.0680.01314.14
7.1.120.0830.00314.17
7.1.110.0730.01014.29
7.1.100.0530.00714.07
7.1.90.0860.00314.23
7.1.80.0750.01113.78
7.1.70.0710.01013.85
7.1.60.0810.01614.01
7.1.50.0860.00714.03
7.1.40.0690.00713.96
7.1.30.1010.01014.01
7.1.20.0840.00314.17
7.1.10.0740.00913.79
7.1.00.0770.00413.93
5.6.380.0090.00914.43

preferences:
17.95 ms | 455 KiB | 5 Q