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, $this->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.88
8.3.60.0120.00318.93
8.3.50.0150.00722.23
8.3.40.0090.00919.23
8.3.30.0110.00320.17
8.3.20.0030.00620.35
8.3.10.0030.00621.97
8.3.00.0040.00422.29
8.2.180.0120.00617.00
8.2.170.0070.00722.96
8.2.160.0040.01122.26
8.2.150.0060.00324.18
8.2.140.0000.00824.66
8.2.130.0030.00526.16
8.2.120.0000.00818.00
8.2.110.0090.00022.12
8.2.100.0000.01218.16
8.2.90.0040.00419.25
8.2.80.0050.00319.46
8.2.70.0050.00317.75
8.2.60.0030.00618.04
8.2.50.0040.00418.07
8.2.40.0000.00818.34
8.2.30.0040.00418.14
8.2.20.0030.00517.98
8.2.10.0040.00417.89
8.2.00.0030.00617.93
8.1.280.0030.01325.92
8.1.270.0040.00424.66
8.1.260.0080.00026.35
8.1.250.0040.00428.09
8.1.240.0060.00323.98
8.1.230.0060.00619.13
8.1.220.0000.00817.79
8.1.210.0080.00018.77
8.1.200.0030.00617.73
8.1.190.0080.00017.66
8.1.180.0030.00718.10
8.1.170.0030.00618.73
8.1.160.0070.00019.00
8.1.150.0040.00418.76
8.1.140.0040.00417.71
8.1.130.0000.00717.90
8.1.120.0000.00817.68
8.1.110.0040.00417.54
8.1.100.0030.00517.57
8.1.90.0020.00517.64
8.1.80.0000.00817.62
8.1.70.0040.00417.59
8.1.60.0040.00417.67
8.1.50.0040.00417.68
8.1.40.0030.00617.71
8.1.30.0000.00817.73
8.1.20.0030.00517.89
8.1.10.0060.00317.70
8.1.00.0060.00317.74
8.0.300.0070.00018.77
8.0.290.0040.00417.18
8.0.280.0000.00718.37
8.0.270.0000.00717.21
8.0.260.0000.00716.96
8.0.250.0030.00317.23
8.0.240.0130.00017.26
8.0.230.0070.00017.20
8.0.220.0040.00417.07
8.0.210.0000.00717.04
8.0.200.0000.00717.10
8.0.190.0080.00017.28
8.0.180.0030.00517.25
8.0.170.0020.00517.15
8.0.160.0050.00217.16
8.0.150.0080.00017.07
8.0.140.0030.00617.13
8.0.130.0030.00313.63
8.0.120.0090.00017.02
8.0.110.0000.00817.10
8.0.100.0040.00416.97
8.0.90.0080.00016.95
8.0.80.0070.00717.14
8.0.70.0040.00416.99
8.0.60.0030.00517.14
8.0.50.0060.00317.13
8.0.30.0100.01217.37
8.0.20.0090.01017.57
8.0.10.0040.00417.31
8.0.00.0080.01317.26
7.4.330.0000.00515.00
7.4.320.0030.00316.87
7.4.300.0060.00016.81
7.4.290.0050.00516.86
7.4.280.0000.00716.77
7.4.270.0000.00716.75
7.4.260.0040.00413.51
7.4.250.0000.00816.66
7.4.240.0020.00516.73
7.4.230.0030.00316.77
7.4.220.0040.01516.93
7.4.210.0060.00916.90
7.4.200.0040.00416.74
7.4.190.0040.00416.75
7.4.160.0080.01116.79
7.4.150.0150.01217.40
7.4.140.0140.00717.86
7.4.130.0110.00616.80
7.4.120.0140.01116.79
7.4.110.0120.00616.78
7.4.100.0130.01016.67
7.4.90.0060.01216.78
7.4.80.0000.02119.39
7.4.70.0070.01116.75
7.4.60.0080.00816.86
7.4.50.0000.00816.58
7.4.40.0160.00022.77
7.4.30.0120.00916.66
7.4.00.0040.01315.24
7.3.330.0060.00013.64
7.3.320.0030.00313.70
7.3.310.0070.00016.61
7.3.300.0070.00016.61
7.3.290.0150.00016.60
7.3.280.0040.01216.60
7.3.270.0100.00717.40
7.3.260.0060.01116.73
7.3.250.0090.01016.63
7.3.240.0110.00716.70
7.3.230.0070.01116.67
7.3.210.0040.01916.73
7.3.200.0120.00719.39
7.3.190.0070.01416.89
7.3.180.0110.00616.54
7.3.170.0060.01216.79
7.3.160.0080.01116.82
7.3.120.0110.00515.08
7.3.110.0090.00915.21
7.3.100.0060.01015.11
7.3.90.0040.01115.10
7.3.80.0040.01115.00
7.3.70.0070.00914.99
7.3.60.0080.00715.09
7.3.50.0020.00915.17
7.3.40.0080.00515.23
7.3.30.0140.00314.99
7.3.20.0080.00816.97
7.3.10.0070.00516.69
7.3.00.0070.01016.83
7.2.330.0160.00416.90
7.2.320.0080.01217.01
7.2.310.0150.00417.07
7.2.300.0070.01017.01
7.2.290.0170.00016.88
7.2.250.0040.01515.38
7.2.240.0030.01715.28
7.2.230.0070.01115.29
7.2.220.0050.01015.11
7.2.210.0070.00915.32
7.2.200.0040.01115.22
7.2.190.0060.00715.33
7.2.180.0070.00715.39
7.2.170.0080.01015.37
7.2.160.0130.00615.21
7.2.150.0090.00917.07
7.2.140.0070.00717.19
7.2.130.0070.01017.10
7.2.120.0090.00917.09
7.2.110.0050.00916.96
7.2.100.0070.00917.19
7.2.90.0060.00817.03
7.2.80.0060.00917.23
7.2.70.0110.00617.07
7.2.60.0050.01116.91
7.2.50.0100.00817.16
7.2.40.0050.00817.04
7.2.30.0060.01017.14
7.2.20.0040.01017.11
7.2.10.0060.00917.09
7.2.00.0070.01017.97
7.1.330.0050.00916.12
7.1.320.0020.00816.03
7.1.310.0090.00516.10
7.1.300.0080.00615.98
7.1.290.0050.00615.81
7.1.280.0070.00616.01
7.1.270.0020.01316.00
7.1.260.0050.01016.01
7.1.250.0020.01316.11
7.1.240.0050.01116.02
7.1.230.0020.01315.97
7.1.220.0050.00815.95
7.1.210.0040.01115.95
7.1.200.0090.00615.94
7.1.190.0080.00515.95
7.1.180.0070.00715.96
7.1.170.0040.01115.89
7.1.160.0050.00715.80
7.1.150.0030.00915.92
7.1.140.0040.00915.63
7.1.130.0020.01215.69
7.1.120.0050.00715.91
7.1.110.0030.01215.64
7.1.100.0040.00916.89
7.1.90.0080.00715.77
7.1.80.0050.01315.85
7.1.70.0050.00816.41
7.1.60.0080.00917.15
7.1.50.0100.00922.42
7.1.40.0070.00815.94
7.1.30.0090.00215.93
7.1.20.0040.01215.76
7.1.10.0070.00515.86
7.1.00.0050.01818.08
7.0.330.0040.00915.57
7.0.320.0090.00715.65
7.0.310.0050.01015.51
7.0.300.0070.00515.48
7.0.290.0050.00715.61
7.0.280.0060.00815.56
7.0.270.0080.00815.63
7.0.260.0090.00615.63
7.0.250.0060.00615.48
7.0.240.0080.00815.51
7.0.230.0080.01115.61
7.0.220.0060.00915.41
7.0.210.0000.01115.58
7.0.200.0090.00915.47
7.0.190.0000.01115.64
7.0.180.0090.00615.62
7.0.170.0040.00615.57
7.0.160.0030.00915.65
7.0.150.0050.00915.56
7.0.140.0060.02917.71
7.0.130.0050.00715.72
7.0.120.0030.01215.56
7.0.110.0080.00815.54
7.0.100.0170.03416.94
7.0.90.0160.03417.58
7.0.80.0080.03117.06
7.0.70.0140.02916.92
7.0.60.0110.02217.08
7.0.50.0100.03717.19
7.0.40.0070.03015.70
7.0.30.0070.03615.77
7.0.20.0040.03415.70
7.0.10.0020.03615.81
7.0.00.0010.03815.71
5.6.400.0060.00914.60
5.6.390.0100.00914.72
5.6.380.0060.01114.69
5.6.370.0050.00714.50
5.6.360.0100.00614.72
5.6.350.0020.01414.56
5.6.340.0090.00914.61
5.6.330.0020.01514.67
5.6.320.0030.01314.53
5.6.310.0020.01214.38
5.6.300.0070.00714.47
5.6.290.0080.00614.47
5.6.280.0060.02716.59
5.6.270.0080.00514.41
5.6.260.0100.00514.62
5.6.250.0070.03016.64
5.6.240.0060.03316.63
5.6.230.0050.03116.58
5.6.220.0060.02716.50
5.6.210.0060.03316.65
5.6.200.0100.02316.69
5.6.190.0070.03616.62
5.6.180.0080.03216.78
5.6.170.0050.03716.78
5.6.160.0090.03116.71
5.6.150.0030.02316.77
5.6.140.0080.03016.77
5.6.130.0090.03016.77
5.6.120.0090.03116.69
5.6.110.0080.01816.70
5.6.100.0060.02316.59
5.6.90.0040.03116.79
5.6.80.0040.03316.43
5.6.70.0090.01716.46
5.6.60.0090.03116.36
5.6.50.0080.01916.49
5.6.40.0060.02416.52
5.6.30.0060.02916.48
5.6.20.0090.02916.36
5.6.10.0040.02616.56
5.6.00.0080.01616.43
5.5.380.0090.01915.42
5.5.370.0080.02315.56
5.5.360.0090.03015.56
5.5.350.0040.03315.46
5.5.340.0030.02415.66
5.5.330.0080.03115.66
5.5.320.0160.02815.67
5.5.310.0070.02015.71
5.5.300.0020.02315.66
5.5.290.0100.03015.67
5.5.280.0050.03015.68
5.5.270.0090.03015.67
5.5.260.0070.02215.68
5.5.250.0080.02515.62
5.5.240.0090.02915.46
5.5.230.0080.01715.30
5.5.220.0050.03215.43
5.5.210.0040.02115.41
5.5.200.0090.02415.47
5.5.190.0080.01815.33
5.5.180.0040.02615.47
5.5.170.0030.00813.02
5.5.160.0030.02315.45
5.5.150.0000.02515.42
5.5.140.0020.02115.36
5.5.130.0070.01715.38
5.5.120.0060.01515.37
5.5.110.0040.01815.33
5.5.100.0050.01815.37
5.5.90.0000.02215.39
5.5.80.0070.02115.39
5.5.70.0070.01715.36
5.5.60.0040.01815.40
5.5.50.0080.02415.32
5.5.40.0070.02315.27
5.5.30.0070.01815.38
5.5.20.0090.01815.37
5.5.10.0070.02015.26
5.5.00.0040.03115.38
5.4.450.0080.02914.15
5.4.440.0070.02514.18
5.4.430.0040.02614.02
5.4.420.0030.02314.21
5.4.410.0060.03014.11
5.4.400.0060.03013.97
5.4.390.0040.02914.02
5.4.380.0060.02913.92
5.4.370.0090.02913.98
5.4.360.0070.02914.06
5.4.350.0050.01913.91
5.4.340.0080.03013.93
5.4.330.0050.00511.43
5.4.320.0060.01814.01
5.4.310.0030.01913.82
5.4.300.0020.02014.04
5.4.290.0060.01614.05
5.4.280.0040.01813.85
5.4.270.0030.01713.87
5.4.260.0010.01814.06
5.4.250.0040.01613.92
5.4.240.0070.01513.92
5.4.230.0070.01813.88
5.4.220.0040.02113.95
5.4.210.0000.02213.84
5.4.200.0050.01813.91
5.4.190.0020.01613.92
5.4.180.0080.01714.05
5.4.170.0050.01413.86
5.4.160.0020.01613.99
5.4.150.0080.01413.88
5.4.140.0030.01813.06
5.4.130.0070.02013.04
5.4.120.0040.01913.08
5.4.110.0030.01913.04
5.4.100.0060.01313.08
5.4.90.0030.03213.01
5.4.80.0050.02012.92
5.4.70.0070.01513.03
5.4.60.0040.01913.01
5.4.50.0040.01513.15
5.4.40.0020.01813.04
5.4.30.0040.01613.00
5.4.20.0020.03113.03
5.4.10.0040.03013.11
5.4.00.0070.02012.73
5.3.290.0030.02912.31
5.3.280.0040.02312.29
5.3.270.0050.01412.27
5.3.260.0050.01512.28
5.3.250.0020.01812.25
5.3.240.0020.01612.27
5.3.230.0070.01312.25
5.3.220.0090.01912.25
5.3.210.0050.01612.25
5.3.200.0030.02112.26
5.3.190.0070.02612.28
5.3.180.0030.01612.24
5.3.170.0050.01612.23
5.3.160.0020.02012.23
5.3.150.0060.02112.25
5.3.140.0050.01712.23
5.3.130.0050.01712.23
5.3.120.0030.01612.26
5.3.110.0030.02912.27
5.3.100.0040.02812.10
5.3.90.0040.02612.04
5.3.80.0080.02412.06
5.3.70.0050.02512.06
5.3.60.0090.01612.10
5.3.50.0040.01912.07
5.3.40.0050.01912.04
5.3.30.0010.02312.03
5.3.20.0050.02511.98
5.3.10.0100.02111.91
5.3.00.0070.02211.93
5.2.170.0050.02711.37
5.2.160.0050.03411.33
5.2.150.0060.03011.43
5.2.140.0020.03711.32
5.2.130.0030.02211.42
5.2.120.0110.02811.35
5.2.110.0040.03411.35
5.2.100.0030.01811.32
5.2.90.0030.03011.40
5.2.80.0070.02311.35
5.2.70.0030.02211.40
5.2.60.0020.03311.34
5.2.50.0070.02811.37
5.2.40.0030.01611.31
5.2.30.0060.02711.22
5.2.20.0050.02311.25
5.2.10.0030.03211.30
5.2.00.0080.02511.12
5.1.60.0020.01710.83
5.1.50.0010.02010.87
5.1.40.0080.02510.71
5.1.30.0020.03110.98
5.1.20.0050.02510.94
5.1.10.0040.02310.89
5.1.00.0060.03410.84
5.0.50.0010.02510.13
5.0.40.0090.01710.06
5.0.30.0020.03410.06
5.0.20.0070.01010.06
5.0.10.0020.02010.06
5.0.00.0060.02210.06
4.4.90.0030.01610.06
4.4.80.0020.01510.06
4.4.70.0030.01010.06
4.4.60.0030.01710.06
4.4.50.0000.01510.06
4.4.40.0030.01210.06
4.4.30.0010.01810.06
4.4.20.0020.01310.06
4.4.10.0030.01710.06
4.4.00.0020.02310.06
4.3.110.0050.01710.06
4.3.100.0060.01210.06
4.3.90.0030.01310.06
4.3.80.0050.01210.06
4.3.70.0050.01710.06
4.3.60.0000.01210.06
4.3.50.0020.02010.06
4.3.40.0030.02510.06
4.3.30.0040.02010.06
4.3.20.0020.01310.06
4.3.10.0020.01810.06
4.3.00.0030.01510.06

preferences:
42.11 ms | 401 KiB | 5 Q