3v4l.org

run code in 300+ PHP versions simultaneously
<?php class StrategyContext { private $strategy = NULL; //bookList is not instantiated at construct time public function __construct($strategy_ind_id) { switch ($strategy_ind_id) { case "C": $this->strategy = new StrategyCaps(); break; case "E": $this->strategy = new StrategyExclaim(); break; case "S": $this->strategy = new StrategyStars(); break; } } public function showBookTitle($book) { return $this->strategy->showTitle($book); } } interface StrategyInterface { public function showTitle($book_in); } class StrategyCaps implements StrategyInterface { public function showTitle($book_in) { $title = $book_in->getTitle(); $this->titleCount++; return strtoupper ($title); } } class StrategyExclaim implements StrategyInterface { public function showTitle($book_in) { $title = $book_in->getTitle(); $this->titleCount++; return Str_replace(' ','!',$title); } } class StrategyStars implements StrategyInterface { public function showTitle($book_in) { $title = $book_in->getTitle(); $this->titleCount++; return Str_replace(' ','*',$title); } } class Book { private $author; private $title; function __construct($title_in, $author_in) { $this->author = $author_in; $this->title = $title_in; } function getAuthor() { return $this->author; } function getTitle() { return $this->title; } function getAuthorAndTitle() { return $this->getTitle() . ' by ' . $this->getAuthor(); } } writeln('BEGIN TESTING STRATEGY PATTERN'); writeln(''); $book = new Book('PHP for Cats','Larry Truett'); $strategyContextC = new StrategyContext('C'); $strategyContextE = new StrategyContext('E'); $strategyContextS = new StrategyContext('S'); writeln('test 1 - show name context C'); writeln($strategyContextC->showBookTitle($book)); writeln(''); writeln('test 2 - show name context E'); writeln($strategyContextE->showBookTitle($book)); writeln(''); writeln('test 3 - show name context S'); writeln($strategyContextS->showBookTitle($book)); writeln(''); writeln('END TESTING STRATEGY PATTERN'); function writeln($line_in) { echo $line_in."<br/>"; }

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.0140.00718.68
8.3.50.0190.00321.14
8.3.40.0120.00318.71
8.3.30.0070.00720.38
8.3.20.0000.00820.58
8.3.10.0000.00720.92
8.3.00.0040.00422.32
8.2.180.0070.01417.00
8.2.170.0120.00322.96
8.2.160.0110.00420.39
8.2.150.0040.00424.18
8.2.140.0000.00924.66
8.2.130.0040.00426.16
8.2.120.0040.00421.05
8.2.110.0090.00022.11
8.2.100.0000.01217.91
8.2.90.0000.00817.88
8.2.80.0080.00018.61
8.2.70.0040.00418.16
8.2.60.0000.00818.28
8.2.50.0000.00918.10
8.2.40.0040.00419.43
8.2.30.0060.00319.48
8.2.20.0000.00717.80
8.2.10.0040.00417.88
8.2.00.0040.00417.91
8.1.280.0100.00725.92
8.1.270.0080.00023.99
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0030.00624.01
8.1.230.0110.00417.70
8.1.220.0080.00017.78
8.1.210.0040.00418.77
8.1.200.0100.00017.35
8.1.190.0040.00419.05
8.1.180.0060.00318.10
8.1.170.0040.00418.55
8.1.160.0000.00718.98
8.1.150.0080.00018.77
8.1.140.0040.00417.46
8.1.130.0030.00317.97
8.1.120.0030.00517.42
8.1.110.0040.00417.41
8.1.100.0000.00817.41
8.1.90.0040.00417.55
8.1.80.0050.00217.45
8.1.70.0000.00717.47
8.1.60.0000.00917.60
8.1.50.0040.00417.63
8.1.40.0050.00317.46
8.1.30.0040.00417.71
8.1.20.0030.00517.73
8.1.10.0000.00817.59
8.1.00.0050.00517.48
8.0.300.0040.00418.77
8.0.290.0080.00016.88
8.0.280.0040.00418.54
8.0.270.0030.00517.34
8.0.260.0030.00316.94
8.0.250.0030.00617.09
8.0.240.0080.00016.99
8.0.230.0040.00417.09
8.0.220.0030.00316.91
8.0.210.0070.00016.96
8.0.200.0030.00317.06
8.0.190.0080.00016.98
8.0.180.0000.00717.01
8.0.170.0040.00417.05
8.0.160.0040.00416.98
8.0.150.0000.00716.96
8.0.140.0030.00616.92
8.0.130.0030.00313.50
8.0.120.0040.00417.00
8.0.110.0060.00317.03
8.0.100.0000.00716.89
8.0.90.0000.00717.00
8.0.80.0060.00916.89
8.0.70.0080.00016.88
8.0.60.0050.00317.05
8.0.50.0050.00316.98
8.0.30.0170.00217.04
8.0.20.0070.01317.40
8.0.10.0000.00716.93
8.0.00.0050.01316.95
7.4.330.0050.00016.76
7.4.320.0000.00716.63
7.4.300.0030.00316.70
7.4.290.0070.00016.50
7.4.280.0000.00716.55
7.4.270.0000.00716.67
7.4.260.0000.00513.33
7.4.250.0040.00416.59
7.4.240.0050.00316.65
7.4.230.0030.00316.47
7.4.220.0070.01116.59
7.4.210.0060.00916.56
7.4.200.0030.00316.49
7.4.190.0050.00216.81
7.4.160.0110.00516.61
7.4.150.0100.01217.40
7.4.140.0080.00917.86
7.4.130.0130.00716.56
7.4.120.0120.00416.55
7.4.110.0070.01716.63
7.4.100.0160.01116.61
7.4.90.0110.01516.64
7.4.80.0130.01319.39
7.4.70.0030.01316.63
7.4.60.0100.00616.56
7.4.50.0030.00616.62
7.4.40.0060.00922.77
7.4.30.0130.00316.83
7.4.00.0120.00315.02
7.3.330.0020.00213.24
7.3.320.0000.00513.26
7.3.310.0000.00716.23
7.3.300.0040.00416.38
7.3.290.0070.00716.46
7.3.280.0080.00916.37
7.3.270.0140.00417.40
7.3.260.0110.00918.24
7.3.250.0130.00616.58
7.3.240.0130.00716.57
7.3.230.0030.01416.46
7.3.210.0070.01016.37
7.3.200.0090.01519.39
7.3.190.0130.00316.42
7.3.180.0130.00416.55
7.3.170.0110.01116.52
7.3.160.0180.00316.38
7.3.120.0090.00714.89
7.3.110.0100.00714.76
7.3.100.0170.00314.98
7.3.90.0060.00614.89
7.3.80.0040.00915.00
7.3.70.0030.01314.77
7.3.60.0060.01014.68
7.3.50.0030.00714.66
7.3.40.0030.00914.69
7.3.30.0030.01314.73
7.3.20.0110.00416.73
7.3.10.0070.00616.69
7.3.00.0060.00816.75
7.2.330.0110.00816.86
7.2.320.0040.01816.85
7.2.310.0070.01716.88
7.2.300.0070.01016.51
7.2.290.0090.00916.89
7.2.250.0030.01314.67
7.2.240.0130.00315.32
7.2.230.0070.00715.23
7.2.220.0110.00315.34
7.2.210.0170.00015.27
7.2.200.0000.01415.20
7.2.190.0110.00615.02
7.2.180.0000.01314.91
7.2.170.0080.01215.15
7.2.160.0000.01415.00
7.2.150.0110.00316.92
7.2.140.0030.00616.79
7.2.130.0040.01217.07
7.2.120.0040.01216.85
7.2.110.0080.00616.88
7.2.100.0040.01017.00
7.2.90.0090.00317.03
7.2.80.0070.00317.02
7.2.70.0090.00416.87
7.2.60.0030.01116.71
7.2.50.0070.00716.94
7.2.40.0080.00616.99
7.2.30.0090.00616.91
7.2.20.0060.00816.87
7.2.10.0050.01216.86
7.2.00.0100.00517.62
7.1.330.0120.00615.71
7.1.320.0090.00915.73
7.1.310.0160.00315.42
7.1.300.0030.01015.74
7.1.290.0000.01415.73
7.1.280.0140.00415.75
7.1.270.0060.00615.59
7.1.260.0060.00915.60
7.1.250.0060.00815.85
7.1.240.0030.00615.66
7.1.230.0040.01115.84
7.1.220.0060.00915.87
7.1.210.0080.00415.78
7.1.200.0080.00615.73
7.1.190.0050.00515.74
7.1.180.0000.01315.71
7.1.170.0070.01015.76
7.1.160.0040.00415.86
7.1.150.0000.01415.46
7.1.140.0000.01515.92
7.1.130.0040.01115.84
7.1.120.0070.01015.89
7.1.110.0100.00716.00
7.1.100.0100.00216.94
7.1.90.0140.00015.77
7.1.80.0060.00615.62
7.1.70.0020.00916.44
7.1.60.0070.00917.44
7.1.50.0070.00816.26
7.1.40.0040.01115.82
7.1.30.0080.00315.45
7.1.20.0060.00615.90
7.1.10.0120.00615.90
7.1.00.0110.03118.96
7.0.330.0100.00715.43
7.0.320.0030.01015.35
7.0.310.0030.01015.50
7.0.300.0030.01015.11
7.0.290.0070.00715.28
7.0.280.0070.00715.23
7.0.270.0040.00815.29
7.0.260.0130.00315.40
7.0.250.0030.01015.34
7.0.240.0110.00315.32
7.0.230.0090.00615.56
7.0.220.0080.00415.44
7.0.210.0090.00615.35
7.0.200.0070.00315.99
7.0.190.0000.01615.25
7.0.180.0090.00615.44
7.0.170.0030.01015.44
7.0.160.0000.01115.22
7.0.150.0070.00715.38
7.0.140.0030.04018.63
7.0.130.0120.00315.25
7.0.120.0040.01215.16
7.0.110.0070.00715.43
7.0.100.0250.05217.58
7.0.90.0120.03917.76
7.0.80.0150.03517.83
7.0.70.0030.04617.74
7.0.60.0120.04417.75
7.0.50.0100.04117.87
7.0.40.0080.04616.68
7.0.30.0050.04016.75
7.0.20.0140.03516.67
7.0.10.0120.02516.81
7.0.00.0080.02716.77
5.6.400.0120.00413.84
5.6.390.0100.00214.20
5.6.380.0060.00314.02
5.6.370.0070.00714.63
5.6.360.0040.00714.25
5.6.350.0090.00314.47
5.6.340.0070.01114.48
5.6.330.0000.01314.29
5.6.320.0070.00714.30
5.6.310.0050.00914.38
5.6.300.0090.00314.31
5.6.290.0030.01014.37
5.6.280.0030.04217.82
5.6.270.0130.00014.00
5.6.260.0080.01114.23
5.6.250.0080.04717.51
5.6.240.0080.02617.55
5.6.230.0070.04417.53
5.6.220.0100.04217.42
5.6.210.0090.02517.34
5.6.200.0050.04617.65
5.6.190.0100.04417.80
5.6.180.0020.03017.82
5.6.170.0000.04417.92
5.6.160.0080.04317.79
5.6.150.0050.02717.65
5.6.140.0130.03317.71
5.6.130.0050.04317.76
5.6.120.0060.04417.73
5.6.110.0050.03317.70
5.6.100.0100.04017.81
5.6.90.0050.03017.57
5.6.80.0080.04017.40
5.6.70.0030.03817.46
5.6.60.0110.03817.35
5.6.50.0070.04517.49
5.6.40.0100.02617.20
5.6.30.0060.02317.36
5.6.20.0070.04117.33
5.6.10.0080.02317.24
5.6.00.0080.04117.24
5.5.380.0050.03117.52
5.5.370.0080.04317.41
5.5.360.0060.03617.31
5.5.350.0130.04017.54
5.5.340.0070.03717.68
5.5.330.0030.02817.60
5.5.320.0030.02517.43
5.5.310.0100.02317.63
5.5.300.0120.03517.69
5.5.290.0060.04417.60
5.5.280.0130.02517.51
5.5.270.0050.03817.64
5.5.260.0100.04217.64
5.5.250.0080.04417.57
5.5.240.0080.04017.19
5.5.230.0060.04617.21
5.5.220.0020.02717.39
5.5.210.0080.03817.19
5.5.200.0080.03817.14
5.5.190.0050.03217.14
5.5.180.0100.03817.22
5.5.170.0060.01014.18
5.5.160.0080.03917.16
5.5.150.0050.03017.05
5.5.140.0090.03917.14
5.5.130.0060.03117.28
5.5.120.0100.02117.31
5.5.110.0050.03817.17
5.5.100.0050.02417.23
5.5.90.0070.03717.33
5.5.80.0040.03917.09
5.5.70.0060.03217.05
5.5.60.0050.04017.24
5.5.50.0070.02517.26
5.5.40.0100.04017.28
5.5.30.0080.04017.05
5.5.20.0090.04417.15
5.5.10.0000.04117.08
5.5.00.0030.05217.05
5.4.450.0030.04315.75
5.4.440.0050.03015.76
5.4.430.0070.04015.77
5.4.420.0050.03815.75
5.4.410.0030.02815.69
5.4.400.0070.03315.45
5.4.390.0100.03515.52
5.4.380.0090.03315.53
5.4.370.0030.04615.58
5.4.360.0100.02815.45
5.4.350.0000.04315.45
5.4.340.0100.02015.43
5.4.330.0060.00312.00
5.4.320.0050.02515.46
5.4.310.0060.04315.61
5.4.300.0070.02315.52
5.4.290.0030.03915.59
5.4.280.0090.03215.62
5.4.270.0090.02615.59
5.4.260.0070.03315.52
5.4.250.0050.03815.48
5.4.240.0090.02215.56
5.4.230.0090.04215.45
5.4.220.0070.04015.54
5.4.210.0050.02515.51
5.4.200.0110.02615.44
5.4.190.0110.03715.43
5.4.180.0100.02515.58
5.4.170.0100.02015.55
5.4.160.0050.04115.43
5.4.150.0060.03815.57
5.4.140.0040.02114.25
5.4.130.0090.03714.23
5.4.120.0030.03514.23
5.4.110.0070.04214.24
5.4.100.0080.03114.27
5.4.90.0050.04114.26
5.4.80.0050.03914.20
5.4.70.0030.03214.18
5.4.60.0070.03914.18
5.4.50.0060.03814.14
5.4.40.0060.02314.26
5.4.30.0080.02314.17
5.4.20.0030.02714.20
5.4.10.0080.04014.24
5.4.00.0030.04013.89
5.3.290.0090.02513.36
5.3.280.0120.03613.39
5.3.270.0070.04413.29
5.3.260.0060.04513.30
5.3.250.0080.04313.30
5.3.240.0110.03713.33
5.3.230.0080.02113.38
5.3.220.0020.05013.28
5.3.210.0080.03613.30
5.3.200.0070.02213.36
5.3.190.0040.02413.27
5.3.180.0080.02613.37
5.3.170.0060.04613.31
5.3.160.0040.04613.34
5.3.150.0050.04313.27
5.3.140.0130.02013.29
5.3.130.0110.03613.33
5.3.120.0080.04313.34
5.3.110.0110.03813.36
5.3.100.0120.03813.09
5.3.90.0070.04313.01
5.3.80.0050.04312.98
5.3.70.0050.03813.10
5.3.60.0070.04012.97
5.3.50.0040.03312.96
5.3.40.0050.04112.96
5.3.30.0080.03013.01
5.3.20.0030.03812.82
5.3.10.0030.04012.86
5.3.00.0020.03912.85
5.2.170.0070.05311.04
5.2.160.0130.04311.30
5.2.150.0070.06311.10
5.2.140.0030.06311.30
5.2.130.0030.06311.19
5.2.120.0070.04311.19
5.2.110.0070.06011.28
5.2.100.0100.05711.13
5.2.90.0100.05711.20
5.2.80.0000.06011.02
5.2.70.0070.05711.16
5.2.60.0070.03711.00
5.2.50.0000.03310.95
5.2.40.0000.06311.18
5.2.30.0100.06010.93
5.2.20.0030.06311.06
5.2.10.0070.06010.92
5.2.00.0070.06010.86
5.1.60.0030.05310.09
5.1.50.0030.05010.03
5.1.40.0030.05710.03
5.1.30.0100.05010.30
5.1.20.0130.05010.39
5.1.10.0030.04710.11
5.1.00.0070.04710.18
5.0.50.0030.0479.76
5.0.40.0170.0439.76
5.0.30.0030.0639.76
5.0.20.0030.0379.76
5.0.10.0070.0279.76
5.0.00.0070.0739.76
4.4.90.0030.0379.76
4.4.80.0000.0209.76
4.4.70.0000.0339.76
4.4.60.0070.0339.76
4.4.50.0030.0339.76
4.4.40.0030.0439.76
4.4.30.0030.0339.76
4.4.20.0030.0279.76
4.4.10.0000.0379.76
4.4.00.0030.0579.76
4.3.110.0100.0109.76
4.3.100.0030.0139.76
4.3.90.0070.0139.76
4.3.80.0000.0539.76
4.3.70.0000.0309.76
4.3.60.0000.0209.76
4.3.50.0030.0339.76
4.3.40.0030.0479.76
4.3.30.0000.0209.76
4.3.20.0000.0409.76
4.3.10.0000.0179.76
4.3.00.0000.0179.76

preferences:
57.27 ms | 401 KiB | 5 Q