3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace App\SemanticAnalysis; /** * Class NoMatchesFoundException * @package App\SemanticAnalysis */ class NoMatchesFoundException extends \Exception {} /** * Class SemanticAnalysis * @package App\SemanticAnalysis */ class SemanticAnalysis { /** * @var */ private $criteria; /** * @var string */ private $text; /** * @var array */ private $matches; /** * @param $criteria * @param $text */ public function __construct($criteria, $text) { $this->criteria = $criteria; $this->text = strtolower($text); $this->matches = []; } /** * @throws NoMatchesFoundException */ public function analyse() { if (preg_match_all($this->buildRegex(), $this->text, $matches) == false) { throw new NoMatchesFoundException(); } $this->matches = $matches['token']; } /** * @return int */ public function getScore() { return $this->scoreMatches(); } /** * @param string $regex * @return string */ private function buildRegex($regex = "") { foreach ($this->criteria as $value) { $regex .= $value[0] . "|"; } return "/(?<token>".rtrim($regex, "|").")/iu"; } /** * @param int $score * @return int */ private function scoreMatches($score = 0) { foreach ($this->criteria as $row) { if (in_array($row[0], $this->matches)) { $score+=$row[1]; } } return $score; } } // TestCase $criteria = [ ['beautiful place', 1], ['amazing location', 1], ['superb service', 1], ['international hotel', 1], ['perfect location', 1], ['terrible', -1] ]; $text = "I have stayed here 4 or 5 times while visiting LA. Despite travelling all over the world and staying in some of the best international hotels ( for work), Hotel Caliornia is one of my absolute favourites. Perfect location, right on the beach. I love the way you can just open your door and be outside, no elevators, corridors big glass windows. The ambience is so nice, retro perfect. As for the staff, I have had consistently superb service, with much more personal service and attention to detail than is usual in bigger hotels. Aaron and Katy were just two who have been exemplary this time but really everyone is terrific. Can't recommend it highly enough."; $semanticAnalysis = new \App\SemanticAnalysis\SemanticAnalysis($criteria, $text); try { $semanticAnalysis->analyse(); var_dump($semanticAnalysis->getScore()); var_dump($semanticAnalysis->getMatches()); } catch (NoMatchesFoundException $e) { print $e->getMessage(); }

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.0180.00018.81
8.3.50.0100.01122.17
8.3.40.0090.00619.13
8.3.30.0110.00419.08
8.3.20.0080.00020.16
8.3.10.0030.00620.78
8.3.00.0070.00021.76
8.2.180.0040.01118.66
8.2.170.0160.00622.96
8.2.160.0050.00922.44
8.2.150.0000.00824.18
8.2.140.0030.00624.66
8.2.130.0000.00821.06
8.2.120.0060.00326.35
8.2.110.0000.00920.39
8.2.100.0040.00818.16
8.2.90.0080.00019.36
8.2.80.0050.00317.97
8.2.70.0030.00517.75
8.2.60.0050.00317.93
8.2.50.0030.00618.10
8.2.40.0000.00820.38
8.2.30.0040.00419.54
8.2.20.0040.00418.04
8.2.10.0000.00818.19
8.2.00.0040.00418.29
8.1.280.0110.00425.92
8.1.270.0100.01022.14
8.1.260.0030.00628.09
8.1.250.0030.00628.09
8.1.240.0100.00023.79
8.1.230.0080.00323.86
8.1.220.0080.00017.91
8.1.210.0080.00018.77
8.1.200.0060.00317.50
8.1.190.0080.00017.73
8.1.180.0080.00018.10
8.1.170.0080.00018.76
8.1.160.0020.00520.99
8.1.150.0000.00818.96
8.1.140.0030.00519.70
8.1.130.0030.00317.78
8.1.120.0040.00417.72
8.1.110.0090.00017.62
8.1.100.0060.00317.55
8.1.90.0000.00817.68
8.1.80.0050.00317.54
8.1.70.0030.00317.64
8.1.60.0080.00017.82
8.1.50.0000.00917.72
8.1.40.0030.00517.66
8.1.30.0040.00417.67
8.1.20.0040.00417.74
8.1.10.0060.00317.75
8.1.00.0000.00817.66
8.0.300.0050.00218.77
8.0.290.0090.00017.00
8.0.280.0040.00418.55
8.0.270.0040.00417.19
8.0.260.0030.00317.33
8.0.250.0030.00317.17
8.0.240.0080.00017.27
8.0.230.0030.00317.29
8.0.220.0040.00417.21
8.0.210.0030.00317.25
8.0.200.0000.00717.16
8.0.190.0040.00417.15
8.0.180.0070.00017.15
8.0.170.0030.00517.23
8.0.160.0050.00217.17
8.0.150.0030.00617.13
8.0.140.0000.00717.22
8.0.130.0000.00613.59
8.0.120.0040.00417.14
8.0.110.0040.00417.30
8.0.100.0000.00717.17
8.0.90.0050.00317.10
8.0.80.0100.00717.32
8.0.70.0000.00817.15
8.0.60.0070.00017.30
8.0.50.0040.00417.22
8.0.30.0130.00617.37
8.0.20.0080.01117.40
8.0.10.0030.00517.23
8.0.00.0090.00817.05
7.4.330.0000.00516.86
7.4.320.0000.00616.81
7.4.300.0030.00316.82
7.4.290.0070.00016.91
7.4.280.0060.00316.90
7.4.270.0040.00416.93
7.4.260.0000.00716.90
7.4.250.0050.00216.79
7.4.240.0030.00516.83
7.4.230.0030.00416.94
7.4.220.0030.01417.02
7.4.210.0060.01317.03
7.4.200.0000.00916.75
7.4.160.0030.01916.80
7.4.150.0060.01317.40
7.4.140.0200.01817.86
7.4.130.0120.00516.75
7.4.120.0030.01616.74
7.4.110.0060.01316.78
7.4.100.0060.01616.73
7.4.90.0060.01516.91
7.4.80.0100.01319.39
7.4.70.0100.00616.66
7.4.60.0120.01216.79
7.4.50.0000.01516.79
7.4.40.0110.00516.65
7.4.30.0030.01316.78
7.4.00.0070.00715.17
7.3.330.0000.00513.63
7.3.320.0000.00513.66
7.3.310.0000.00716.70
7.3.300.0000.00816.61
7.3.290.0070.01016.69
7.3.280.0060.00916.66
7.3.270.0110.00617.40
7.3.260.0130.00516.67
7.3.250.0110.00916.67
7.3.240.0040.01416.69
7.3.230.0120.00616.48
7.3.210.0070.01016.61
7.3.200.0100.00716.75
7.3.190.0060.01116.86
7.3.180.0090.01216.80
7.3.170.0060.00916.73
7.3.160.0120.00916.67
7.2.330.0150.00316.98
7.2.320.0070.01616.68
7.2.310.0070.01016.95
7.2.300.0150.00317.04
7.2.290.0030.01216.88
7.2.60.0140.00317.02
7.2.00.0240.00719.38
7.1.200.0000.01315.77
7.1.100.0040.01118.37
7.1.70.0000.00717.26
7.1.60.0140.01119.40
7.1.50.0090.00317.38
7.1.00.0030.07722.50
7.0.200.0110.00415.13
7.0.60.0030.05720.04
7.0.50.0070.05317.97
7.0.40.0100.07720.26
7.0.30.0100.05320.12
7.0.20.0370.05720.12
7.0.10.0030.05720.24
7.0.00.0030.04320.35
5.6.280.0070.03021.05
5.6.210.0130.05320.58
5.6.200.0170.02718.16
5.6.190.0030.04720.48
5.6.180.0300.07020.46
5.6.170.0300.07320.47
5.6.160.0030.09020.54
5.6.150.0170.07018.27
5.6.140.0070.07318.15
5.6.130.0070.08318.18
5.6.120.0000.04721.14
5.6.110.0100.08320.90
5.6.100.0130.08021.06
5.6.90.0100.07721.01
5.6.80.0100.07020.30
5.5.350.0030.08320.43
5.5.340.0100.07718.08
5.5.330.0070.08320.18
5.5.320.0300.07320.31
5.5.310.0300.07720.20
5.5.300.0070.05017.94
5.5.290.0030.06018.04
5.5.280.0100.08320.92
5.5.270.0130.05720.92
5.5.260.0070.05320.95
5.5.250.0000.05020.64
5.5.240.0200.07320.19

preferences:
41.26 ms | 401 KiB | 5 Q