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, '~') . '~i', $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.70.0000.01217.49
7.1.60.0000.01817.29
7.1.50.0030.01017.25
7.1.40.0070.01716.77
7.1.30.0050.01117.09
7.1.20.0130.00417.09
7.1.10.0170.00316.77
7.1.00.0050.00717.05
7.0.200.0030.01017.01
7.0.190.0050.00517.05
7.0.180.0080.00316.33
7.0.170.0020.01016.58
7.0.160.0040.00716.60
7.0.150.0060.00816.59
7.0.140.0050.00516.69
7.0.130.0040.00817.10
7.0.120.0100.00416.97
7.0.110.0070.00716.77
7.0.100.0000.01216.57
7.0.90.0090.00216.70
7.0.80.0050.01016.60
7.0.70.0060.00416.59
7.0.60.0090.00216.64
7.0.50.0090.00616.69
7.0.40.0040.00615.27
7.0.30.0000.01015.27
7.0.20.0070.00315.27
7.0.10.0100.00215.27
7.0.00.0000.01015.31
5.6.300.0040.07620.80
5.6.290.0140.03520.83
5.6.280.0030.04820.88
5.6.270.0000.05020.90
5.6.260.0000.04620.98
5.6.250.0240.05220.91
5.6.240.0040.04620.88
5.6.230.0000.05020.87
5.6.220.0030.04220.83
5.6.210.0030.04920.95
5.6.200.0000.06621.03
5.6.190.0100.08320.97
5.6.180.0130.07921.05
5.6.170.0040.04320.87
5.6.160.0070.03920.94
5.6.150.0040.05021.05
5.6.140.0070.03921.00
5.6.130.0030.04721.00
5.6.120.0000.06120.94
5.6.110.0100.06720.98
5.6.100.0030.04720.95
5.6.90.0100.04220.76
5.6.80.0030.04120.35
5.6.70.0000.04820.24
5.6.60.0220.04120.41
5.6.50.0000.05120.38
5.6.40.0000.05120.14
5.6.30.0100.06120.36
5.6.20.0030.04020.20
5.6.10.0120.03720.19
5.6.00.0100.03820.38
5.5.380.0030.04617.54
5.5.370.0070.04417.59
5.5.360.0100.07917.42
5.5.350.0060.05017.53
5.5.340.0000.04718.01
5.5.330.0000.06918.07
5.5.320.0040.04918.13
5.5.310.0030.04018.05
5.5.300.0030.04517.86
5.5.290.0000.05418.18
5.5.280.0000.04317.76
5.5.270.0030.04018.08
5.5.260.0030.05218.03
5.5.250.0030.05117.84
5.5.240.0000.04717.39
5.5.230.0030.07917.55
5.5.220.0000.04117.38
5.5.210.0000.06417.47
5.5.200.0070.03417.45
5.5.190.0030.07417.45
5.5.180.0030.04017.45
5.5.160.0030.04217.44
5.5.150.0040.03917.47
5.5.140.0000.04517.21
5.5.130.0100.08517.44
5.5.120.0000.04017.44
5.5.110.0000.04517.44
5.5.100.0070.06317.40
5.5.90.0070.03617.34
5.5.80.0000.04717.38
5.5.70.0030.05017.25
5.5.60.0030.03817.33
5.5.50.0030.04017.27
5.5.40.0030.03717.30
5.5.30.0070.04117.41
5.5.20.0000.04017.33
5.5.10.0000.04617.30
5.5.00.0070.04717.32
5.4.450.0070.05019.41
5.4.440.0000.04819.46
5.4.430.0030.08119.39
5.4.420.0000.08719.39
5.4.410.0030.04119.40
5.4.400.0060.03818.95
5.4.390.0000.04518.89
5.4.380.0070.03419.11
5.4.370.0000.04319.11
5.4.360.0000.07418.92
5.4.350.0000.05719.11
5.4.340.0030.03918.98
5.4.320.0030.03919.11
5.4.310.0030.04519.11
5.4.300.0000.04019.20
5.4.290.0030.07319.02
5.4.280.0000.06018.98
5.4.270.0000.04518.97
5.4.260.0030.04319.11
5.4.250.0030.03819.20
5.4.240.0070.03519.23
5.4.230.0030.04018.91
5.4.220.0030.04419.21
5.4.210.0070.03719.06
5.4.200.0090.03819.03
5.4.190.0030.04519.12
5.4.180.0030.04219.05
5.4.170.0070.03619.19
5.4.160.0030.04218.89
5.4.150.0000.04619.18
5.4.140.0000.04116.73
5.4.130.0000.03916.52
5.4.120.0070.05716.77
5.4.110.0070.04116.46
5.4.100.0030.06516.80
5.4.90.0030.06516.53
5.4.80.0030.04116.68
5.4.70.0000.04816.77
5.4.60.0060.03516.64
5.4.50.0030.04216.68
5.4.40.0030.03516.51
5.4.30.0030.03916.61
5.4.20.0030.03616.71
5.4.10.0070.04716.58
5.4.00.0030.03415.90
5.3.290.0090.03515.41
5.3.280.0000.04015.41
5.3.270.0030.03815.41
5.3.260.0100.04715.41
5.3.250.0040.03515.41
5.3.240.0090.03115.41
5.3.230.0000.04015.41
5.3.220.0030.04115.41
5.3.210.0040.03915.41
5.3.200.0000.04215.41
5.3.190.0060.03215.41
5.3.180.0000.04015.41
5.3.170.0030.03615.41
5.3.160.0060.04515.41
5.3.150.0100.03815.41
5.3.140.0030.04415.41
5.3.130.0030.05015.41
5.3.120.0060.03415.41
5.3.110.0000.04115.41
5.3.100.0000.04215.41
5.3.90.0030.03915.41
5.3.80.0030.03815.41
5.3.70.0000.05115.41
5.3.60.0030.04015.41
5.3.50.0070.03215.41
5.3.40.0070.07115.41
5.3.30.0030.03715.41
5.3.20.0030.03715.41
5.3.10.0070.03115.41
5.3.00.0070.04215.41

preferences:
33.64 ms | 400 KiB | 5 Q