3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Similarity { protected $data = null; protected $distance = null; public function __construct($data, $distance) { $this->data = (string)$data; $this->distance = (int)$distance; } public function checkMatch($search, callable $checker=null, array $args=[], $return=false) { $data = preg_split('/\s+/', strtolower($this->data), -1, PREG_SPLIT_NO_EMPTY); $search = trim(preg_replace('/\s+/', ' ', strtolower($search))); foreach($this->getAssoc($data, substr_count($search, ' ')+1) as $assoc) { foreach($this->getPermutations($assoc) as $ordered) { $ordered = join(' ', $ordered); $result = call_user_func_array($checker, array_merge([$ordered, $search], $args)); if($result<=$this->distance) { return $return?$ordered:true; } } } return $return?null:false; } protected function getPermutations(array $input) { if(count($input)==1) { return [$input]; } $result = []; foreach($input as $key=>$element) { foreach($this->getPermutations(array_diff_key($input, [$key=>0])) as $subarray) { $result[] = array_merge([$element], $subarray); } } return $result; } protected function nextAssoc($assoc) { if(false !== ($pos = strrpos($assoc, '01'))) { $assoc[$pos] = '1'; $assoc[$pos+1] = '0'; return substr($assoc, 0, $pos+2). str_repeat('0', substr_count(substr($assoc, $pos+2), '0')). str_repeat('1', substr_count(substr($assoc, $pos+2), '1')); } return false; } protected function getAssoc(array $data, $count=2) { if(count($data)<$count) { return null; } $assoc = str_repeat('0', count($data)-$count).str_repeat('1', $count); $result = []; do { $result[]=array_intersect_key($data, array_filter(str_split($assoc))); } while($assoc=$this->nextAssoc($assoc)); return $result; } } $data = 'Niels Faurskov Andersen'; $search = [ 'Niels Andersen', 'Niels Faurskov', 'Niels Faurskov Andersen', 'Nils Faurskov Andersen', 'Nils Andersen', 'niels faurskov', 'niels Fæurskov', 'niffddels Faurskævffre', 'jens grunnet' ]; $checker = new Similarity($data, 2); echo(sprintf('Testing "%s"'.PHP_EOL.PHP_EOL, $data)); foreach($search as $name) { echo(sprintf( 'Name "%s" has %s'.PHP_EOL, $name, ($result=$checker->checkMatch($name, 'levenshtein', [], 1)) ?sprintf('matched with "%s"', $result) :'mismatched' ) ); }

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.70.0140.00718.36
8.3.60.0060.01618.56
8.3.50.0150.00721.27
8.3.40.0130.00319.22
8.3.30.0090.00620.39
8.3.20.0080.00020.13
8.3.10.0040.00422.04
8.3.00.0040.00422.29
8.2.180.0070.01416.36
8.2.170.0040.01819.04
8.2.160.0140.00722.96
8.2.150.0060.00324.18
8.2.140.0000.00824.66
8.2.130.0040.01426.16
8.2.120.0080.00021.09
8.2.110.0060.00320.57
8.2.100.0040.00817.91
8.2.90.0040.00419.30
8.2.80.0000.00819.40
8.2.70.0030.00517.75
8.2.60.0070.00418.05
8.2.50.0060.00318.07
8.2.40.0000.00818.22
8.2.30.0050.00319.52
8.2.20.0000.00917.93
8.2.10.0000.00818.00
8.2.00.0000.00817.82
8.1.280.0070.00725.92
8.1.270.0050.00323.99
8.1.260.0070.00026.35
8.1.250.0000.00828.09
8.1.240.0070.00324.01
8.1.230.0040.00719.24
8.1.220.0000.00817.90
8.1.210.0080.00018.77
8.1.200.0000.00917.72
8.1.190.0090.00017.66
8.1.180.0050.00318.10
8.1.170.0040.00418.73
8.1.160.0000.00718.95
8.1.150.0030.00518.68
8.1.140.0040.00417.57
8.1.130.0040.00317.89
8.1.120.0040.00417.67
8.1.110.0000.00817.54
8.1.100.0040.00417.53
8.1.90.0070.00017.64
8.1.80.0040.00417.54
8.1.70.0040.00417.59
8.1.60.0060.00317.78
8.1.50.0050.00317.54
8.1.40.0000.00817.71
8.1.30.0000.00817.75
8.1.20.0030.00617.84
8.1.10.0000.00817.64
8.1.00.0060.00317.58
8.0.300.0060.00318.77
8.0.290.0060.00317.30
8.0.280.0080.00018.45
8.0.270.0050.00217.25
8.0.260.0000.00717.07
8.0.250.0030.00417.13
8.0.240.0040.00417.16
8.0.230.0000.00717.11
8.0.220.0070.00016.99
8.0.210.0030.00317.13
8.0.200.0030.00317.03
8.0.190.0000.00817.05
8.0.180.0040.00417.14
8.0.170.0000.00816.98
8.0.160.0040.00417.05
8.0.150.0000.00716.93
8.0.140.0040.00416.93
8.0.130.0000.00813.53
8.0.120.0050.00516.95
8.0.110.0040.00416.99
8.0.100.0060.00317.05
8.0.90.0030.00517.03
8.0.80.0090.00917.07
8.0.70.0050.00216.96
8.0.60.0050.00216.97
8.0.50.0030.00517.06
8.0.30.0160.00517.18
8.0.20.0080.01117.48
8.0.10.0050.00317.18
8.0.00.0070.01317.02
7.4.330.0030.00315.00
7.4.320.0000.00616.76
7.4.300.0000.00616.61
7.4.290.0060.00316.78
7.4.280.0050.00316.75
7.4.270.0030.00316.80
7.4.260.0060.00313.52
7.4.250.0030.00616.74
7.4.240.0040.00316.78
7.4.230.0050.00216.74
7.4.220.0140.01216.93
7.4.210.0080.00916.83
7.4.200.0000.00816.87
7.4.190.0040.00416.95
7.4.160.0080.00816.80
7.4.150.0110.00717.40
7.4.140.0090.00917.86
7.4.130.0120.00616.83
7.4.120.0100.00916.75
7.4.110.0130.00316.75
7.4.100.0120.00616.83
7.4.90.0140.00716.81
7.4.80.0200.00319.39
7.4.70.0170.00316.91
7.4.60.0110.00616.67
7.4.50.0050.00316.66
7.4.40.0030.00922.77
7.4.30.0120.00816.82
7.4.00.0030.01415.21
7.3.330.0030.00313.41
7.3.320.0030.00313.36
7.3.310.0030.00316.59
7.3.300.0030.00516.52
7.3.290.0000.01416.61
7.3.280.0060.01216.56
7.3.270.0030.01317.40
7.3.260.0090.01216.92
7.3.250.0120.00916.65
7.3.240.0090.00916.63
7.3.230.0080.01016.96
7.3.210.0120.00616.80
7.3.200.0060.01319.39
7.3.190.0100.01316.97
7.3.180.0140.00316.62
7.3.170.0060.01116.80
7.3.160.0040.01216.70
7.3.120.0060.01014.91
7.3.110.0000.01815.00
7.3.100.0090.00615.02
7.3.90.0100.00714.84
7.3.80.0100.00614.83
7.3.70.0100.00715.12
7.3.60.0030.00815.18
7.3.50.0030.01214.76
7.3.40.0040.00815.15
7.3.30.0070.00715.13
7.3.20.0060.00316.73
7.3.10.0110.00316.92
7.3.00.0000.01316.74
7.2.330.0070.01116.86
7.2.320.0050.01316.93
7.2.310.0120.00616.96
7.2.300.0110.00516.80
7.2.290.0050.01116.89
7.2.240.0070.01015.39
7.2.230.0030.01315.55
7.2.220.0000.01015.52
7.2.210.0080.00615.42
7.2.200.0070.00715.03
7.2.190.0040.01215.26
7.2.180.0000.01315.35
7.2.170.0090.00315.25
7.2.160.0060.00615.03
7.2.150.0040.00917.15
7.2.140.0120.00317.07
7.2.130.0140.00317.26
7.2.120.0030.00916.92
7.2.110.0090.00617.21
7.2.100.0000.01716.87
7.2.90.0120.00317.36
7.2.80.0070.01017.26
7.2.70.0090.00617.03
7.2.60.0090.00617.14
7.2.50.0000.01216.97
7.2.40.0090.00317.05
7.2.30.0070.00717.29
7.2.20.0060.00616.99
7.2.10.0130.00016.93
7.2.00.0030.01017.31
7.1.330.0090.00316.02
7.1.320.0110.00416.00
7.1.310.0040.01116.04
7.1.300.0070.00716.08
7.1.290.0040.01116.02
7.1.280.0060.00615.91
7.1.270.0060.00915.93
7.1.260.0060.01015.90
7.1.250.0030.01216.04
7.1.100.0040.01218.54
7.1.70.0000.00917.13
7.1.60.0120.00919.32
7.1.50.0070.01617.27
7.1.00.0000.03722.38
7.0.200.0000.00717.07
7.0.140.0000.07022.00
7.0.100.0330.05719.98
7.0.90.0330.06719.96
7.0.80.0430.04319.99
7.0.70.0270.07720.22
7.0.60.0070.08320.02
7.0.50.0030.07720.36
7.0.40.0100.08020.14
7.0.30.0070.09320.18
7.0.20.0070.08720.13
7.0.10.0030.08319.99
7.0.00.0030.07720.00
5.6.250.0130.08020.59
5.6.240.0170.07720.70
5.6.230.0070.08020.65
5.6.220.0000.08320.55
5.6.210.0100.04320.46
5.6.200.0100.07321.04
5.6.190.0100.07721.12
5.6.180.0000.06720.99
5.6.170.0030.08020.98
5.6.160.0170.07321.20
5.6.150.0170.04021.04
5.6.140.0200.08721.12
5.6.130.0030.07321.13
5.6.120.0100.08021.10
5.6.110.0030.09021.10
5.6.100.0070.08721.07
5.6.90.0130.07320.94
5.6.80.0030.08020.54
5.6.70.0100.08020.43
5.6.60.0030.07720.47
5.6.50.0100.07320.51
5.6.40.0100.08020.32
5.6.30.0070.08320.33
5.6.20.0100.07020.43
5.6.10.0000.08320.42
5.6.00.0100.08020.32
5.5.380.0100.04020.45
5.5.370.0130.08020.59
5.5.360.0100.07720.55
5.5.350.0200.06320.48
5.5.340.0070.08720.81
5.5.330.0000.09020.91
5.5.320.0100.08320.88
5.5.310.0170.07720.94
5.5.300.0030.08020.94
5.5.290.0030.06720.80
5.5.280.0100.07320.81
5.5.270.0030.08020.93
5.5.260.0200.06720.65
5.5.250.0100.04320.75
5.5.240.0070.08020.18
5.5.230.0070.07020.11
5.5.220.0070.07320.23
5.5.210.0000.04320.25
5.5.200.0070.07720.14
5.5.190.0130.07320.16
5.5.180.0130.04320.28
5.5.160.0200.06320.14
5.5.150.0100.07020.29
5.5.140.0200.06720.15
5.5.130.0100.07320.12
5.5.120.0000.06320.17
5.5.110.0130.07720.00
5.5.100.0100.08020.10
5.5.90.0130.07020.14
5.5.80.0200.05720.10
5.5.70.0200.06720.18
5.5.60.0130.07720.14
5.5.50.0130.07020.16
5.5.40.0030.08019.91
5.5.30.0130.07320.01
5.5.20.0170.05720.16
5.5.10.0130.07020.07
5.5.00.0070.07320.07
5.4.450.0100.07319.45
5.4.440.0130.06719.41
5.4.430.0030.07319.54
5.4.420.0070.08319.34
5.4.410.0100.07319.19
5.4.400.0000.06719.13
5.4.390.0130.06319.06
5.4.380.0130.07719.16
5.4.370.0070.04319.02
5.4.360.0000.07019.17
5.4.350.0000.07019.20
5.4.340.0000.05019.17
5.4.320.0100.04019.04
5.4.310.0100.06719.12
5.4.300.0030.05319.08
5.4.290.0070.08018.87
5.4.280.0100.08318.84
5.4.270.0070.08019.11
5.4.260.0170.06019.08
5.4.250.0170.06319.07
5.4.240.0100.04018.89
5.4.230.0200.07719.17
5.4.220.0070.07319.02
5.4.210.0030.08318.95
5.4.200.0070.07319.02
5.4.190.0070.07719.01
5.4.180.0030.08019.19
5.4.170.0100.07719.14
5.4.160.0100.06719.01
5.4.150.0070.08319.00
5.4.140.0170.06316.48
5.4.130.0070.07316.45
5.4.120.0130.06316.41
5.4.110.0100.06316.37
5.4.100.0100.07016.34
5.4.90.0070.07316.38
5.4.80.0070.07316.54
5.4.70.0000.04016.49
5.4.60.0030.05016.26
5.4.50.0000.05016.38
5.4.40.0000.07716.49
5.4.30.0030.04716.45
5.4.20.0030.07716.49
5.4.10.0070.07716.38
5.4.00.0100.06315.86
5.3.290.0100.04314.81
5.3.280.0070.07314.73
5.3.270.0100.07014.56
5.3.260.0070.06714.59
5.3.250.0200.05714.72
5.3.240.0130.07014.71
5.3.230.0130.07014.67
5.3.220.0070.07314.58
5.3.210.0030.07714.63
5.3.200.0100.05014.59
5.3.190.0070.07714.66
5.3.180.0070.05314.58
5.3.170.0070.06314.60
5.3.160.0130.06714.63
5.3.150.0100.05314.60
5.3.140.0070.08014.54
5.3.130.0100.04314.56
5.3.120.0030.06014.67
5.3.110.0100.06314.50
5.3.100.0100.07314.13
5.3.90.0070.07314.16
5.3.80.0100.07013.93
5.3.70.0030.08014.02
5.3.60.0070.07314.04
5.3.50.0100.07314.09
5.3.40.0230.05714.08
5.3.30.0100.06014.05
5.3.20.0030.08013.79
5.3.10.0000.07313.78
5.3.00.0070.06713.67
5.2.170.0030.06311.06
5.2.160.0000.06711.21
5.2.150.0070.06711.21
5.2.140.0000.04011.08
5.2.130.0100.06011.09
5.2.120.0100.05011.24
5.2.110.0070.03711.21
5.2.100.0030.06311.17
5.2.90.0070.05311.05
5.2.80.0030.05011.01
5.2.70.0030.06011.10
5.2.60.0030.06711.19
5.2.50.0100.05711.03
5.2.40.0000.04310.91
5.2.30.0000.06311.11
5.2.20.0000.06010.91
5.2.10.0030.06310.98
5.2.00.0070.05010.64
5.1.60.0070.05010.12
5.1.50.0100.04710.07
5.1.40.0100.0509.83
5.1.30.0100.05010.42
5.1.20.0100.05710.29
5.1.10.0100.04710.17
5.1.00.0030.05710.16
5.0.50.0070.0408.51
5.0.40.0000.0378.48
5.0.30.0000.0538.22
5.0.20.0000.0208.27
5.0.10.0000.0208.21
5.0.00.0000.0378.16
4.4.90.0030.0177.84
4.4.80.0000.0277.84
4.4.70.0070.0277.84
4.4.60.0070.0337.84
4.4.50.0070.0307.84
4.4.40.0000.0577.84
4.4.30.0030.0277.84
4.4.20.0100.0307.84
4.4.10.0000.0407.84
4.4.00.0030.0377.84
4.3.110.0030.0207.84
4.3.100.0000.0207.84
4.3.90.0030.0137.84
4.3.80.0030.0207.84
4.3.70.0000.0137.84
4.3.60.0030.0137.84
4.3.50.0000.0177.84
4.3.40.0030.0277.84
4.3.30.0000.0177.84
4.3.20.0000.0177.84
4.3.10.0000.0237.84
4.3.00.0030.0107.84

preferences:
43.65 ms | 401 KiB | 5 Q