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) { $new_word = $this->thesaurus->lookup($word); if ($word !== $new_word) { if (ctype_upper($word[0])) { $new_word = ucfirst($new_word); } $string = $this->replace($word, $new_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 str_replace('#', '', $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.4.00.0130.00615.38
7.3.120.0130.00015.31
7.3.110.0040.01414.86
7.3.100.0090.01014.82
7.3.90.0040.01214.99
7.3.80.0130.00314.81
7.3.70.0030.01015.15
7.3.60.0030.01015.05
7.3.50.0070.00715.18
7.3.40.0100.00314.82
7.3.30.0040.00815.07
7.3.20.0120.00316.79
7.3.10.0070.01016.67
7.3.00.0070.01016.39
7.2.250.0070.01115.35
7.2.240.0030.01715.50
7.2.230.0040.01115.27
7.2.220.0060.00915.16
7.2.210.0060.00615.03
7.2.200.0000.01715.18
7.2.190.0060.01115.00
7.2.180.0030.01215.34
7.2.170.0070.01015.06
7.2.160.0000.01515.38
7.2.150.0080.00816.88
7.2.140.0070.01316.91
7.2.130.0070.00816.91
7.2.120.0000.01016.89
7.2.110.0100.01016.63
7.2.100.0060.01016.80
7.2.90.0000.01417.10
7.2.80.0050.00516.98
7.2.70.0000.01516.86
7.2.60.0120.00316.94
7.2.50.0040.00817.02
7.2.40.0140.00316.98
7.2.30.0110.00716.75
7.2.20.0110.00416.94
7.2.10.0100.00716.86
7.2.00.0120.00317.07
7.1.330.0070.01116.18
7.1.320.0090.00616.04
7.1.310.0000.01516.00
7.1.300.0070.00715.91
7.1.290.0100.00015.95
7.1.280.0150.00415.96
7.1.270.0140.00415.87
7.1.260.0000.01416.13
7.1.250.0060.00915.65
7.1.240.0100.00315.78
7.1.230.0030.01016.08
7.1.220.0030.00715.52
7.1.210.0030.01115.72
7.1.200.0030.01015.43
7.1.190.0090.00615.76
7.1.180.0000.01115.93
7.1.170.0040.01215.88
7.1.160.0030.01015.36
7.1.150.0110.00716.11
7.1.140.0060.01215.56
7.1.130.0040.01215.88
7.1.120.0030.01415.79
7.1.110.0040.00815.81
7.1.100.0100.00615.79
7.1.90.0090.00616.09
7.1.80.0040.01215.90
7.1.70.0050.00816.66
7.1.60.0110.01017.53
7.1.50.0110.01016.65
7.1.40.0120.00616.09
7.1.30.0030.01016.11
7.1.20.0060.00616.13
7.1.10.0060.00816.00
7.1.00.0090.04019.15
7.0.330.0060.00915.44
7.0.320.0100.00615.33
7.0.310.0030.01015.27
7.0.300.0070.00715.02
7.0.290.0040.00715.53
7.0.280.0100.00315.57
7.0.270.0100.00715.27
7.0.260.0110.00415.32
7.0.250.0040.01115.30
7.0.240.0030.01215.72
7.0.230.0030.01015.61
7.0.220.0080.00415.60
7.0.210.0070.01015.48
7.0.200.0050.00716.31
7.0.190.0120.00315.60
7.0.180.0080.00515.47
7.0.170.0060.01015.59
7.0.160.0070.01015.65
7.0.150.0060.01015.67
7.0.140.0020.04618.77
7.0.130.0040.00815.58
7.0.120.0030.01015.70
7.0.110.0120.00315.49
7.0.100.0070.04217.73
7.0.90.0100.04217.77
7.0.80.0160.03617.57
7.0.70.0110.03317.63
7.0.60.0120.04317.70
7.0.50.0050.02518.05
7.0.40.0070.02316.70
7.0.30.0050.02616.78
7.0.20.0020.02816.96
7.0.10.0080.02516.81
7.0.00.0070.03616.93
5.6.400.0060.01314.82
5.6.390.0070.01014.41
5.6.380.0030.01014.05
5.6.370.0040.01114.22
5.6.360.0070.01014.12
5.6.350.0130.00014.39
5.6.340.0040.01114.35
5.6.330.0090.00914.45
5.6.320.0040.01114.36
5.6.310.0040.01414.62
5.6.300.0070.01114.45
5.6.290.0090.00914.50
5.6.280.0050.04217.71
5.6.270.0100.00714.46
5.6.260.0100.00314.21
5.6.250.0090.04217.40
5.6.240.0100.04317.50
5.6.230.0140.03717.54
5.6.220.0050.03817.42
5.6.210.0050.04717.74
5.6.200.0080.03017.74
5.6.190.0050.02817.58
5.6.180.0050.02817.85
5.6.170.0090.02317.69
5.6.160.0080.03317.76
5.6.150.0090.03317.77
5.6.140.0060.03117.81
5.6.130.0030.02817.62
5.6.120.0070.02517.93
5.6.110.0020.02817.81
5.6.100.0100.02817.77
5.6.90.0070.02517.66
5.6.80.0050.02517.35
5.6.70.0020.02817.35
5.6.60.0050.02817.40
5.6.50.0060.03117.47
5.6.40.0080.04117.38
5.6.30.0100.03817.39
5.6.20.0090.04217.38
5.6.10.0120.04017.42
5.6.00.0050.03417.41
5.5.380.0100.04217.45
5.5.370.0120.04217.42
5.5.360.0080.04217.47
5.5.350.0100.04117.52
5.5.340.0030.02917.49
5.5.330.0030.02817.61
5.5.320.0050.04517.55
5.5.310.0040.02917.57
5.5.300.0040.03917.79
5.5.290.0060.02717.72
5.5.280.0070.02517.64
5.5.270.0030.02917.65
5.5.260.0050.04017.57
5.5.250.0080.03417.37
5.5.240.0080.02817.02
5.5.230.0030.02817.22
5.5.220.0090.02217.31
5.5.210.0020.03017.31
5.5.200.0070.04317.24
5.5.190.0110.04017.27
5.5.180.0150.03817.39
5.5.170.0100.00614.18
5.5.160.0050.03717.31
5.5.150.0060.03717.42
5.5.140.0070.04217.37
5.5.130.0090.04017.34
5.5.120.0070.04717.39
5.5.110.0120.04017.27
5.5.100.0090.04917.30
5.5.90.0050.04617.23
5.5.80.0050.04317.21
5.5.70.0030.04817.21
5.5.60.0110.04317.31
5.5.50.0100.04017.21
5.5.40.0060.04617.10
5.5.30.0130.03717.29
5.5.20.0030.04617.22
5.5.10.0090.04517.04
5.5.00.0050.04716.97
5.4.450.0090.02115.59
5.4.440.0050.02315.59
5.4.430.0050.02215.56
5.4.420.0050.02415.54
5.4.410.0050.02315.56
5.4.400.0050.02115.30
5.4.390.0060.02015.38
5.4.380.0080.04115.30
5.4.370.0100.02615.43
5.4.360.0050.04115.31
5.4.350.0100.04315.43
5.4.340.0100.03515.45
5.4.330.0090.00311.71
5.4.320.0090.03415.30
5.4.310.0100.03615.42
5.4.300.0050.03215.33
5.4.290.0080.04215.30
5.4.280.0050.04315.36
5.4.270.0070.04215.43
5.4.260.0050.04515.37
5.4.250.0120.03415.33
5.4.240.0060.04015.29
5.4.230.0100.03615.47
5.4.220.0100.03815.37
5.4.210.0100.03915.37
5.4.200.0090.03915.47
5.4.190.0070.04415.33
5.4.180.0010.04615.42
5.4.170.0080.03615.40
5.4.160.0050.03815.46
5.4.150.0110.03615.46
5.4.140.0080.03514.10
5.4.130.0030.04214.08
5.4.120.0050.02814.09
5.4.110.0030.04214.14
5.4.100.0060.04214.10
5.4.90.0030.04714.06
5.4.80.0070.03814.04
5.4.70.0080.03814.13
5.4.60.0080.03514.04
5.4.50.0050.02514.08
5.4.40.0050.04314.09
5.4.30.0110.03814.06
5.4.20.0080.04014.05
5.4.10.0050.04114.02
5.4.00.0060.04113.83
5.3.290.0060.04113.23
5.3.280.0020.04713.16
5.3.270.0120.04213.17
5.3.260.0050.04613.16
5.3.250.0090.03813.20
5.3.240.0060.04413.20
5.3.230.0070.03813.20
5.3.220.0110.03813.22
5.3.210.0080.03613.18
5.3.200.0050.04613.11
5.3.190.0060.04113.14
5.3.180.0090.03913.20
5.3.170.0060.03913.11
5.3.160.0060.04113.19
5.3.150.0020.04313.20
5.3.140.0050.04213.11
5.3.130.0040.04113.17
5.3.120.0090.04413.20
5.3.110.0020.03413.15
5.3.100.0100.03812.93
5.3.90.0050.04012.86
5.3.80.0060.03912.84
5.3.70.0080.04012.92
5.3.60.0050.03512.88
5.3.50.0030.03212.80
5.3.40.0050.04112.89
5.3.30.0050.03212.85
5.3.20.0070.04112.77
5.3.10.0050.04412.70
5.3.00.0070.04012.70
5.2.170.0030.05311.09
5.2.160.0100.05711.12
5.2.150.0000.07011.03
5.2.140.0030.06711.08
5.2.130.0100.06010.98
5.2.120.0130.03711.04
5.2.110.0070.05711.17
5.2.100.0070.02711.19
5.2.90.0070.06011.18
5.2.80.0130.06010.98
5.2.70.0030.06011.15
5.2.60.0130.05310.93
5.2.50.0030.05310.99
5.2.40.0130.05311.01
5.2.30.0070.06711.10
5.2.20.0000.06311.05
5.2.10.0030.04710.90
5.2.00.0030.05310.66
5.1.60.0070.05010.02
5.1.50.0070.0509.86
5.1.40.0030.03010.04
5.1.30.0030.06010.43
5.1.20.0000.06310.31
5.1.10.0000.06010.18
5.1.00.0070.0579.98
5.0.50.0070.0478.57
5.0.40.0030.0478.29
5.0.30.0030.0478.35
5.0.20.0030.0438.13
5.0.10.0100.0438.27
5.0.00.0130.0608.13
4.4.90.0070.0308.13
4.4.80.0000.0208.13
4.4.70.0000.0378.13
4.4.60.0100.0308.13
4.4.50.0070.0338.13
4.4.40.0000.0578.13
4.4.30.0030.0378.13
4.4.20.0030.0338.13
4.4.10.0000.0408.13
4.4.00.0030.0538.13
4.3.110.0000.0378.13
4.3.100.0030.0338.13
4.3.90.0000.0378.13
4.3.80.0030.0538.13
4.3.70.0030.0378.13
4.3.60.0030.0278.13
4.3.50.0030.0338.13
4.3.40.0030.0538.13
4.3.30.0030.0238.13
4.3.20.0030.0278.13
4.3.10.0000.0378.13
4.3.00.0030.0308.13

preferences:
43.13 ms | 401 KiB | 5 Q