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' ]; $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.0040.01118.68
8.3.50.0090.00921.27
8.3.40.0110.01119.08
8.3.30.0100.00320.26
8.3.20.0040.00419.08
8.3.10.0060.00320.95
8.3.00.0040.00423.65
8.2.180.0090.00925.92
8.2.170.0130.00719.04
8.2.160.0070.00722.96
8.2.150.0090.00025.66
8.2.140.0000.00824.66
8.2.130.0080.00026.16
8.2.120.0080.00019.77
8.2.110.0040.00720.35
8.2.100.0090.00317.91
8.2.90.0130.00018.98
8.2.80.0030.00618.04
8.2.70.0000.01117.88
8.2.60.0060.00318.05
8.2.50.0080.00018.07
8.2.40.0030.00718.21
8.2.30.0000.00719.51
8.2.20.0000.00817.83
8.2.10.0040.00418.00
8.2.00.0080.00017.81
8.1.270.0080.00024.66
8.1.260.0040.00426.35
8.1.250.0050.00328.09
8.1.240.0090.00021.11
8.1.230.0090.00319.04
8.1.220.0000.00817.78
8.1.210.0030.00518.77
8.1.200.0040.00717.60
8.1.190.0030.00617.38
8.1.180.0090.00018.10
8.1.170.0050.00318.89
8.1.160.0040.00418.91
8.1.150.0030.00618.89
8.1.140.0040.00417.56
8.1.130.0070.00017.73
8.1.120.0000.00717.59
8.1.110.0000.00817.55
8.1.100.0040.00417.55
8.1.90.0040.00417.52
8.1.80.0040.00417.53
8.1.70.0000.00717.68
8.1.60.0000.00917.78
8.1.50.0030.00617.72
8.1.40.0030.00617.72
8.1.30.0040.00417.67
8.1.20.0060.00317.89
8.1.10.0040.00417.81
8.1.00.0030.00617.73
8.0.300.0030.00520.05
8.0.290.0040.00416.88
8.0.280.0080.00018.50
8.0.270.0000.00817.32
8.0.260.0000.00717.01
8.0.250.0040.00417.06
8.0.240.0080.00417.02
8.0.230.0080.00017.15
8.0.220.0000.00816.99
8.0.210.0000.00717.12
8.0.200.0000.00717.13
8.0.190.0000.00717.07
8.0.180.0050.00316.99
8.0.170.0050.00317.03
8.0.160.0040.00417.04
8.0.150.0000.00717.01
8.0.140.0030.00616.94
8.0.130.0030.00313.48
8.0.120.0080.00017.05
8.0.110.0030.00517.13
8.0.100.0040.00417.11
8.0.90.0050.00316.95
8.0.80.0030.01417.11
8.0.70.0000.00816.90
8.0.60.0070.00016.98
8.0.50.0060.00317.02
8.0.30.0110.00817.25
8.0.20.0090.01417.40
8.0.10.0030.00517.22
8.0.00.0070.01316.91
7.4.330.0000.00616.71
7.4.320.0000.00816.77
7.4.300.0000.00816.74
7.4.290.0000.00716.83
7.4.280.0000.01016.64
7.4.270.0050.00316.82
7.4.260.0030.00313.55
7.4.250.0030.00616.72
7.4.240.0020.00516.89
7.4.230.0030.00316.80
7.4.220.0150.00316.90
7.4.210.0110.00716.81
7.4.200.0000.00716.88
7.4.190.0030.00316.93
7.4.150.0140.00617.40
7.4.140.0090.01017.86
7.4.130.0130.00516.71
7.4.120.0090.01016.76
7.4.110.0120.00616.75
7.4.100.0120.00616.68
7.4.90.0150.00416.86
7.4.80.0110.00619.39
7.4.70.0030.01516.78
7.4.60.0100.01016.89
7.4.50.0000.00916.55
7.4.40.0070.01022.77
7.4.30.0120.00616.70
7.4.00.0060.01215.18
7.3.330.0000.00513.42
7.3.320.0030.00313.49
7.3.310.0040.00416.60
7.3.300.0000.00816.61
7.3.290.0070.00716.58
7.3.280.0130.00616.55
7.3.270.0090.00817.40
7.3.260.0090.01118.24
7.3.250.0100.00916.59
7.3.240.0080.00916.75
7.3.230.0070.01116.91
7.3.210.0070.01016.71
7.3.200.0150.01019.39
7.3.190.0030.01316.80
7.3.180.0100.01016.92
7.3.170.0070.01116.58
7.3.160.0080.00816.54
7.3.120.0070.01114.98
7.3.110.0080.01114.94
7.3.100.0070.01014.96
7.3.90.0070.00715.06
7.3.80.0020.00815.21
7.3.70.0080.00815.10
7.3.60.0050.01115.00
7.3.50.0080.00614.91
7.3.40.0060.00615.03
7.3.30.0100.00315.06
7.3.20.0020.01416.75
7.3.10.0060.00616.81
7.3.00.0120.00316.60
7.2.330.0030.01417.03
7.2.320.0060.01216.98
7.2.310.0130.01017.03
7.2.300.0110.00616.85
7.2.290.0100.00616.88
7.2.250.0080.01015.31
7.2.240.0100.00715.15
7.2.230.0080.00815.29
7.2.220.0070.00715.20
7.2.210.0070.00715.27
7.2.200.0020.01115.04
7.2.190.0080.00615.47
7.2.180.0030.01115.25
7.2.170.0060.00815.12
7.2.160.0090.00615.27
7.2.150.0040.01116.95
7.2.140.0000.01517.24
7.2.130.0000.01316.98
7.2.120.0060.00917.12
7.2.110.0040.00816.78
7.2.100.0040.00717.11
7.2.90.0000.01316.98
7.2.80.0110.00017.19
7.2.70.0040.01517.20
7.2.60.0080.00717.14
7.2.50.0040.01116.87
7.2.40.0460.01317.89
7.2.30.0470.01017.91
7.2.20.0500.01317.69
7.2.10.0380.01317.77
7.2.00.0300.01217.98
7.1.330.0040.01116.08
7.1.320.0030.00915.93
7.1.310.0060.01116.12
7.1.300.0040.00815.99
7.1.290.0080.00316.04
7.1.280.0020.01015.95
7.1.270.0000.01215.99
7.1.260.0070.00616.00
7.1.250.0060.00615.96
7.1.240.0060.00915.76
7.1.230.0040.00716.09
7.1.220.0000.01616.05
7.1.210.0060.00316.11
7.1.200.0110.00415.88
7.1.190.0040.01415.70
7.1.180.0030.00916.10
7.1.170.0060.00615.70
7.1.160.0460.01416.79
7.1.150.0360.01116.65
7.1.140.0310.01216.72
7.1.130.0370.01316.72
7.1.120.0370.01216.68
7.1.110.0310.01016.40
7.1.100.0320.01216.36
7.1.90.0340.01116.17
7.1.80.0250.01016.18
7.1.70.0210.00616.07
7.1.60.0260.01225.64
7.1.50.0260.01625.01
7.1.40.0320.01527.28
7.1.30.0280.01327.33
7.1.20.0360.01527.32
7.1.10.0210.01215.32
7.1.00.0860.02017.20
7.0.330.0050.00515.75
7.0.320.0030.01015.54
7.0.310.0100.00715.32
7.0.300.0060.00615.50
7.0.290.0370.01016.39
7.0.280.0030.01015.27
7.0.270.0540.01316.39
7.0.260.0280.01316.31
7.0.250.0330.01116.03
7.0.240.0280.00915.86
7.0.230.0340.00816.06
7.0.220.0360.00815.92
7.0.210.0240.01015.21
7.0.200.0150.00915.62
7.0.190.0240.01015.34
7.0.180.0210.01215.09
7.0.170.0150.01314.95
7.0.160.0240.00815.05
7.0.150.0260.01015.06
7.0.140.0170.02516.81
7.0.130.0170.01015.25
7.0.120.0200.00715.16
7.0.110.0210.01115.05
7.0.100.0230.00915.02
7.0.90.0180.01415.12
7.0.80.0180.01115.15
7.0.70.0160.01015.11
7.0.60.0200.02416.33
7.0.50.0160.02215.87
7.0.40.0130.02215.90
7.0.30.0140.02915.95
7.0.20.0140.01615.89
7.0.10.0140.01715.97
7.0.00.0130.02616.05
5.6.400.0100.00314.50
5.6.390.0000.01714.71
5.6.380.0110.00314.46
5.6.370.0070.00714.58
5.6.360.0040.01114.60
5.6.350.0030.01214.77
5.6.340.0090.00614.51
5.6.330.0060.00614.42
5.6.320.0120.00414.81
5.6.310.0090.00014.28
5.6.300.0160.05218.84
5.6.290.0180.05218.72
5.6.280.0130.05619.40
5.6.270.0150.05518.82
5.6.260.0170.05618.88
5.6.250.0140.05018.73
5.6.240.0140.05318.84
5.6.230.0150.04618.85
5.6.220.0140.06118.68
5.6.210.0120.05419.24
5.6.200.0100.04618.59
5.6.190.0120.06419.20
5.6.180.0130.05519.25
5.6.170.0140.05519.15
5.6.160.0130.05719.09
5.6.150.0130.05819.02
5.6.140.0160.05519.12
5.6.130.0140.05619.18
5.6.120.0160.05319.07
5.6.110.0150.04819.16
5.6.100.0150.05519.15
5.6.90.0100.06119.00
5.6.80.0110.04618.54
5.6.70.0140.05218.58
5.6.60.0120.04918.64
5.6.50.0150.04418.63
5.6.40.0110.06018.68
5.6.30.0130.05118.62
5.6.20.0120.05718.49
5.6.10.0110.05618.77
5.6.00.0120.04818.60
5.5.380.0210.07317.52
5.5.370.0190.06217.59
5.5.360.0170.05917.53
5.5.350.0120.04918.47
5.5.340.0140.05418.01
5.5.330.0130.07718.67
5.5.320.0130.07418.73
5.5.310.0110.06318.79
5.5.300.0120.07518.82
5.5.290.0130.07418.70
5.5.280.0100.07018.73
5.5.270.0130.05918.65
5.5.260.0110.08018.73
5.5.250.0150.06618.56
5.5.240.0160.05518.11
5.5.230.0100.06218.14
5.5.220.0120.07418.05
5.5.210.0170.07018.13
5.5.200.0140.06718.07
5.5.190.0140.06518.09
5.5.180.0130.06618.07
5.5.160.0150.05918.04
5.5.150.0120.05618.03
5.5.140.0160.06018.14
5.5.130.0200.05418.12
5.5.120.0130.05218.08
5.5.110.0150.05618.14
5.5.100.0110.05617.90
5.5.90.0120.05118.00
5.5.80.0120.05517.96
5.5.70.0110.05917.93
5.5.60.0150.06417.91
5.5.50.0100.05817.92
5.5.40.0120.05217.94
5.5.30.0090.06117.90
5.5.20.0140.06317.84
5.5.10.0100.05917.99
5.5.00.0130.06117.75
5.4.450.0180.06819.23
5.4.440.0120.07219.24
5.4.430.0180.07119.30
5.4.420.0160.06819.36
5.4.410.0130.06319.18
5.4.400.0150.05519.09
5.4.390.0140.07219.11
5.4.380.0140.06719.11
5.4.370.0150.05218.92
5.4.360.0110.06819.11
5.4.350.0140.05619.05
5.4.340.0160.06119.10
5.4.320.0150.07119.00
5.4.310.0140.06819.05
5.4.300.0120.06618.96
5.4.290.0140.07018.97
5.4.280.0140.05318.91
5.4.270.0110.05518.98
5.4.260.0130.06119.10
5.4.250.0140.06119.05
5.4.240.0140.06318.99
5.4.230.0160.05919.00
5.4.220.0100.05818.94
5.4.210.0100.05819.05
5.4.200.0140.06618.96
5.4.190.0170.05218.85
5.4.180.0100.06118.98
5.4.170.0130.06019.02
5.4.160.0100.05218.94
5.4.150.0110.06119.08
5.4.140.0160.05116.52
5.4.130.0130.05216.59
5.4.120.0140.05616.51
5.4.110.0110.05216.63
5.4.100.0090.04716.57
5.4.90.0140.05116.51
5.4.80.0130.05416.56
5.4.70.0130.04416.58
5.4.60.0120.05316.63
5.4.50.0140.06116.46
5.4.40.0090.04616.49
5.4.30.0110.05016.48
5.4.20.0090.05016.56
5.4.10.0120.05216.49
5.4.00.0110.05115.99
5.3.290.0150.06614.75
5.3.280.0110.06014.53
5.3.270.0090.06914.83
5.3.260.0110.05614.62
5.3.250.0120.05614.77
5.3.240.0130.04714.70
5.3.230.0120.06014.68
5.3.220.0120.05414.74
5.3.210.0120.05414.62
5.3.200.0140.05414.73
5.3.190.0130.04914.63
5.3.180.0080.04814.78
5.3.170.0120.04614.82
5.3.160.0140.05114.60
5.3.150.0130.05314.70
5.3.140.0130.05014.64
5.3.130.0150.04414.70
5.3.120.0130.05014.71
5.3.110.0110.05114.64
5.3.100.0130.05014.18
5.3.90.0150.05414.01
5.3.80.0090.05714.09
5.3.70.0110.05414.18
5.3.60.0150.05414.11
5.3.50.0150.05814.10
5.3.40.0100.05613.95
5.3.30.0120.05913.95
5.3.20.0120.06013.81
5.3.10.0130.06413.81
5.3.00.0120.05013.66
5.2.170.0100.05511.61
5.2.160.0110.05011.54
5.2.150.0090.04711.54
5.2.140.0110.05411.68
5.2.130.0090.05811.53
5.2.120.0110.05011.63
5.2.110.0100.05211.63
5.2.100.0100.05911.59
5.2.90.0140.04511.50
5.2.80.0100.04411.61
5.2.70.0100.05511.59
5.2.60.0090.05711.51
5.2.50.0100.05211.46
5.2.40.0100.05311.58
5.2.30.0120.05511.58
5.2.20.0110.05311.45
5.2.10.0150.04911.50
5.2.00.0080.04111.32
5.1.60.0060.03210.81
5.1.50.0070.04210.88
5.1.40.0100.03110.86
5.1.30.0120.05011.13
5.1.20.0100.04311.10
5.1.10.0080.04610.98
5.1.00.0100.04810.89
5.0.50.0070.03910.26
5.0.40.0090.03610.26
5.0.30.0080.04110.26
5.0.20.0090.03710.26
5.0.10.0050.03110.26
5.0.00.0030.05310.26
4.4.90.0060.02910.26
4.4.80.0070.02710.26
4.4.70.0040.02610.26
4.4.60.0060.02410.26
4.4.50.0040.02210.26
4.4.40.0050.04710.26
4.4.30.0050.02310.26
4.4.20.0040.02910.26
4.4.10.0050.03010.26
4.4.00.0050.03310.26
4.3.110.0070.02810.26
4.3.100.0050.02410.26
4.3.90.0070.03010.26
4.3.80.0070.04010.26
4.3.70.0040.02610.26
4.3.60.0050.02610.26
4.3.50.0070.02610.26
4.3.40.0050.04210.26
4.3.30.0040.02810.26
4.3.20.0040.02710.26
4.3.10.0050.02710.26
4.3.00.0040.02310.26

preferences:
50.89 ms | 400 KiB | 5 Q