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 = '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.60.0120.00316.75
8.3.50.0080.00722.26
8.3.40.0090.00619.17
8.3.30.0040.01119.18
8.3.20.0030.00520.18
8.3.10.0050.00323.48
8.3.00.0070.00722.46
8.2.180.0160.00316.75
8.2.170.0150.00022.96
8.2.160.0140.00320.44
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0030.01526.16
8.2.120.0080.00019.61
8.2.110.0130.00322.07
8.2.100.0000.01118.09
8.2.90.0030.00619.30
8.2.80.0040.00418.05
8.2.70.0000.00917.88
8.2.60.0040.00418.01
8.2.50.0030.00718.07
8.2.40.0030.00618.28
8.2.30.0000.00818.22
8.2.20.0080.00017.79
8.2.10.0000.00817.78
8.2.00.0050.00317.93
8.1.280.0140.00325.92
8.1.270.0060.00323.86
8.1.260.0060.00326.35
8.1.250.0030.00528.09
8.1.240.0060.00323.75
8.1.230.0030.00919.28
8.1.220.0050.00317.91
8.1.210.0040.00418.77
8.1.200.0080.00517.38
8.1.190.0000.00817.43
8.1.180.0060.00318.10
8.1.170.0060.00318.89
8.1.160.0060.00322.00
8.1.150.0040.00418.84
8.1.140.0000.00817.62
8.1.130.0030.00317.77
8.1.120.0000.00717.69
8.1.110.0040.00417.52
8.1.100.0040.00417.68
8.1.90.0040.00417.53
8.1.80.0000.00717.63
8.1.70.0000.00717.61
8.1.60.0110.00317.77
8.1.50.0030.00517.73
8.1.40.0030.00517.72
8.1.30.0000.00817.75
8.1.20.0000.00817.80
8.1.10.0000.00817.68
8.1.00.0050.00317.58
8.0.300.0040.00418.77
8.0.290.0060.00317.30
8.0.280.0030.00318.51
8.0.270.0000.00716.98
8.0.260.0040.00416.97
8.0.250.0000.00717.09
8.0.240.0000.00717.22
8.0.230.0020.00517.16
8.0.220.0050.00217.16
8.0.210.0000.00717.18
8.0.200.0070.00017.16
8.0.190.0060.00317.10
8.0.180.0060.00317.12
8.0.170.0050.00317.16
8.0.160.0030.00616.98
8.0.150.0030.00517.11
8.0.140.0040.00417.12
8.0.130.0030.00313.54
8.0.120.0060.00317.19
8.0.110.0060.00317.03
8.0.100.0040.00417.13
8.0.90.0080.00017.16
8.0.80.0120.00917.11
8.0.70.0000.00717.04
8.0.60.0000.00817.04
8.0.50.0030.00517.01
8.0.30.0090.01117.27
8.0.20.0060.01717.40
8.0.10.0040.00417.13
8.0.00.0140.01617.15
7.4.330.0020.00215.12
7.4.320.0000.00616.77
7.4.300.0060.00016.90
7.4.290.0070.00016.80
7.4.280.0000.00716.75
7.4.270.0030.00316.85
7.4.260.0030.00316.86
7.4.250.0050.00216.63
7.4.240.0030.00616.81
7.4.230.0000.00716.76
7.4.220.0060.01316.73
7.4.210.0050.01016.90
7.4.200.0040.00416.93
7.4.190.0000.00717.02
7.4.160.0130.01016.71
7.4.150.0150.00417.40
7.4.140.0140.01017.86
7.4.130.0080.01016.88
7.4.120.0110.00716.75
7.4.110.0100.00616.75
7.4.100.0040.01316.79
7.4.90.0090.00916.78
7.4.80.0030.01619.39
7.4.70.0090.01216.69
7.4.60.0030.01316.50
7.4.50.0030.00516.82
7.4.40.0090.00622.77
7.4.30.0030.01416.82
7.4.00.0120.00315.40
7.3.330.0000.00513.60
7.3.320.0050.00013.48
7.3.310.0030.00516.66
7.3.300.0000.00716.51
7.3.290.0130.00316.59
7.3.280.0080.00716.63
7.3.270.0130.00517.40
7.3.260.0070.01117.02
7.3.250.0090.00816.61
7.3.240.0120.00616.68
7.3.230.0070.01016.86
7.3.210.0100.01016.70
7.3.200.0120.00619.39
7.3.190.0030.01516.59
7.3.180.0090.00816.68
7.3.170.0080.00816.73
7.3.160.0150.00916.72
7.3.120.0090.00615.14
7.2.330.0090.01016.97
7.2.320.0060.01616.91
7.2.310.0130.00316.89
7.2.300.0060.01716.91
7.2.290.0030.01416.72
7.2.00.0030.00919.44
7.1.100.0030.01018.21
7.1.70.0080.00317.32
7.1.60.0080.01119.29
7.1.50.0070.01116.98
7.1.00.0070.07322.46
7.0.200.0000.00717.07
7.0.140.0100.06722.09
7.0.60.0100.08020.01
7.0.50.0070.04317.92
7.0.40.0070.09020.14
7.0.30.0230.04320.16
7.0.20.0200.04020.24
7.0.10.0030.05020.14
7.0.00.0030.09320.21
5.6.280.0070.07021.17
5.6.210.0130.07320.71
5.6.200.0200.05718.29
5.6.190.0170.08020.46
5.6.180.0130.04320.55
5.6.170.0130.04320.47
5.6.160.0030.06020.48
5.6.150.0000.04318.18
5.6.140.0130.04018.18
5.6.130.0030.04018.28
5.6.120.0070.09021.11
5.6.110.0170.08021.02
5.6.100.0070.06021.13
5.6.90.0100.08721.02
5.6.80.0070.08320.46
5.5.350.0200.08020.46
5.5.340.0330.03717.94
5.5.330.0030.04320.41
5.5.320.0200.08320.27
5.5.310.0270.06020.30
5.5.300.0130.05317.96
5.5.290.0200.06717.98
5.5.280.0030.08020.70
5.5.270.0070.07020.75
5.5.260.0170.07720.89
5.5.250.0100.07720.63
5.5.240.0000.07020.18
5.4.450.0630.04719.61
5.4.440.0870.05019.54
5.4.430.0070.06019.21
5.4.420.0170.05019.39
5.4.410.0170.04719.52
5.4.400.0130.05019.12
5.4.390.0070.05719.04
5.4.380.0070.06019.02
5.4.370.0330.06018.76
5.4.360.0630.05018.80
5.4.350.0370.04718.75
5.4.340.0270.06318.77
5.4.320.0110.03212.52
5.4.310.0050.04212.52
5.4.300.0080.03912.52
5.4.290.0060.03812.52
5.4.280.0030.04212.42
5.4.270.0080.03412.42
5.4.260.0070.03712.42
5.4.250.0060.03812.42
5.4.240.0070.03512.39
5.4.230.0090.04012.38
5.4.220.0070.04412.38
5.4.210.0090.04612.38
5.4.200.0040.04112.38
5.4.190.0040.03712.38
5.4.180.0020.03912.38
5.4.170.0010.04012.39
5.4.160.0040.03612.39
5.4.150.0080.03712.38
5.4.140.0040.04412.07
5.4.130.0050.03712.05
5.4.120.0080.03712.01
5.4.110.0050.04212.00
5.4.100.0050.03512.00
5.4.90.0040.03712.00
5.4.80.0070.04012.00
5.4.70.0030.03712.00
5.4.60.0060.03312.00
5.4.50.0040.03612.00
5.4.40.0050.03611.99
5.4.30.0060.03811.98
5.4.20.0030.03811.98
5.4.10.0070.03511.98
5.4.00.0070.03311.48
5.3.290.0080.03712.80
5.3.280.0060.04212.71
5.3.270.0090.04212.73
5.3.260.0070.04012.72
5.3.250.0080.03512.72
5.3.240.0050.03612.72
5.3.230.0050.03712.71
5.3.220.0050.03612.68
5.3.210.0040.04012.68
5.3.200.0080.03212.68
5.3.190.0080.03412.68
5.3.180.0070.03612.68
5.3.170.0050.03512.67
5.3.160.0080.04012.67
5.3.150.0050.03812.67
5.3.140.0080.03712.66
5.3.130.0040.04512.66
5.3.120.0030.04212.66
5.3.110.0040.04012.65
5.3.100.0070.03412.11
5.3.90.0050.04112.08
5.3.80.0060.04012.08
5.3.70.0070.03812.07
5.3.60.0070.04412.07
5.3.50.0050.03912.00
5.3.40.0050.03712.00
5.3.30.0050.03511.95
5.3.20.0010.04011.73
5.3.10.0080.03111.70
5.3.00.0040.04211.68
5.2.170.0030.0369.18
5.2.160.0060.0269.18
5.2.150.0060.0319.18
5.2.140.0040.0319.18
5.2.130.0040.0299.14
5.2.120.0030.0299.14
5.2.110.0020.0329.15
5.2.100.0060.0299.14
5.2.90.0050.0289.14
5.2.80.0020.0319.14
5.2.70.0060.0279.13
5.2.60.0030.0309.09
5.2.50.0040.0329.06
5.2.40.0060.0279.04
5.2.30.0060.0269.01
5.2.20.0030.0299.00
5.2.10.0050.0308.91
5.2.00.0010.0318.76
5.1.60.0030.0248.05
5.1.50.0030.0248.05
5.1.40.0020.0258.03
5.1.30.0040.0258.39
5.1.20.0040.0268.41
5.1.10.0040.0258.13
5.1.00.0040.0318.12
5.0.50.0030.0196.60
5.0.40.0020.0206.47
5.0.30.0040.0296.28
5.0.20.0050.0166.25
5.0.10.0040.0246.23
5.0.00.0000.0416.21
4.4.90.0020.0174.78
4.4.80.0030.0164.76
4.4.70.0020.0154.75
4.4.60.0020.0164.75
4.4.50.0010.0174.77
4.4.40.0040.0294.71
4.4.30.0020.0164.76
4.4.20.0060.0124.84
4.4.10.0030.0174.85
4.4.00.0020.0324.76
4.3.110.0020.0224.67
4.3.100.0020.0154.66
4.3.90.0010.0164.63
4.3.80.0020.0294.58
4.3.70.0040.0164.63
4.3.60.0000.0164.62
4.3.50.0020.0154.63
4.3.40.0030.0234.53
4.3.30.0020.0163.29
4.3.20.0010.0193.26
4.3.10.0000.0193.22
4.3.00.0170.0207.32

preferences:
41.73 ms | 401 KiB | 5 Q