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) { $solid = $this->normalizeInput($this->data, $search); $data = $solid['data']; $search = $solid['search']; $data = preg_split('/\s+/', $data); 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; } protected function normalizeInput($data, $search) { $data = preg_split('/\s+/', trim(strtolower($data)), -1, PREG_SPLIT_NO_EMPTY); $search = preg_split('/\s+/', trim(strtolower($search)), -1, PREG_SPLIT_NO_EMPTY); if(count($data)<count($search)) { $temp = $data; $data = join(' ', $search); $search = join(' ', $temp); } else { $data = join(' ', $data); $search = join(' ', $search); } return ['data'=>$data, 'search'=>$search]; } } $data = 'Louise Bro'; $search = [ 'Louise Gulbæk Bro', '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.0120.00316.98
8.3.60.0110.00718.56
8.3.50.0070.01121.27
8.3.40.0080.00819.08
8.3.30.0140.00020.38
8.3.20.0000.00820.33
8.3.10.0060.00322.09
8.3.00.0040.00422.21
8.2.180.0150.00316.63
8.2.170.0110.00722.96
8.2.160.0100.00622.28
8.2.150.0030.00624.18
8.2.140.0000.00824.66
8.2.130.0040.00426.16
8.2.120.0000.00819.48
8.2.110.0070.00320.49
8.2.100.0090.00318.00
8.2.90.0000.01318.00
8.2.80.0030.00518.05
8.2.70.0050.00318.04
8.2.60.0080.00018.22
8.2.50.0030.00618.10
8.2.40.0040.00420.58
8.2.30.0050.00318.20
8.2.20.0040.00417.91
8.2.10.0000.00817.83
8.2.00.0090.00017.98
8.1.280.0140.00725.92
8.1.270.0080.00024.66
8.1.260.0040.00426.35
8.1.250.0060.00328.09
8.1.240.0000.00922.18
8.1.230.0060.00622.68
8.1.220.0030.00617.91
8.1.210.0030.00618.77
8.1.200.0030.00617.61
8.1.190.0000.00917.48
8.1.180.0000.00818.10
8.1.170.0050.00318.89
8.1.160.0040.00422.22
8.1.150.0030.00518.77
8.1.140.0000.00817.57
8.1.130.0000.00820.22
8.1.120.0060.00317.69
8.1.110.0030.00517.71
8.1.100.0000.00817.68
8.1.90.0000.00817.64
8.1.80.0070.00017.65
8.1.70.0040.00417.56
8.1.60.0030.00617.64
8.1.50.0060.00317.69
8.1.40.0040.00417.63
8.1.30.0040.00417.80
8.1.20.0040.00417.87
8.1.10.0000.00817.80
8.1.00.0030.00517.64
8.0.300.0000.00820.04
8.0.290.0090.00016.88
8.0.280.0080.00018.52
8.0.270.0000.00718.20
8.0.260.0030.00320.32
8.0.250.0000.00817.06
8.0.240.0000.01117.14
8.0.230.0040.00417.14
8.0.220.0000.00816.99
8.0.210.0030.00317.00
8.0.200.0030.00317.15
8.0.190.0030.00617.16
8.0.180.0070.00017.14
8.0.170.0070.00017.08
8.0.160.0070.00017.16
8.0.150.0000.00817.02
8.0.140.0030.00516.92
8.0.130.0030.00313.53
8.0.120.0030.00617.05
8.0.110.0030.00617.01
8.0.100.0070.00017.05
8.0.90.0040.00416.96
8.0.80.0030.01317.03
8.0.70.0000.00816.97
8.0.60.0040.00416.96
8.0.50.0000.00816.93
8.0.30.0110.00817.15
8.0.20.0140.00517.40
8.0.10.0040.00417.17
8.0.00.0140.00717.04
7.4.330.0050.00015.00
7.4.320.0030.00316.87
7.4.300.0040.00416.75
7.4.290.0030.00516.78
7.4.280.0000.00716.69
7.4.270.0040.00416.80
7.4.260.0070.00013.45
7.4.250.0070.00016.83
7.4.240.0030.00316.72
7.4.230.0030.00516.94
7.4.220.0040.01516.97
7.4.210.0080.01016.82
7.4.200.0070.00016.91
7.4.190.0080.00017.05
7.4.160.0080.01516.77
7.4.150.0120.00917.40
7.4.140.0150.00917.86
7.4.130.0120.01216.78
7.4.120.0070.01116.71
7.4.110.0140.00716.91
7.4.100.0130.00616.73
7.4.90.0090.00916.77
7.4.80.0140.00419.39
7.4.70.0040.01216.76
7.4.60.0090.00816.67
7.4.50.0030.00616.74
7.4.40.0090.00722.77
7.4.30.0070.01016.68
7.4.10.0040.01515.33
7.4.00.0090.00914.97
7.3.330.0040.00213.62
7.3.320.0000.00513.50
7.3.310.0040.00416.50
7.3.300.0000.00716.59
7.3.290.0000.01316.59
7.3.280.0100.00716.58
7.3.270.0070.01017.40
7.3.260.0060.01216.60
7.3.250.0170.00816.71
7.3.240.0150.00316.76
7.3.230.0060.01416.65
7.3.210.0090.00916.78
7.3.200.0000.01719.39
7.3.190.0130.01016.54
7.3.180.0100.00716.60
7.3.170.0110.00616.81
7.3.160.0070.01116.41
7.3.130.0120.00615.27
7.3.120.0070.01115.12
7.3.110.0090.00614.88
7.3.100.0030.01015.15
7.3.90.0090.00614.75
7.3.80.0100.00614.95
7.3.70.0070.01115.14
7.3.60.0080.00614.88
7.3.50.0030.01115.10
7.3.40.0090.00315.22
7.3.30.0070.01014.92
7.3.20.0000.01316.80
7.3.10.0040.00416.78
7.3.00.0100.00716.87
7.2.330.0110.01116.74
7.2.320.0080.01117.00
7.2.310.0130.00616.70
7.2.300.0000.01717.10
7.2.290.0040.01316.90
7.2.260.0170.00315.18
7.2.250.0070.01115.32
7.2.240.0110.00415.11
7.2.230.0070.01415.38
7.2.220.0130.00315.57
7.2.210.0090.00915.06
7.2.200.0030.01015.41
7.2.190.0090.00715.37
7.2.180.0070.00715.31
7.2.170.0160.00015.46
7.2.160.0060.00615.28
7.2.150.0060.01017.10
7.2.140.0120.00416.91
7.2.130.0090.00617.34
7.2.120.0090.00616.86
7.2.110.0060.00817.10
7.2.100.0070.00716.97
7.2.90.0070.00317.34
7.2.80.0120.00317.23
7.2.70.0110.00617.35
7.2.60.0100.00316.98
7.2.50.0060.00617.11
7.2.40.0030.01017.09
7.2.30.0070.01016.96
7.2.20.0040.00917.11
7.2.10.0030.01016.94
7.2.00.0150.00016.98
7.1.330.0090.00416.07
7.1.320.0080.00816.14
7.1.310.0000.01415.70
7.1.300.0030.00616.12
7.1.290.0090.00915.86
7.1.280.0100.01016.17
7.1.270.0000.01015.83
7.1.260.0070.00716.11
7.1.250.0030.00615.87
7.1.240.0030.01216.09
7.1.230.0070.00316.10
7.1.220.0030.01316.09
7.1.210.0000.01516.16
7.1.200.0020.01315.96
7.1.190.0060.01016.01
7.1.180.0000.01515.84
7.1.170.0060.00615.88
7.1.160.0060.00916.16
7.1.150.0060.00915.94
7.1.140.0000.00915.91
7.1.130.0030.01116.02
7.1.120.0100.01015.80
7.1.110.0080.00515.69
7.1.100.0040.01215.99
7.1.90.0030.01015.70
7.1.80.0060.00916.12
7.1.70.0060.00316.81
7.1.60.0070.00717.73
7.1.50.0060.01216.42
7.1.40.0030.01016.00
7.1.30.0030.01316.09
7.1.20.0040.00416.06
7.1.10.0100.00315.96
7.1.00.0030.02019.29
7.0.330.0060.00315.34
7.0.320.0060.00915.38
7.0.310.0070.00715.66
7.0.300.0060.00315.18
7.0.290.0040.00415.69
7.0.280.0070.00715.35
7.0.270.0070.00415.69
7.0.260.0000.01015.58
7.0.250.0030.01015.71
7.0.240.0000.01415.73
7.0.230.0030.00615.66
7.0.220.0000.01315.60
7.0.210.0040.00715.36
7.0.200.0120.00915.53
7.0.190.0070.01015.59
7.0.180.0070.01015.55
7.0.170.0060.00915.38
7.0.160.0030.00615.39
7.0.150.0030.01015.80
7.0.140.0040.04118.84
7.0.130.0090.00615.73
7.0.120.0090.00615.65
7.0.110.0110.00415.70
7.0.100.0050.02617.75
7.0.90.0090.02417.83
7.0.80.0180.02517.88
7.0.70.0060.02017.78
7.0.60.0070.02217.70
7.0.50.0040.02217.96
7.0.40.0080.04116.99
7.0.30.0060.04416.82
7.0.20.0050.03016.82
7.0.10.0160.03516.88
7.0.00.0040.03416.85
5.6.400.0060.01214.53
5.6.390.0070.00714.79
5.6.380.0030.01014.57
5.6.370.0040.00814.60
5.6.360.0040.01114.66
5.6.350.0070.00714.81
5.6.340.0060.00814.73
5.6.330.0100.01014.88
5.6.320.0110.00714.86
5.6.310.0070.01014.67
5.6.300.0030.00614.59
5.6.290.0040.01414.75
5.6.280.0070.04017.89
5.6.270.0070.00714.63
5.6.260.0060.00614.68
5.6.250.0030.02617.84
5.6.240.0100.03917.58
5.6.230.0080.02517.56
5.6.220.0080.01817.56
5.6.210.0070.02017.71
5.6.200.0060.02017.76
5.6.190.0030.02517.83
5.6.180.0110.03717.96
5.6.170.0080.04417.79
5.6.160.0020.04717.92
5.6.150.0060.03117.79
5.6.140.0070.04118.00
5.6.130.0070.04617.99
5.6.120.0110.02817.81
5.6.110.0140.03517.89
5.6.100.0020.02817.67
5.6.90.0060.02517.79
5.6.80.0070.02517.40
5.6.70.0070.02517.36
5.6.60.0020.03917.50
5.6.50.0090.04217.44
5.6.40.0120.03317.44
5.6.30.0070.04517.52
5.6.20.0070.03517.56
5.6.10.0100.02217.27
5.6.00.0060.03817.46
5.5.380.0080.02017.57
5.5.370.0060.02317.58
5.5.360.0020.02817.40
5.5.350.0020.02217.57
5.5.340.0020.02617.87
5.5.330.0050.03017.76
5.5.320.0070.04217.77
5.5.310.0080.04217.65
5.5.300.0030.03317.78
5.5.290.0120.02217.59
5.5.280.0070.04217.79
5.5.270.0120.03817.66
5.5.260.0070.03517.52
5.5.250.0080.02217.69
5.5.240.0020.02917.44
5.5.230.0080.03817.37
5.5.220.0090.04417.44
5.5.210.0070.04017.20
5.5.200.0130.03317.20
5.5.190.0050.03417.37
5.5.180.0070.03817.34
5.5.170.0000.01014.60
5.5.160.0080.03517.41
5.5.150.0100.04217.38
5.5.140.0030.03017.38
5.5.130.0080.04217.23
5.5.120.0030.03317.24
5.5.110.0030.02717.38
5.5.100.0030.04917.39
5.5.90.0060.03917.29
5.5.80.0070.02417.32
5.5.70.0070.03817.31
5.5.60.0100.02517.33
5.5.50.0120.02317.40
5.5.40.0130.02717.33
5.5.30.0050.03117.25
5.5.20.0030.03617.30
5.5.10.0020.02617.27
5.5.00.0100.02717.14
5.4.450.0050.03715.83
5.4.440.0100.04015.92
5.4.430.0150.02015.82
5.4.420.0060.02315.87
5.4.410.0030.04015.85
5.4.400.0060.02215.71
5.4.390.0020.02615.64
5.4.380.0040.04215.71
5.4.370.0130.03615.79
5.4.360.0030.03015.79
5.4.350.0070.02815.75
5.4.340.0060.02615.79
5.4.330.0060.00612.38
5.4.320.0080.04115.76
5.4.310.0100.03215.76
5.4.300.0110.04215.68
5.4.290.0120.03815.71
5.4.280.0070.02715.70
5.4.270.0070.02015.79
5.4.260.0030.03815.65
5.4.250.0050.03415.71
5.4.240.0100.04015.76
5.4.230.0000.03815.77
5.4.220.0050.02315.61
5.4.210.0020.04015.79
5.4.200.0120.03515.71
5.4.190.0070.03215.74
5.4.180.0020.02415.78
5.4.170.0040.02315.61
5.4.160.0020.04715.61
5.4.150.0090.02415.70
5.4.140.0090.04014.42
5.4.130.0090.03714.32
5.4.120.0030.02514.36
5.4.110.0080.04014.44
5.4.100.0120.01714.33
5.4.90.0030.04114.38
5.4.80.0060.02114.42
5.4.70.0040.02314.42
5.4.60.0060.02214.37
5.4.50.0050.02214.43
5.4.40.0020.03714.44
5.4.30.0050.02314.44
5.4.20.0060.03614.42
5.4.10.0070.02714.41
5.4.00.0060.03014.13
5.3.290.0100.01813.59
5.3.280.0050.02513.55
5.3.270.0030.04013.57
5.3.260.0050.02713.51
5.3.250.0030.02813.47
5.3.240.0020.03813.52
5.3.230.0030.03713.49
5.3.220.0070.03513.53
5.3.210.0030.04013.54
5.3.200.0040.03313.54
5.3.190.0020.02513.53
5.3.180.0030.03313.45
5.3.170.0040.02513.47
5.3.160.0050.02213.45
5.3.150.0040.03413.54
5.3.140.0040.01813.48
5.3.130.0030.02613.49
5.3.120.0070.02013.47
5.3.110.0050.02413.44
5.3.100.0010.03113.19
5.3.90.0060.03913.23
5.3.80.0100.03013.26
5.3.70.0000.03413.21
5.3.60.0050.03913.26
5.3.50.0050.02913.16
5.3.40.0020.03513.17
5.3.30.0030.03413.13
5.3.20.0050.03813.11
5.3.10.0050.03213.05
5.3.00.0060.04013.02
5.2.170.0070.05311.14
5.2.160.0100.05711.04
5.2.150.0030.03711.18
5.2.140.0130.05311.27
5.2.130.0070.05011.23
5.2.120.0030.03311.14
5.2.110.0070.06010.96
5.2.100.0030.04011.02
5.2.90.0070.02711.10
5.2.80.0100.05011.21
5.2.70.0030.06011.12
5.2.60.0030.03310.98
5.2.50.0000.03311.09
5.2.40.0170.05010.86
5.2.30.0030.06310.89
5.2.20.0070.04711.00
5.2.10.0030.03310.98
5.2.00.0100.05710.77
5.1.60.0000.02710.09
5.1.50.0070.05010.05
5.1.40.0000.03010.02
5.1.30.0030.05710.29
5.1.20.0030.04310.29
5.1.10.0070.05010.17
5.1.00.0100.05010.14
5.0.50.0070.0438.41
5.0.40.0070.0138.47
5.0.30.0030.0638.29
5.0.20.0000.0308.24
5.0.10.0000.0338.23
5.0.00.0000.0678.22
4.4.90.0000.0308.16
4.4.80.0000.0238.16
4.4.70.0030.0278.16
4.4.60.0070.0308.16
4.4.50.0030.0338.16
4.4.40.0070.0278.16
4.4.30.0070.0108.16
4.4.20.0000.0238.16
4.4.10.0030.0178.16
4.4.00.0030.0408.16
4.3.110.0030.0378.16
4.3.100.0030.0338.16
4.3.90.0030.0308.16
4.3.80.0030.0408.16
4.3.70.0030.0178.16
4.3.60.0000.0208.16
4.3.50.0030.0178.16
4.3.40.0000.0538.16
4.3.30.0000.0208.16
4.3.20.0070.0278.16
4.3.10.0000.0278.16
4.3.00.0000.0378.16

preferences:
58.73 ms | 401 KiB | 5 Q