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; }

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)
5.4.450.0100.06019.36
5.4.440.0030.08319.44
5.4.430.0030.08019.33
5.4.420.0030.07719.43
5.4.410.0070.07719.34
5.4.400.0170.06718.88
5.4.390.0200.05319.25
5.4.380.0130.07019.16
5.4.370.0070.03719.24
5.4.360.0030.07019.08
5.4.350.0000.06719.14
5.4.340.0100.07318.97
5.4.320.0070.04319.15
5.4.310.0100.06019.14
5.4.300.0000.04319.11
5.4.290.0100.05018.96
5.4.280.0100.06318.85
5.4.270.0030.04719.11
5.4.260.0070.07019.00
5.4.250.0030.06019.20
5.4.240.0130.07319.07
5.4.230.0100.06718.96
5.4.220.0030.04019.19
5.4.210.0170.06719.07
5.4.200.0130.07019.23
5.4.190.0070.03719.20
5.4.180.0070.03719.19
5.4.170.0000.04719.13
5.4.160.0000.04019.06
5.4.150.0100.04019.20
5.4.140.0030.03316.38
5.4.130.0000.03716.36
5.4.120.0170.06016.35
5.4.110.0070.03316.72
5.4.100.0000.03716.46
5.4.90.0070.03316.50
5.4.80.0000.03716.69
5.4.70.0030.03716.43
5.4.60.0070.03316.41
5.4.50.0070.03716.27
5.4.40.0000.03716.64
5.4.30.0000.03716.40
5.4.20.0100.02716.26
5.4.10.0000.04016.43
5.4.00.0030.03315.91
5.3.290.0070.07714.72
5.3.280.0030.07714.66
5.3.270.0070.03714.51
5.3.260.0000.04014.68
5.3.250.0000.04014.63
5.3.240.0030.04014.63
5.3.230.0030.04014.64
5.3.220.0070.04014.60
5.3.210.0030.03714.60
5.3.200.0000.04314.63
5.3.190.0070.03314.59
5.3.180.0030.03714.61
5.3.170.0030.03714.58
5.3.160.0030.03714.58
5.3.150.0000.04314.58
5.3.140.0030.03714.58
5.3.130.0000.04714.49
5.3.120.0070.03314.57
5.3.110.0070.03314.61
5.3.100.0000.04014.09
5.3.90.0000.04014.20
5.3.80.0070.04014.08
5.3.70.0000.04014.04
5.3.60.0030.06713.90
5.3.50.0030.03713.99
5.3.40.0070.04014.02
5.3.30.0030.04714.09
5.3.20.0070.04013.87
5.3.10.0070.07013.68
5.3.00.0030.07713.54

preferences:
32.93 ms | 401 KiB | 5 Q