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', 'Niels Faverskov' ]; $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.0130.00617.13
8.3.60.0070.01118.56
8.3.50.0150.00521.27
8.3.40.0110.00419.00
8.3.30.0040.01120.18
8.3.20.0040.00420.39
8.3.10.0040.00422.05
8.3.00.0090.00022.35
8.2.180.0120.00316.88
8.2.170.0140.00722.96
8.2.160.0100.00322.16
8.2.150.0150.00424.18
8.2.140.0140.00624.66
8.2.130.0040.00426.16
8.2.120.0030.00520.78
8.2.110.0030.00622.16
8.2.100.0090.00318.03
8.2.90.0030.00619.40
8.2.80.0000.00819.21
8.2.70.0030.00617.75
8.2.60.0050.00318.05
8.2.50.0040.00418.07
8.2.40.0030.00618.34
8.2.30.0040.00419.55
8.2.20.0040.00417.99
8.2.10.0040.00417.90
8.2.00.0080.00017.93
8.1.280.0070.00725.92
8.1.270.0030.00523.99
8.1.260.0060.00326.35
8.1.250.0080.00028.09
8.1.240.0060.00323.91
8.1.230.0090.00323.93
8.1.220.0040.00417.77
8.1.210.0050.00318.77
8.1.200.0090.00017.47
8.1.190.0080.00017.66
8.1.180.0030.00619.14
8.1.170.0040.00418.59
8.1.160.0080.00020.57
8.1.150.0070.00418.82
8.1.140.0040.00417.63
8.1.130.0000.00817.89
8.1.120.0040.00417.59
8.1.110.0040.00417.64
8.1.100.0030.00517.61
8.1.90.0000.00817.60
8.1.80.0040.00417.55
8.1.70.0040.00417.66
8.1.60.0060.00317.78
8.1.50.0090.00017.63
8.1.40.0030.00617.72
8.1.30.0000.00817.85
8.1.20.0060.00317.74
8.1.10.0080.00017.64
8.1.00.0070.00417.73
8.0.300.0050.00218.77
8.0.290.0040.00417.04
8.0.280.0000.00718.55
8.0.270.0040.00416.94
8.0.260.0030.00318.50
8.0.250.0000.00717.05
8.0.240.0080.00017.13
8.0.230.0050.00317.11
8.0.220.0070.00016.96
8.0.210.0000.00717.08
8.0.200.0040.00417.10
8.0.190.0030.00517.13
8.0.180.0080.00017.13
8.0.170.0060.00317.08
8.0.160.0040.00417.01
8.0.150.0000.00716.95
8.0.140.0000.00716.96
8.0.130.0030.00313.54
8.0.120.0070.00017.07
8.0.110.0050.00217.16
8.0.100.0000.00816.91
8.0.90.0050.00316.91
8.0.80.0090.00617.04
8.0.70.0000.00717.04
8.0.60.0000.00817.12
8.0.50.0070.00016.87
8.0.30.0120.00917.49
8.0.20.0120.01117.40
8.0.10.0040.00417.02
8.0.00.0110.01216.98
7.4.330.0030.00315.04
7.4.320.0070.00016.74
7.4.300.0030.00316.75
7.4.290.0000.00716.87
7.4.280.0050.00316.84
7.4.270.0000.00716.78
7.4.260.0040.00413.52
7.4.250.0000.00716.77
7.4.240.0060.00116.85
7.4.230.0040.00416.75
7.4.220.0060.01216.69
7.4.210.0070.00816.79
7.4.200.0100.00016.83
7.4.190.0000.00717.03
7.4.160.0040.01516.84
7.4.150.0090.00917.40
7.4.140.0150.00617.86
7.4.130.0050.01316.77
7.4.120.0080.01016.80
7.4.110.0070.01116.59
7.4.100.0060.01316.68
7.4.90.0170.00316.73
7.4.80.0120.00619.39
7.4.70.0120.00916.85
7.4.60.0150.00416.63
7.4.50.0040.00416.55
7.4.40.0030.01022.77
7.4.30.0090.00816.78
7.4.10.0040.01614.85
7.4.00.0040.01215.38
7.3.330.0000.00513.58
7.3.320.0030.00313.41
7.3.310.0030.00316.61
7.3.300.0000.00816.61
7.3.290.0000.01516.57
7.3.280.0060.01216.51
7.3.270.0040.01317.40
7.3.260.0120.00616.58
7.3.250.0060.01216.69
7.3.240.0080.01216.68
7.3.230.0070.01116.70
7.3.210.0040.01316.80
7.3.200.0090.01519.39
7.3.190.0100.00716.73
7.3.180.0120.00916.75
7.3.170.0030.01916.55
7.3.160.0060.01116.72
7.3.130.0080.01115.07
7.3.120.0020.01715.01
7.3.110.0090.00615.11
7.3.100.0140.00015.31
7.3.90.0040.01415.33
7.3.80.0040.00815.14
7.3.70.0080.00815.09
7.3.60.0090.00614.80
7.3.50.0040.00914.89
7.3.40.0040.01215.16
7.3.30.0090.00315.18
7.3.20.0070.00716.54
7.3.10.0080.00716.80
7.3.00.0070.00716.74
7.2.330.0080.00916.84
7.2.320.0150.00316.87
7.2.310.0080.00816.76
7.2.300.0070.01016.83
7.2.290.0140.00717.05
7.2.260.0030.01415.40
7.2.250.0160.00015.54
7.2.240.0090.00615.54
7.2.230.0060.01015.46
7.2.220.0040.01115.45
7.2.210.0000.00915.41
7.2.200.0060.00815.04
7.2.190.0100.00315.18
7.2.180.0000.01515.25
7.2.170.0090.00315.25
7.2.160.0000.01715.27
7.2.150.0030.01217.02
7.2.140.0000.01217.05
7.2.130.0110.00717.23
7.2.120.0100.00417.06
7.2.110.0080.00717.03
7.2.100.0040.01117.14
7.2.90.0070.00916.86
7.2.80.0120.00417.03
7.2.70.0090.00617.04
7.2.60.0050.01016.91
7.2.50.0110.00617.17
7.2.40.0090.00616.84
7.2.30.0050.01217.07
7.2.20.0090.00717.11
7.2.10.0060.00917.13
7.2.00.0080.00717.71
7.1.330.0030.01015.93
7.1.320.0070.01316.23
7.1.310.0060.00915.86
7.1.300.0030.00915.86
7.1.290.0060.00916.12
7.1.280.0030.01016.14
7.1.270.0080.00616.14
7.1.260.0100.00715.98
7.1.250.0070.00715.93
7.1.240.0030.00615.98
7.1.230.0110.00316.11
7.1.220.0070.00315.96
7.1.210.0000.01615.78
7.1.200.0110.00316.00
7.1.190.0060.00615.94
7.1.180.0060.00616.09
7.1.170.0000.01516.12
7.1.160.0040.01116.16
7.1.150.0040.01216.13
7.1.140.0000.01415.79
7.1.130.0080.00315.68
7.1.120.0100.00315.90
7.1.110.0000.01316.13
7.1.100.0070.00517.13
7.1.90.0080.00815.98
7.1.80.0090.00616.01
7.1.70.0060.00416.70
7.1.60.0060.01117.66
7.1.50.0070.00516.44
7.1.40.0110.00315.68
7.1.30.0000.01416.00
7.1.20.0030.00915.74
7.1.10.0060.00615.75
7.1.00.0090.01619.14
7.0.330.0070.00715.62
7.0.320.0080.00015.63
7.0.310.0150.00315.73
7.0.300.0040.01115.70
7.0.290.0120.00015.63
7.0.280.0130.00015.74
7.0.270.0030.01215.52
7.0.260.0030.00915.77
7.0.250.0040.00815.50
7.0.240.0070.01115.55
7.0.230.0070.00715.57
7.0.220.0070.00715.57
7.0.210.0070.00715.47
7.0.200.0030.00816.14
7.0.190.0000.01615.71
7.0.180.0080.00815.68
7.0.170.0060.00615.29
7.0.160.0030.00915.80
7.0.150.0030.01015.44
7.0.140.0070.03818.95
7.0.130.0120.00015.67
7.0.120.0000.01315.44
7.0.110.0000.00915.66
7.0.100.0060.04117.68
7.0.90.0090.03917.73
7.0.80.0050.04517.69
7.0.70.0070.02717.80
7.0.60.0050.04517.79
7.0.50.0090.04118.07
7.0.40.0160.03816.75
7.0.30.0030.05216.79
7.0.20.0030.04316.85
7.0.10.0070.04616.84
7.0.00.0090.04516.88
5.6.400.0070.00714.68
5.6.390.0030.00614.44
5.6.380.0030.00614.89
5.6.370.0120.00614.42
5.6.360.0000.01614.60
5.6.350.0090.00614.92
5.6.340.0060.00914.76
5.6.330.0080.00314.57
5.6.320.0030.01314.30
5.6.310.0070.00614.84
5.6.300.0120.00614.68
5.6.290.0040.01214.62
5.6.280.0030.04517.67
5.6.270.0090.00614.82
5.6.260.0120.00314.51
5.6.250.0060.04617.61
5.6.240.0120.04017.57
5.6.230.0080.04617.47
5.6.220.0030.02817.51
5.6.210.0100.04217.52
5.6.200.0050.04217.76
5.6.190.0070.04317.83
5.6.180.0050.03417.73
5.6.170.0030.04617.77
5.6.160.0110.04217.71
5.6.150.0100.04217.67
5.6.140.0040.04917.84
5.6.130.0050.05117.74
5.6.120.0080.04517.83
5.6.110.0050.04217.70
5.6.100.0030.04217.68
5.6.90.0140.03417.78
5.6.80.0090.02717.44
5.6.70.0070.03717.38
5.6.60.0130.03717.46
5.6.50.0080.04217.44
5.6.40.0110.03817.39
5.6.30.0120.04217.46
5.6.20.0050.04517.56
5.6.10.0100.03617.44
5.6.00.0090.03917.45
5.5.380.0070.04217.54
5.5.370.0120.03717.49
5.5.360.0050.04717.65
5.5.350.0130.04117.48
5.5.340.0080.04217.79
5.5.330.0060.04617.58
5.5.320.0030.05617.67
5.5.310.0070.05017.55
5.5.300.0100.04217.60
5.5.290.0110.04617.62
5.5.280.0090.04817.67
5.5.270.0120.04417.65
5.5.260.0110.04117.70
5.5.250.0050.05117.44
5.5.240.0030.04817.32
5.5.230.0050.04517.36
5.5.220.0100.04217.26
5.5.210.0080.04217.24
5.5.200.0080.04317.10
5.5.190.0050.04217.28
5.5.180.0100.04117.17
5.5.170.0060.00914.59
5.5.160.0050.03717.39
5.5.150.0070.04117.37
5.5.140.0100.04017.42
5.5.130.0080.04517.37
5.5.120.0070.03817.36
5.5.110.0100.03717.20
5.5.100.0080.04517.21
5.5.90.0080.04217.12
5.5.80.0100.04217.22
5.5.70.0060.04117.33
5.5.60.0030.04317.31
5.5.50.0070.04517.36
5.5.40.0020.04517.24
5.5.30.0080.03717.09
5.5.20.0070.04417.22
5.5.10.0070.04117.29
5.5.00.0050.04617.28
5.4.450.0120.03815.24
5.4.440.0100.03515.28
5.4.430.0070.04115.32
5.4.420.0130.03515.33
5.4.410.0050.03315.35
5.4.400.0050.04115.14
5.4.390.0060.04114.96
5.4.380.0110.03915.12
5.4.370.0030.04415.09
5.4.360.0120.04115.07
5.4.350.0050.04015.13
5.4.340.0050.04215.08
5.4.330.0060.00911.30
5.4.320.0050.02715.25
5.4.310.0050.04515.07
5.4.300.0100.03815.07
5.4.290.0070.04415.17
5.4.280.0070.02215.17
5.4.270.0070.04215.03
5.4.260.0040.04414.98
5.4.250.0090.03615.01
5.4.240.0070.04115.00
5.4.230.0030.03815.20
5.4.220.0050.04315.10
5.4.210.0070.03815.17
5.4.200.0080.04014.89
5.4.190.0070.04115.23
5.4.180.0070.04315.03
5.4.170.0060.02815.03
5.4.160.0060.03115.00
5.4.150.0120.03714.97
5.4.140.0020.03313.71
5.4.130.0110.03613.84
5.4.120.0080.03613.78
5.4.110.0030.04513.65
5.4.100.0050.04013.68
5.4.90.0030.03713.79
5.4.80.0000.04413.71
5.4.70.0080.03613.65
5.4.60.0050.04013.74
5.4.50.0030.04013.71
5.4.40.0090.03513.85
5.4.30.0030.04013.85
5.4.20.0040.02613.72
5.4.10.0050.02313.79
5.4.00.0020.02613.59
5.3.290.0070.04012.56
5.3.280.0090.03112.51
5.3.270.0080.03712.47
5.3.260.0050.04212.42
5.3.250.0090.03812.54
5.3.240.0070.03512.49
5.3.230.0060.03612.42
5.3.220.0050.04112.43
5.3.210.0020.02812.47
5.3.200.0050.02812.43
5.3.190.0070.04312.50
5.3.180.0060.03912.52
5.3.170.0080.03512.53
5.3.160.0040.04112.46
5.3.150.0070.04212.55
5.3.140.0050.04112.51
5.3.130.0030.04312.53
5.3.120.0070.03212.40
5.3.110.0050.02212.52
5.3.100.0030.02312.18
5.3.90.0020.02512.28
5.3.80.0030.02412.16
5.3.70.0050.02212.19
5.3.60.0070.02312.19
5.3.50.0020.02212.11
5.3.40.0020.02312.11
5.3.30.0050.03612.02
5.3.20.0030.02311.96
5.3.10.0060.02011.97
5.3.00.0050.01711.91
5.2.170.0000.03011.26
5.2.160.0030.03011.26
5.2.150.0000.03311.21
5.2.140.0000.03311.21
5.2.130.0000.03311.22
5.2.120.0000.03010.97
5.2.110.0070.02711.17
5.2.100.0000.03011.02
5.2.90.0030.03011.00
5.2.80.0100.02011.22
5.2.70.0030.02711.13
5.2.60.0070.02711.12
5.2.50.0000.03011.13
5.2.40.0070.04010.88
5.2.30.0030.03711.09
5.2.20.0000.03011.02
5.2.10.0030.02710.94
5.2.00.0000.05710.82
5.1.60.0070.04710.00
5.1.50.0070.04310.11
5.1.40.0070.0339.97
5.1.30.0000.03010.44
5.1.20.0030.03710.50
5.1.10.0030.03010.17
5.1.00.0100.02010.09
5.0.50.0030.0209.46
5.0.40.0030.0179.46
5.0.30.0000.0309.46
5.0.20.0000.0209.46
5.0.10.0030.0179.46
5.0.00.0000.0339.46
4.4.90.0000.0139.46
4.4.80.0030.0109.46
4.4.70.0000.0239.46
4.4.60.0030.0279.46
4.4.50.0030.0179.46
4.4.40.0030.0379.46
4.4.30.0000.0379.46
4.4.20.0000.0179.46
4.4.10.0000.0139.46
4.4.00.0000.0239.46
4.3.110.0030.0139.46
4.3.100.0000.0209.46
4.3.90.0000.0379.46
4.3.80.0000.0579.46
4.3.70.0000.0139.46
4.3.60.0000.0139.46
4.3.50.0030.0139.46
4.3.40.0000.0379.46
4.3.30.0000.0139.46
4.3.20.0000.0179.46
4.3.10.0000.0179.46
4.3.00.0030.0109.46

preferences:
50.7 ms | 401 KiB | 5 Q