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 Faurskov', 'niffddels Faurskovffre', 'niels faƦrskov' ]; $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.60.0130.01318.43
8.3.50.0110.01121.27
8.3.40.0110.00719.04
8.3.30.0040.01220.16
8.3.20.0050.00320.24
8.3.10.0060.00322.04
8.3.00.0030.00522.45
8.2.180.0070.01016.88
8.2.170.0110.00322.96
8.2.160.0110.00422.26
8.2.150.0080.00024.18
8.2.140.0080.00024.66
8.2.130.0130.00726.16
8.2.120.0080.00021.13
8.2.110.0090.00022.21
8.2.100.0090.00317.97
8.2.90.0080.00019.21
8.2.80.0030.00519.30
8.2.70.0030.00617.88
8.2.60.0060.00618.05
8.2.50.0000.00818.07
8.2.40.0000.00818.20
8.2.30.0060.00319.57
8.2.20.0040.00417.91
8.2.10.0040.00417.88
8.2.00.0050.00317.93
8.1.280.0120.00325.92
8.1.270.0080.00023.99
8.1.260.0030.00526.35
8.1.250.0040.00428.09
8.1.240.0000.00923.97
8.1.230.0070.00419.22
8.1.220.0080.00017.91
8.1.210.0040.00418.77
8.1.200.0050.00517.61
8.1.190.0090.00017.64
8.1.180.0000.00819.13
8.1.170.0040.00418.87
8.1.160.0060.00319.00
8.1.150.0090.00018.70
8.1.140.0000.00817.59
8.1.130.0000.00717.80
8.1.120.0000.00817.55
8.1.110.0050.00317.68
8.1.100.0040.00417.65
8.1.90.0000.00717.53
8.1.80.0050.00317.69
8.1.70.0040.00417.62
8.1.60.0030.00617.77
8.1.50.0000.00817.59
8.1.40.0040.00417.61
8.1.30.0080.00017.75
8.1.20.0030.00617.72
8.1.10.0030.00717.64
8.1.00.0000.00917.66
8.0.300.0050.00318.77
8.0.290.0000.00817.18
8.0.280.0050.00218.38
8.0.270.0050.00217.31
8.0.260.0000.00717.01
8.0.250.0030.00317.13
8.0.240.0030.00517.18
8.0.230.0040.00417.16
8.0.220.0000.00816.99
8.0.210.0060.00317.01
8.0.200.0000.00617.09
8.0.190.0030.00517.04
8.0.180.0000.00817.06
8.0.170.0060.00317.05
8.0.160.0040.00416.97
8.0.150.0040.00417.03
8.0.140.0000.00816.93
8.0.130.0000.00813.60
8.0.120.0030.00617.07
8.0.110.0000.00816.99
8.0.100.0000.00816.88
8.0.90.0040.00416.90
8.0.80.0140.00416.95
8.0.70.0030.00516.97
8.0.60.0040.00417.09
8.0.50.0070.00017.12
8.0.30.0160.00617.29
8.0.20.0120.00717.40
8.0.10.0030.00517.20
8.0.00.0130.00616.97
7.4.330.0050.00015.00
7.4.320.0060.00016.70
7.4.300.0030.00316.69
7.4.290.0000.00716.77
7.4.280.0000.00716.88
7.4.270.0040.00416.85
7.4.260.0030.00513.59
7.4.250.0000.00716.64
7.4.240.0020.00516.78
7.4.230.0000.00716.79
7.4.220.0070.01916.92
7.4.210.0080.00916.87
7.4.200.0000.00816.79
7.4.190.0080.00016.72
7.4.160.0040.01216.80
7.4.150.0140.00617.40
7.4.140.0090.00917.86
7.4.130.0110.01016.75
7.4.120.0060.01116.69
7.4.110.0120.00616.59
7.4.100.0110.00616.89
7.4.90.0050.01516.82
7.4.80.0110.00719.39
7.4.70.0130.01016.78
7.4.60.0120.00616.98
7.4.50.0040.00416.71
7.4.40.0070.00722.77
7.4.30.0070.01516.89
7.4.10.0000.01815.00
7.4.00.0060.00915.28
7.3.330.0050.00013.43
7.3.320.0050.00013.38
7.3.310.0050.00216.56
7.3.300.0040.00416.44
7.3.290.0070.00716.57
7.3.280.0090.00916.58
7.3.270.0060.01217.40
7.3.260.0090.00916.89
7.3.250.0090.00916.73
7.3.240.0130.01016.84
7.3.230.0140.00316.85
7.3.210.0100.00716.82
7.3.200.0090.00919.39
7.3.190.0060.01616.84
7.3.180.0030.01316.56
7.3.170.0120.00716.53
7.3.160.0090.00616.72
7.3.130.0060.01315.07
7.3.120.0070.01015.08
7.3.110.0060.01315.07
7.3.100.0000.01714.71
7.3.90.0070.01315.41
7.3.80.0000.01614.84
7.3.70.0000.01514.72
7.3.60.0030.00914.94
7.3.50.0040.01115.13
7.3.40.0080.00415.16
7.3.30.0080.00815.06
7.3.20.0000.01316.93
7.3.10.0020.01416.62
7.3.00.0060.00616.88
7.2.330.0090.00916.92
7.2.320.0110.00717.00
7.2.310.0030.01416.66
7.2.300.0160.00717.04
7.2.290.0090.00917.07
7.2.260.0110.00715.33
7.2.250.0030.01315.51
7.2.240.0110.00415.16
7.2.230.0030.01515.13
7.2.220.0030.01715.15
7.2.210.0110.00315.11
7.2.200.0080.00815.35
7.2.190.0040.01515.52
7.2.180.0070.01115.07
7.2.170.0030.00915.21
7.2.160.0040.01115.28
7.2.150.0120.00417.39
7.2.140.0000.01717.18
7.2.130.0080.00417.23
7.2.120.0040.00816.95
7.2.110.0090.00617.21
7.2.100.0040.01117.16
7.2.90.0130.00317.20
7.2.80.0110.00317.24
7.2.70.0100.00717.29
7.2.60.0070.00917.21
7.2.50.0070.00717.04
7.2.40.0000.01116.87
7.2.30.0040.01216.86
7.2.20.0070.01117.20
7.2.10.0030.01617.00
7.2.00.0060.00818.11
7.1.330.0090.00616.21
7.1.320.0060.01216.24
7.1.310.0090.00316.13
7.1.300.0040.01416.16
7.1.290.0000.01015.70
7.1.280.0040.01116.00
7.1.270.0120.00316.05
7.1.260.0070.01015.97
7.1.250.0070.00415.80
7.1.240.0110.00416.07
7.1.230.0000.00916.05
7.1.220.0060.00915.91
7.1.210.0070.01015.98
7.1.200.0090.00915.89
7.1.190.0060.00615.95
7.1.180.0070.00715.88
7.1.170.0030.01015.95
7.1.160.0030.00716.02
7.1.150.0070.00316.02
7.1.140.0070.00316.13
7.1.130.0040.00816.03
7.1.120.0030.01415.70
7.1.110.0080.00815.81
7.1.100.0030.00917.19
7.1.90.0040.00816.11
7.1.80.0060.00316.14
7.1.70.0030.00816.76
7.1.60.0100.00917.65
7.1.50.0090.00916.54
7.1.40.0090.00615.89
7.1.30.0000.01015.86
7.1.20.0090.00016.10
7.1.10.0030.00916.07
7.1.00.0060.01819.22
7.0.330.0060.01015.68
7.0.320.0050.00515.69
7.0.310.0050.00515.64
7.0.300.0060.00315.65
7.0.290.0060.00615.59
7.0.280.0070.00715.72
7.0.270.0070.01115.50
7.0.260.0040.00815.18
7.0.250.0110.00415.64
7.0.240.0100.00315.74
7.0.230.0060.00315.66
7.0.220.0120.00315.63
7.0.210.0110.00415.69
7.0.200.0060.00516.21
7.0.190.0070.00715.63
7.0.180.0030.00715.41
7.0.170.0060.00615.65
7.0.160.0060.00615.69
7.0.150.0060.00815.68
7.0.140.0020.04218.82
7.0.130.0090.00615.80
7.0.120.0040.00415.45
7.0.110.0070.00715.68
7.0.100.0070.00715.84
7.0.90.0000.01615.62
7.0.80.0180.02117.81
7.0.70.0060.02117.76
7.0.60.0110.02517.85
7.0.50.0050.02318.03
7.0.40.0030.03016.66
7.0.30.0050.02516.93
7.0.20.0070.02216.92
7.0.10.0080.02016.93
7.0.00.0050.02516.84
5.6.400.0070.01014.70
5.6.390.0100.00614.76
5.6.380.0040.01114.48
5.6.370.0060.00614.75
5.6.360.0000.00814.45
5.6.350.0040.01114.79
5.6.340.0000.01714.41
5.6.330.0070.00714.59
5.6.320.0070.00714.65
5.6.310.0100.00714.79
5.6.300.0070.00714.94
5.6.290.0060.00914.60
5.6.280.0030.04117.73
5.6.270.0090.00614.78
5.6.260.0000.01214.46
5.6.250.0070.00714.45
5.6.240.0070.00414.58
5.6.230.0060.02917.56
5.6.220.0020.03117.58
5.6.210.0060.02117.50
5.6.200.0080.02617.90
5.6.190.0020.03017.74
5.6.180.0030.02817.76
5.6.170.0030.02717.66
5.6.160.0050.02318.00
5.6.150.0100.02117.87
5.6.140.0060.02817.83
5.6.130.0010.02817.79
5.6.120.0080.04017.84
5.6.110.0050.02617.75
5.6.100.0080.02217.92
5.6.90.0050.04517.79
5.6.80.0100.02517.58
5.6.70.0080.03517.60
5.6.60.0140.04017.39
5.6.50.0050.04517.56
5.6.40.0100.04317.44
5.6.30.0100.04217.46
5.6.20.0120.04317.43
5.6.10.0110.04217.61
5.6.00.0050.04117.48
5.5.380.0000.01314.69
5.5.370.0030.02317.60
5.5.360.0100.03817.57
5.5.350.0080.02317.46
5.5.340.0040.02517.77
5.5.330.0030.02717.74
5.5.320.0090.02117.69
5.5.310.0060.02317.68
5.5.300.0020.04117.62
5.5.290.0060.03517.62
5.5.280.0030.02817.78
5.5.270.0030.03017.64
5.5.260.0080.02317.77
5.5.250.0100.04617.60
5.5.240.0070.04017.42
5.5.230.0080.04117.34
5.5.220.0100.04217.28
5.5.210.0060.04517.43
5.5.200.0080.04517.25
5.5.190.0080.04517.21
5.5.180.0080.04217.36
5.5.170.0070.00714.60
5.5.160.0070.04417.47
5.5.150.0120.03817.34
5.5.140.0070.04417.19
5.5.130.0090.02117.37
5.5.120.0120.03817.42
5.5.110.0070.04717.21
5.5.100.0110.04017.22
5.5.90.0100.03517.35
5.5.80.0050.04517.21
5.5.70.0050.02617.32
5.5.60.0030.04317.25
5.5.50.0050.04117.13
5.5.40.0060.03317.14
5.5.30.0050.02817.13
5.5.20.0110.02117.16
5.5.10.0020.04817.23
5.5.00.0070.03017.30
5.4.450.0030.02315.21
5.4.440.0040.03215.45
5.4.430.0030.02415.35
5.4.420.0020.02915.46
5.4.410.0030.02515.39
5.4.400.0050.04115.21
5.4.390.0090.04015.12
5.4.380.0050.04315.04
5.4.370.0080.03515.27
5.4.360.0100.03714.98
5.4.350.0080.03615.22
5.4.340.0050.04415.13
5.4.330.0000.01111.48
5.4.320.0000.03115.09
5.4.310.0090.03915.22
5.4.300.0060.03815.07
5.4.290.0090.02015.06
5.4.280.0020.02615.30
5.4.270.0050.03915.29
5.4.260.0050.04315.06
5.4.250.0080.03715.20
5.4.240.0050.02215.10
5.4.230.0070.03915.12
5.4.220.0050.03915.12
5.4.210.0070.02815.22
5.4.200.0070.02415.21
5.4.190.0050.02315.25
5.4.180.0050.02515.13
5.4.170.0050.02815.06
5.4.160.0130.03315.11
5.4.150.0080.04415.11
5.4.140.0070.03713.79
5.4.130.0050.02513.86
5.4.120.0020.02813.88
5.4.110.0050.04513.76
5.4.100.0070.02513.93
5.4.90.0100.03613.87
5.4.80.0060.02513.73
5.4.70.0100.03513.81
5.4.60.0050.02713.97
5.4.50.0050.02213.94
5.4.40.0070.03813.82
5.4.30.0030.04313.73
5.4.20.0070.03713.80
5.4.10.0020.04013.74
5.4.00.0080.03713.60
5.3.290.0070.03712.83
5.3.280.0060.03812.83
5.3.270.0070.03712.73
5.3.260.0080.04312.73
5.3.250.0070.02512.81
5.3.240.0100.03412.81
5.3.230.0020.03912.81
5.3.220.0070.04012.75
5.3.210.0090.03812.80
5.3.200.0070.02612.72
5.3.190.0050.03512.78
5.3.180.0080.03812.77
5.3.170.0030.02812.71
5.3.160.0050.04212.72
5.3.150.0080.03012.81
5.3.140.0070.04012.72
5.3.130.0040.03412.76
5.3.120.0070.04212.75
5.3.110.0080.04112.75
5.3.100.0030.03812.51
5.3.90.0090.02512.49
5.3.80.0020.02212.46
5.3.70.0020.04012.42
5.3.60.0080.03512.47
5.3.50.0060.02512.43
5.3.40.0080.03012.48
5.3.30.0030.03612.42
5.3.20.0050.02312.35
5.3.10.0050.03412.30
5.3.00.0060.03512.31
5.2.170.0030.06011.93
5.2.160.0100.05711.93
5.2.150.0130.05711.93
5.2.140.0070.04711.93
5.2.130.0030.06011.93
5.2.120.0000.07011.93
5.2.110.0030.06011.93
5.2.100.0070.03311.93
5.2.90.0030.06311.93
5.2.80.0100.04711.93
5.2.70.0030.06311.93
5.2.60.0000.06311.93
5.2.50.0070.04711.67
5.2.40.0030.06311.67
5.2.30.0100.05711.67
5.2.20.0070.05711.67
5.2.10.0070.06011.67
5.2.00.0100.05711.67
5.1.60.0030.04011.67
5.1.50.0030.05711.67
5.1.40.0070.03011.67
5.1.30.0070.04311.67
5.1.20.0070.05711.67
5.1.10.0070.04311.67
5.1.00.0070.04711.67
5.0.50.0100.03711.67
5.0.40.0070.04311.67
5.0.30.0070.06011.67
5.0.20.0030.02711.67
5.0.10.0070.04311.67
5.0.00.0030.05711.67
4.4.90.0130.02311.93
4.4.80.0030.03311.67
4.4.70.0030.03311.67
4.4.60.0070.02311.67
4.4.50.0070.03011.67
4.4.40.0000.06011.67
4.4.30.0000.02711.67
4.4.20.0070.02311.67
4.4.10.0000.03711.67
4.4.00.0000.04711.67
4.3.110.0030.03011.67
4.3.100.0030.02011.67
4.3.90.0000.03711.67
4.3.80.0000.05711.67
4.3.70.0000.04011.67
4.3.60.0070.02311.67
4.3.50.0000.03311.67
4.3.40.0030.04011.67
4.3.30.0030.02311.67
4.3.20.0030.03311.67
4.3.10.0070.03011.67
4.3.00.0030.02711.67

preferences:
49.68 ms | 401 KiB | 5 Q