3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Thesaurus { protected $synonyms = array( array('great', 'wonderful', 'amazing', 'fabulous', 'awesome', 'stunning'), array('look', 'see', 'observe') ); public function lookup($word) { foreach ($this->synonyms as $index => $synonym) { if (in_array(strtolower($word), $synonym)) { unset($synonym[ array_search($word, $synonym) ]); return $synonym[ array_rand($synonym) ]; } } return $word; } } class Transformer { protected $thesaurus; public function __construct(Thesaurus $thesaurus) { $this->thesaurus = $thesaurus; } public function transform($string) { foreach (str_word_count($string, 1) as $word) { $string = $this->replace($word, $this->thesaurus->lookup($word), $string); } return $string; } private function replace($needle, $replacement, $haystack) { echo $needle . ' ' . $replacement . PHP_EOL; return preg_replace( '/(?<!#)' . preg_quote($needle) . '(?!#)/', '#' . $replacement . '#', $haystack, 1 ); } } $transformer = new Transformer(new Thesaurus); foreach (range(1, 20) as $index) { echo $transformer->transform('This is my great description. It really is wonderful. Look how wonderful it is.'), PHP_EOL; echo '-----------------------------------------------------' . PHP_EOL; }

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)
7.1.00.0030.07022.54
7.0.130.0030.07321.94
7.0.120.0130.06322.09
7.0.110.0000.08022.14
7.0.100.0030.07722.22
7.0.90.0030.08022.06
7.0.80.0000.07722.03
7.0.70.0070.07022.13
7.0.60.0000.07722.13
7.0.50.0130.06722.23
7.0.40.0000.07722.22
7.0.30.0030.07322.04
7.0.20.0000.08022.09
7.0.10.0100.06722.11
7.0.00.0130.06722.21
5.6.280.0100.07020.92
5.6.270.0070.07320.88
5.6.260.0030.07721.14
5.6.250.0100.07021.09
5.6.240.0100.07321.04
5.6.230.0100.07321.09
5.6.220.0070.07321.09
5.6.210.0000.08020.97
5.6.200.0030.08021.07
5.6.190.0100.07721.07
5.6.180.0100.06721.04
5.6.170.0070.07020.99
5.6.160.0000.07021.01
5.6.150.0100.07721.04
5.6.140.0130.07021.08
5.6.130.0030.07721.11
5.6.120.0000.08020.98
5.6.110.0070.07320.95
5.6.100.0000.08320.84
5.6.90.0100.07020.98
5.6.80.0000.07720.24
5.6.70.0100.06720.35
5.6.60.0030.07320.41
5.6.50.0070.07020.17
5.6.40.0070.07020.33
5.6.30.0030.06720.39
5.6.20.0030.07320.44
5.6.10.0070.06020.24
5.6.00.0030.07320.46
5.5.380.0030.07317.63
5.5.370.0070.06717.64
5.5.360.0070.07317.61
5.5.350.0070.06717.56
5.5.340.0130.06718.09
5.5.330.0000.07718.12
5.5.320.0000.07718.30
5.5.310.0000.07718.12
5.5.300.0000.07018.14
5.5.290.0030.07718.04
5.5.280.0100.07317.89
5.5.270.0070.07717.89
5.5.260.0030.10018.13
5.5.250.0000.08017.93
5.5.240.0000.06317.25
5.5.230.0070.07317.34
5.5.220.0100.06317.30
5.5.210.0030.07017.64
5.5.200.0030.07017.23
5.5.190.0070.06717.66
5.5.180.0000.06717.50
5.5.160.0000.07017.21
5.5.150.0000.07017.47
5.5.140.0070.06317.58
5.5.130.0000.06717.43
5.5.120.0030.06317.47
5.5.110.0070.06017.64
5.5.100.0030.07317.40
5.5.90.0030.07017.47
5.5.80.0000.07317.14
5.5.70.0030.07317.35
5.5.60.0000.07317.20
5.5.50.0070.06717.20
5.5.40.0000.07317.06
5.5.30.0070.06717.09
5.5.20.0030.06717.34
5.5.10.0000.06717.10
5.5.00.0000.07717.19
5.4.450.0100.06719.38
5.4.440.0000.08019.64
5.4.430.0030.07019.66
5.4.420.0000.07719.34
5.4.410.0000.07019.52
5.4.400.0030.07019.18
5.4.390.0100.06719.18
5.4.380.0100.06319.20
5.4.370.0130.06019.21
5.4.360.0030.07318.98
5.4.350.0100.06319.15
5.4.340.0070.07019.32
5.4.320.0030.07319.21
5.4.310.0000.07319.02
5.4.300.0070.06719.32
5.4.290.0030.06319.15
5.4.280.0000.07019.18
5.4.270.0030.07018.93
5.4.260.0070.06719.15
5.4.250.0000.07319.00
5.4.240.0070.06719.14
5.4.230.0030.07318.90
5.4.220.0130.06318.98
5.4.210.0100.06319.20
5.4.200.0100.06319.19
5.4.190.0000.07019.38
5.4.180.0030.07019.14
5.4.170.0030.07019.14
5.4.160.0070.06719.21
5.4.150.0030.07019.16
5.4.140.0030.06716.67
5.4.130.0000.07016.51
5.4.120.0070.06316.60
5.4.110.0030.06316.52
5.4.100.0030.06316.51
5.4.90.0000.06716.55
5.4.80.0030.06716.54
5.4.70.0030.06716.58
5.4.60.0030.06316.44
5.4.50.0130.05716.45
5.4.40.0000.07016.42
5.4.30.0000.07016.61
5.4.20.0000.06716.41
5.4.10.0030.06716.33
5.4.00.0030.06715.82
5.3.290.0000.07314.68
5.3.280.0030.06314.51
5.3.270.0070.06714.63
5.3.260.0000.09714.74
5.3.250.0070.06714.48
5.3.240.0000.07314.68
5.3.230.0000.06314.76
5.3.220.0070.06314.61
5.3.210.0070.06714.59
5.3.200.0000.07014.81
5.3.190.0030.06714.70
5.3.180.0000.06314.59
5.3.170.0000.07314.73
5.3.160.0070.06714.66
5.3.150.0030.07014.59
5.3.140.0000.07014.43
5.3.130.0000.07714.42
5.3.120.0030.07014.65
5.3.110.0100.06314.57
5.3.100.0070.06313.91
5.3.90.0070.06314.08
5.3.80.0030.06314.01
5.3.70.0000.06714.03
5.3.60.0030.06714.15
5.3.50.0030.06714.04
5.3.40.0000.07014.09
5.3.30.0000.06713.90
5.3.20.0030.05713.84
5.3.10.0000.07013.89
5.3.00.0070.06313.75

preferences:
35.28 ms | 401 KiB | 5 Q