3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Callcenter_Flagcustomer_Model_Observer { /** * Possibly flag an address. * * Matching an existing flagged address is an inexact science. We want * to catch most trivial circumventions but we don't want to incorrectly * flag good orders - the latter we care about MUCH more than the former. * * At the end of the day, I decided to do a basic normalized levenshtein * comparison, and if there are more than 3 total mistakes between the * flagged address and the incoming address, we flag the order. Region * and Country are exact matches due to not being input by hand. * * @param array[string] $a1 * @param array[string] $a2 * @return boolean */ public static function shouldFlag($a1, $a2) { if ($a1['region'] !== $a2['region']) { return false; } elseif ($a1['country'] !== $a2['country']) { return false; } $score = 0; $score += self::sCompare($a1['street'], $a2['street']); $score += self::compare($a1['city'], $a2['city']); $score += self::pCompare($a1['postcode'], $a2['postcode'], $a1['country'], $a2['country']); if ($score > 3) { return false; } return true; } /** * Compare two normalized strings via levenshtein distance. * * @param string $s1 String to compare. * @param string $s2 String to compare against. * @return float Score. */ private static function compare($s1, $s2) { $sn1 = self::normalize($s1); $sn2 = self::normalize($s2); $score = levenshtein($sn1, $sn2); return $score; } /** * Compare two normalized postcodes via levenshtein distance. * * @param string $s1 String to compare. * @param string $s2 String to compare against. * @param string $c1 Country of $s1. * @param string $c2 Country of $s2. * @return float Score. */ private static function pCompare($s1, $s2, $c1, $c2) { $sn1 = self::normalize($s1); $sn2 = self::normalize($s2); if (strtoupper($c1) === 'US' && strlen($sn1) === 9) { $sn1 = substr($sn1, 0, 5); } if (strtoupper($c2) === 'US' && strlen($sn2) === 9) { $sn2 = substr($sn2, 0, 5); } $score = levenshtein($sn1, $sn2); return $score; } /** * Compare two normalized street names via levenshtein distance. * * @param string $s1 String to compare. * @param string $s2 String to compare against. * @return float Score. */ private static function sCompare($s1, $s2) { $sn1 = self::sNormalize($s1); $sn2 = self::sNormalize($s2); $score = levenshtein($sn1, $sn2); return $score; } /** * Normalize a string for comparison. * * @param string $s String to normalize. * @return string */ private static function normalize($s) { // Normalize to lowercase alphanumeric. $s = strtolower(preg_replace('/[^a-zA-Z0-9]+/', '', $s)); return trim($s); } /** * Normalize an address for comparison. Has a few more steps that * are specific to addresses. * * @param string $s String to normalize. * @return string */ private static function sNormalize($s) { static $mappings = [ 'apt' => 'apartment', 'ave' => 'avenue', 'blvd' => 'boulevard', 'ct' => 'court', 'dr' => 'drive', 'e' => 'east', 'n' => 'north', 'ne' => 'northeast', 'nw' => 'northwest', 'pkwy' => 'parkway', 'pl' => 'place', 'rd' => 'road', 's' => 'south', 'se' => 'southeast', 'st' => 'street', 'sw' => 'southwest', 'w' => 'west', ]; $from = []; $to = []; foreach ($mappings as $key => $value) { $from[] = ' '.$key.' '; $to[] = ' '.$value. ' '; } // Normalize to lowercase alphanumeric with spaces. $s = strtolower(preg_replace('/[^a-zA-Z0-9 ]+/', '', $s)); // Ensure surrounded with spaces. $s = ' '.$s.' '; // Get rid of multiple spaces - turn into single spaces. $s = preg_replace('/\s{2,}/', ' ', $s); // Get rid of ordinal indicators. $s = preg_replace('/(\d+)(?:st|nd|rd|th)/', '\1', $s); // Replace street abbreviations. $s = str_replace($from, $to, $s); return trim($s); } } $result = Callcenter_Flagcustomer_Model_Observer::shouldFlag([ 'street' => '65 JANIS RD', 'city' => 'WESTFIELD', 'region' => 'MA', 'postcode' => '01085-4016', 'country' => 'US', ], [ 'street' => '65 JANIS RD', 'city' => 'WESTFIELD', 'region' => 'MA', 'postcode' => '01085-4016', 'country' => 'US', ]); var_dump($result);

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.0110.00418.43
8.3.50.0120.00618.23
8.3.40.0000.01519.10
8.3.30.0110.00418.92
8.3.20.0060.00320.20
8.3.10.0080.00023.70
8.3.00.0030.00519.69
8.2.180.0160.00616.75
8.2.170.0060.01222.96
8.2.160.0100.00519.17
8.2.150.0070.00724.18
8.2.140.0080.00024.66
8.2.130.0080.00019.21
8.2.120.0060.00926.35
8.2.110.0090.00020.46
8.2.100.0040.00818.03
8.2.90.0050.00319.26
8.2.80.0050.00317.97
8.2.70.0060.00617.88
8.2.60.0030.00618.04
8.2.50.0000.00918.10
8.2.40.0030.00620.30
8.2.30.0100.00019.56
8.2.20.0040.00418.24
8.2.10.0050.00318.35
8.2.00.0000.00718.27
8.1.270.0040.00423.91
8.1.260.0000.00826.35
8.1.250.0050.00328.09
8.1.240.0090.00021.16
8.1.230.0080.00319.23
8.1.220.0090.00017.91
8.1.210.0040.00418.77
8.1.200.0030.00617.60
8.1.190.0080.00017.48
8.1.180.0030.00518.10
8.1.170.0050.00518.96
8.1.160.0040.00419.07
8.1.150.0030.00620.75
8.1.140.0040.00419.64
8.1.130.0000.00718.90
8.1.120.0040.00417.58
8.1.110.0000.00917.50
8.1.100.0000.00817.66
8.1.90.0000.00717.52
8.1.80.0070.00017.63
8.1.70.0050.00217.63
8.1.60.0060.00317.60
8.1.50.0030.00617.65
8.1.40.0060.00317.68
8.1.30.0040.00417.89
8.1.20.0000.00817.74
8.1.10.0080.00017.75
8.1.00.0040.00417.56
8.0.300.0080.00018.77
8.0.290.0040.00416.88
8.0.280.0030.00318.42
8.0.270.0030.00317.31
8.0.260.0000.00717.01
8.0.250.0050.00317.15
8.0.240.0080.00017.02
8.0.230.0030.00317.10
8.0.220.0040.00417.08
8.0.210.0030.00316.98
8.0.200.0040.00417.19
8.0.190.0030.00617.19
8.0.180.0070.00017.03
8.0.170.0040.00417.07
8.0.160.0090.00016.96
8.0.150.0040.00417.10
8.0.140.0080.00017.04
8.0.130.0030.00313.44
8.0.120.0000.00817.10
8.0.110.0040.00316.96
8.0.100.0080.00017.07
8.0.90.0000.00716.96
8.0.80.0130.01017.09
8.0.70.0040.00417.09
8.0.60.0050.00317.14
8.0.50.0040.00416.90
8.0.30.0080.00817.24
8.0.20.0140.00817.44
8.0.10.0020.00517.13
8.0.00.0130.01016.79
7.4.330.0000.00515.55
7.4.320.0060.00016.74
7.4.300.0030.00316.65
7.4.290.0070.00016.84
7.4.280.0000.00716.89
7.4.270.0030.00316.74
7.4.260.0030.00316.73
7.4.250.0050.00316.83
7.4.240.0040.00416.75
7.4.230.0070.00016.65
7.4.220.0120.00616.75
7.4.210.0070.00716.86
7.4.200.0000.00716.78
7.4.160.0130.00316.70
7.4.150.0090.00917.40
7.4.140.0130.00517.86
7.4.130.0040.01316.72
7.4.120.0110.01116.92
7.4.110.0090.00916.62
7.4.100.0150.00316.70
7.4.90.0190.00316.71
7.4.80.0040.01419.39
7.4.70.0130.00416.66
7.4.60.0070.01016.64
7.4.50.0120.00316.67
7.4.40.0060.01216.66
7.4.30.0060.01016.75
7.4.00.0070.00615.23
7.3.330.0030.00313.40
7.3.320.0000.00613.46
7.3.310.0000.00716.36
7.3.300.0040.00416.49
7.3.290.0090.00616.56
7.3.280.0090.01016.53
7.3.270.0140.00717.40
7.3.260.0090.00816.54
7.3.250.0110.00916.66
7.3.240.0090.00916.85
7.3.230.0090.00916.63
7.3.210.0120.01016.54
7.3.200.0080.00816.56
7.3.190.0100.01316.75
7.3.180.0090.01416.92
7.3.170.0120.00616.54
7.3.160.0130.00316.79
7.3.120.0030.01615.21
7.3.110.0060.00614.89
7.3.100.0030.01315.23
7.3.90.0080.00415.26
7.3.80.0090.00614.70
7.3.70.0070.00714.93
7.3.60.0070.01115.13
7.3.50.0070.00715.18
7.3.40.0000.01315.13
7.3.30.0000.00915.13
7.3.20.0070.00716.60
7.3.10.0060.00916.63
7.3.00.0110.00716.86
7.2.330.0090.00917.03
7.2.320.0110.00617.12
7.2.310.0110.00716.72
7.2.300.0070.01016.95
7.2.290.0030.01317.06
7.2.250.0070.01415.29
7.2.240.0000.01615.12
7.2.230.0060.00915.05
7.2.220.0040.01115.44
7.2.210.0030.00715.36
7.2.200.0040.00815.42
7.2.190.0090.00915.33
7.2.180.0120.00315.28
7.2.170.0090.00615.37
7.2.110.0100.01416.89
7.2.90.3470.00314.87
7.2.80.2560.00315.19
7.2.70.0620.01015.36
7.2.60.0150.00815.45
7.2.50.0900.00615.38
7.2.40.0170.01015.18
7.2.30.0190.00515.18
7.2.20.2890.01315.35
7.2.10.2050.01315.38
7.2.00.0120.00615.42
7.1.330.0060.00915.64
7.1.320.0030.00716.16
7.1.310.0040.01116.02
7.1.300.0060.00315.73
7.1.290.0080.00815.98
7.1.280.0090.00016.01
7.1.270.0070.00715.94
7.1.260.0050.00515.84
7.1.210.0610.01214.30
7.1.200.2360.00314.20
7.1.190.0180.00013.98
7.1.180.0180.00714.33
7.1.170.0170.00014.30
7.1.160.0220.00614.19
7.1.150.0120.00814.09
7.1.140.2620.00714.29
7.1.130.3110.01014.20
7.1.120.0090.00914.09
7.1.110.0100.01014.38
7.1.100.0470.00314.26
7.1.90.0550.00314.27
7.1.80.0310.00814.24
7.1.70.0180.00014.13
7.1.60.1110.01232.44
7.1.50.0330.01532.32
7.1.40.0210.02432.35
7.1.30.0270.01032.34
7.1.20.1420.00032.23
7.1.10.0860.00314.07
7.1.00.1160.00314.04
7.0.310.0610.01013.79
7.0.300.0090.01013.80
7.0.290.0130.00813.77
7.0.280.0150.00313.87
7.0.270.0250.01113.50
7.0.260.0090.01213.67
7.0.250.0150.00413.89
7.0.240.0190.01014.01
7.0.230.1970.00413.97
7.0.220.2150.00713.93
7.0.210.1350.00913.88
7.0.200.2040.01013.82
7.0.190.1790.00713.77
7.0.180.1350.01213.97
7.0.170.0230.00314.05
7.0.160.1610.00713.76
7.0.150.0240.00013.87
7.0.140.1090.01313.91
7.0.130.0700.00613.79
7.0.120.0970.00714.04
7.0.110.0850.00413.98
7.0.100.0280.00613.69
7.0.90.2220.01013.77
7.0.80.0190.00613.77
7.0.70.0140.00813.73
7.0.60.0520.00413.80
7.0.50.0100.01014.12
7.0.40.0230.00813.84
7.0.30.0340.00614.11
7.0.20.0140.00513.98
7.0.10.1040.00413.83
7.0.00.0130.00613.79

preferences:
64.4 ms | 400 KiB | 5 Q