3v4l.org

run code in 300+ PHP versions simultaneously
<?php $rows = [ ['`1234567890-=', '~!@#$%^&*()_+'], ['qwertyuiop[]\\', 'QWERTYUIOP{}|'], ['asdfghjkl;\'', 'ASDFGHJKL:"'], ['zxcvbnm,./', 'ZXCVBNM<>?'] ]; $wholeregex = []; foreach($rows as $k => $row) { $num = $k + 1; echo "Row $num\n"; $array = []; foreach($row as $subrow) { $subarray = array_map('ord', str_split($subrow)); $array = array_merge($subarray, $array); } sort($array); echo "\t" . implode( ' ', $array), "\n"; $ret = [$array[0]]; for($i = 1; $i < count($array); $i++) { $num = $array[$i]; if(($array[$i - 1] + 1) == $num) { if( ($i == (count($array) - 1)) || ($array[$i + 1] != ($num + 1)) ) { $ret[] = array_pop($ret) . '-' . $num; } } else { $ret[] = $num; } } echo "\t" . implode( ' ', $ret), "\n"; $regex = '(['; $subregex = implode( '', array_map(function($el) { $vals = explode('-', $el); if(count($vals) == 1) { return chr($vals[0]); } return chr($vals[0]) . '-' . chr($vals[1]); }, $ret)); $regex .= $subregex; $regex .= '])'; echo "\t" . $regex, "\n"; $wholeregex[] = $regex; } $finalregex = '%' . implode('|', $wholeregex) . '%'; $finalregex = str_replace('(-', '\(-', $finalregex); echo $finalregex, "\n"; echo strlen($finalregex), "\n"; $argv[1] = "a"; $i=$argv[1];preg_match("%([!#-&\(-+-0-9=@^-`~])|([EIO-RT-UWY[-]eio-rt-uwy{-}])|(["':-;ADF-HJ-LSadf-hj-ls])|([,.-/<>-?B-CM-NVXZb-cm-nvxz])%",$i,$m);echo array_flip($m)[$i];

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)
7.0.20.0270.08320.24
7.0.10.0070.06720.33
7.0.00.0000.05720.20
5.6.170.0230.03320.47
5.6.160.0100.04020.43
5.6.150.0100.07318.13
5.6.140.0030.05018.24
5.6.130.0130.05718.21
5.6.120.0130.07721.06
5.6.110.0000.04721.03
5.6.100.0100.08021.15
5.6.90.0000.09321.14
5.6.80.0130.04020.52
5.5.310.0270.05320.25
5.5.300.0030.08018.08
5.5.290.0070.06018.09
5.5.280.0100.07720.98
5.5.270.0070.04720.78
5.5.260.0070.07720.96
5.5.250.0130.04020.63
5.5.240.0270.05020.14

preferences:
164.25 ms | 1394 KiB | 7 Q