3v4l.org

run code in 500+ PHP versions simultaneously
<?php // Crate json string contain 50000 objecy $locations = ""; for ($i=0; $i<50000; $i++){ $locations .= "{\"location\":\"$i\",\"distance\":\"25.75206\"},"; } $json = "[".substr($locations, 0, -1)."]"; $location = '100'; // Using json_decode and loop $time = microtime(true); $locations = json_decode($json, true); foreach ($locations as $key => $value) { if ($value['location'] == $location) { @$distance = $value['distance']; } } echo "json_decode and loop:\n".(microtime(true) - $time)."\n"; // Using regex $time2 = microtime(true); if (preg_match("/\{\s*\"location\"\s*:\s*\"{$location}\".*?}/", $json, $match)){ $locations = json_decode("[{$match[0]}]", true)[0]; $distance = $locations['distance']; } echo "regex: \n".(microtime(true) - $time2);

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.2.280.0570.03646.63
8.1.30.0440.03346.50
7.3.00.4110.05345.73
7.2.130.4490.04645.54
7.2.120.4010.04346.11
7.2.110.7400.06645.84
7.2.100.6090.05746.20
7.2.90.6400.05045.97
7.2.80.9000.05046.13
7.2.70.6100.06745.99
7.2.60.5750.06646.07
7.2.50.6360.05746.08
7.2.40.6050.05346.14
7.2.30.6950.05046.04
7.2.20.8530.06045.78
7.2.10.9010.06645.80
7.2.01.1840.05646.20
7.1.250.3600.05644.66
7.0.330.5370.04044.80
5.6.380.0500.14755.11

preferences:
49.79 ms | 560 KiB | 5 Q