3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Benchmark: Reflection Performance * * Conclusion: there is no performance-gain from caching reflection-objects. */ define('NUM_TESTS', 10); header('Content-type: text/plain'); $func = function($a, $b, $c) { // ... }; class Foo { public $a; protected $b; private $c; public function foo($a,$b,$c) {} protected function bar($a,$b,$c) {} private function baz($a,$b,$c) {} } for ($i=0; $i<NUM_TESTS; $i++) { $start = microtime(true); $ref = new ReflectionClass($func); $end = microtime(true); echo "ReflectionClass # $i: " . number_format(1000000*($end-$start), 3) . " µsec\n"; } for ($i=0; $i<NUM_TESTS; $i++) { $start = microtime(true); $ref = new ReflectionFunction($func); $end = microtime(true); echo "ReflectionFunction # $i: " . number_format(1000000*($end-$start), 3) . " µsec\n"; } class Cache { private $cache = array(); public function getReflection($class) { if (!isset($this->cache[$class])) { $this->cache[$class] = new ReflectionClass($class); } return $this->cache[$class]; } } $cache = new Cache; for ($i=0; $i<NUM_TESTS; $i++) { $start = microtime(true); $ref = $cache->getReflection('Foo'); $end = microtime(true); echo "Cached ReflectionClass # $i: " . number_format(1000000*($end-$start), 3) . " µsec\n"; }

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.10.0030.01715.21
7.4.00.0070.01114.94
7.3.130.0110.00714.98
7.3.120.0060.01315.02
7.3.110.0100.00814.97
7.3.100.0030.00914.96
7.3.90.0080.00915.07
7.3.80.0050.00715.00
7.3.70.0040.00814.96
7.3.60.0050.01115.01
7.3.50.0090.00715.00
7.3.40.0020.01414.90
7.3.30.0020.01314.82
7.3.20.0050.00916.75
7.3.10.0050.00916.80
7.3.00.0090.00616.74
7.2.260.0030.00915.13
7.2.250.0120.00414.90
7.2.240.0060.01115.03
7.2.230.0050.01015.04
7.2.220.0090.00715.15
7.2.210.0050.01215.49
7.2.200.0030.01215.19
7.2.190.0090.00915.19
7.2.180.0050.01015.18
7.2.170.0070.00915.24
7.2.160.0050.00915.14
7.2.150.0050.01016.88
7.2.140.0070.00717.20
7.2.130.0030.01316.93
7.2.120.0050.01216.99
7.2.110.0020.01116.82
7.2.100.0060.00717.04
7.2.90.0050.00917.12
7.2.80.0060.01117.02
7.2.70.0110.00317.18
7.2.60.0030.01017.04
7.2.50.0070.00917.14
7.2.40.0050.01017.11
7.2.30.0120.00317.13
7.2.20.0050.00816.95
7.2.10.0070.00716.94
7.2.00.0060.00817.69
7.1.330.0050.01215.98
7.1.320.0050.00615.79
7.1.310.0100.00515.80
7.1.300.0090.00615.68
7.1.290.0080.00815.74
7.1.280.0070.00815.82
7.1.270.0070.00815.79
7.1.260.0070.00915.98
7.1.250.0080.00615.86
7.1.240.0080.00815.84
7.1.230.0070.00715.60
7.1.220.0070.00715.86
7.1.210.0080.00815.97
7.1.200.0090.00016.01
7.1.190.0070.00715.68
7.1.180.0070.00715.88
7.1.170.0030.01215.70
7.1.160.0120.00315.97
7.1.150.0100.00315.87
7.1.140.0000.01015.70
7.1.130.0000.01515.70
7.1.120.0000.01715.89
7.1.110.0040.01115.81
7.1.100.0040.00815.70
7.1.90.0000.01315.90
7.1.80.0090.00615.92
7.1.70.0040.00616.64
7.1.60.0100.01017.67
7.1.50.0080.00916.54
7.1.40.0090.00315.87
7.1.30.0100.00315.85
7.1.20.0110.00315.59
7.1.10.0060.00915.88
7.1.00.0020.03019.35
7.0.330.0070.01015.65
7.0.320.0070.00715.52
7.0.310.0070.01015.26
7.0.300.0040.01115.32
7.0.290.0030.01415.44
7.0.280.0070.00715.39
7.0.270.0070.00715.36
7.0.260.0090.00315.44
7.0.250.0030.00615.53
7.0.240.0030.01015.64
7.0.230.0030.00515.53
7.0.220.0000.01415.52
7.0.210.0030.01415.43
7.0.200.0030.00716.21
7.0.190.0060.01015.18
7.0.180.0070.00415.28
7.0.170.0080.00415.70
7.0.160.0030.01015.42
7.0.150.0030.01315.53
7.0.140.0110.03718.91
7.0.130.0030.01315.70
7.0.120.0060.00915.30
7.0.110.0000.01815.34
7.0.100.0060.00615.21
7.0.90.0030.00915.61
7.0.80.0030.01315.25
7.0.70.0030.01015.85
7.0.60.0030.02517.76
7.0.50.0130.03716.88
7.0.40.0070.03715.71
7.0.30.0060.02515.87
7.0.20.0070.04515.72
7.0.10.0050.04315.60
7.0.00.0090.02915.64
5.6.400.0040.01114.59
5.6.390.0040.01114.67
5.6.380.0060.00614.43
5.6.370.0060.00914.61
5.6.360.0030.01014.48
5.6.350.0060.00914.82
5.6.340.0130.00314.65
5.6.330.0090.00314.77
5.6.320.0030.00614.77
5.6.310.0040.01114.41
5.6.300.0090.00614.76
5.6.290.0110.00014.45
5.6.280.0070.04017.82
5.6.270.0060.00914.34
5.6.260.0090.00614.73
5.6.250.0070.00714.57
5.6.240.0060.00914.62
5.6.230.0140.00414.68
5.6.220.0060.00614.58
5.6.210.0080.04517.82
5.6.200.0070.02516.29
5.6.190.0030.04716.40
5.6.180.0050.03416.43
5.6.170.0080.02816.53
5.6.160.0070.04316.39
5.6.150.0120.02216.37
5.6.140.0070.04516.41
5.6.130.0040.02916.39
5.6.120.0050.03016.37
5.6.110.0070.03516.33
5.6.100.0050.04516.40
5.6.90.0080.04316.35
5.6.80.0050.04116.19
5.6.70.0100.04216.02
5.6.60.0060.04016.02
5.6.50.0050.02516.05
5.6.40.0100.04016.14
5.6.30.0110.02016.07
5.6.20.0070.04215.99
5.6.10.0120.04016.11
5.6.00.0070.04016.13
5.5.380.0090.00614.28
5.5.370.0060.00314.48
5.5.360.0000.01714.52
5.5.350.0100.02417.57
5.5.340.0070.03316.29
5.5.330.0090.04016.38
5.5.320.0100.03416.15
5.5.310.0110.03816.28
5.5.300.0050.03516.24
5.5.290.0100.04016.39
5.5.280.0020.04916.24
5.5.270.0050.04916.24
5.5.260.0070.04716.12
5.5.250.0080.04316.22
5.5.240.0060.04115.92
5.5.230.0060.04315.94
5.5.220.0080.03715.97
5.5.210.0070.04216.02
5.5.200.0060.03115.91
5.5.190.0050.03916.08
5.5.180.0050.02416.04
5.5.170.0030.01414.32
5.5.160.0070.04516.01
5.5.150.0050.04215.96
5.5.140.0080.03715.79
5.5.130.0080.03815.88
5.5.120.0050.03416.03
5.5.110.0070.04216.00
5.5.100.0050.04115.85
5.5.90.0120.02215.65
5.5.80.0090.03715.85
5.5.70.0130.03715.89
5.5.60.0100.04215.67
5.5.50.0080.04015.85
5.5.40.0060.04115.79
5.5.30.0080.03815.91
5.5.20.0050.03715.92
5.5.10.0070.04215.62
5.5.00.0090.03615.70
5.4.450.0080.02015.28
5.4.440.0030.03715.26
5.4.430.0040.04315.39
5.4.420.0050.04715.22
5.4.410.0100.03815.39
5.4.400.0040.04415.34
5.4.390.0060.04015.25
5.4.380.0030.03115.21
5.4.370.0030.04715.22
5.4.360.0030.04615.18
5.4.350.0080.03815.19
5.4.340.0050.02215.13
5.4.330.0000.01210.98
5.4.320.0050.02915.31
5.4.310.0050.02715.18
5.4.300.0070.03615.27
5.4.290.0020.04515.15
5.4.280.0070.03815.19
5.4.270.0070.03515.24
5.4.260.0050.04115.13
5.4.250.0050.04415.24
5.4.240.0050.04415.26
5.4.230.0070.04215.18
5.4.220.0080.04015.26
5.4.210.0080.03515.08
5.4.200.0070.02515.28
5.4.190.0030.04415.09
5.4.180.0070.03915.11
5.4.170.0060.02515.12
5.4.160.0050.02115.19
5.4.150.0060.04015.05
5.4.140.0100.03113.80
5.4.130.0030.02513.93
5.4.120.0030.02513.75
5.4.110.0030.03213.71
5.4.100.0100.04013.79
5.4.90.0050.02513.75
5.4.80.0020.04214.03
5.4.70.0030.03713.96
5.4.60.0070.03313.88
5.4.50.0050.02413.98
5.4.40.0120.03713.95
5.4.30.0070.02414.00
5.4.20.0030.03913.77
5.4.10.0120.03413.77
5.4.00.0030.03613.59
5.3.290.0130.03312.83
5.3.280.0100.02212.59
5.3.270.0070.02912.70
5.3.260.0030.02312.86
5.3.250.0110.03612.64
5.3.240.0050.03112.50
5.3.230.0030.03112.82
5.3.220.0000.02912.64
5.3.210.0080.03712.71
5.3.200.0100.03312.45
5.3.190.0020.03312.66
5.3.180.0050.04112.64
5.3.170.0070.03312.81
5.3.160.0020.03412.83
5.3.150.0030.02612.84
5.3.140.0080.02312.78
5.3.130.0030.04512.63
5.3.120.0060.03512.63
5.3.110.0060.03812.75
5.3.100.0050.04212.49
5.3.90.0020.04212.50
5.3.80.0000.02612.43
5.3.70.0050.02012.42
5.3.60.0080.04012.27
5.3.50.0070.03412.39
5.3.40.0030.04112.39
5.3.30.0030.02412.43
5.3.20.0060.03312.29
5.3.10.0030.02212.00
5.3.00.0050.03212.20
5.2.170.0100.03011.10
5.2.160.0030.05311.14
5.2.150.0070.05711.13
5.2.140.0070.06011.09
5.2.130.0030.06311.08
5.2.120.0070.04310.92
5.2.110.0100.04710.96
5.2.100.0070.06011.00
5.2.90.0000.05311.02
5.2.80.0030.06011.05
5.2.70.0030.05711.09
5.2.60.0000.06311.02
5.2.50.0030.05310.99
5.2.40.0030.06310.83
5.2.30.0000.06310.97
5.2.20.0030.06710.86
5.2.10.0030.06310.86
5.2.00.0070.05710.70
5.1.60.0000.0479.83
5.1.50.0070.02710.07
5.1.40.0030.02310.05
5.1.30.0030.02710.36
5.1.20.0170.02710.39
5.1.10.0030.0439.90
5.1.00.0000.04010.04
5.0.50.0000.0478.37
5.0.40.0000.0308.43
5.0.30.0000.0378.30
5.0.20.0070.0338.16
5.0.10.0030.0408.24
5.0.00.0000.0578.14
4.4.90.0000.0307.74
4.4.80.0070.0307.74
4.4.70.0030.0377.74
4.4.60.0070.0307.74
4.4.50.0070.0307.75
4.4.40.0000.0407.77
4.4.30.0000.0177.78
4.4.20.0000.0377.79
4.4.10.0000.0337.79
4.4.00.0070.0507.80
4.3.110.0030.0177.81
4.3.100.0000.0177.82
4.3.90.0000.0307.82
4.3.80.0000.0537.84
4.3.70.0030.0307.85
4.3.60.0030.0337.86
4.3.50.0000.0337.86
4.3.40.0000.0577.86
4.3.30.0000.0377.86
4.3.20.0030.0337.86
4.3.10.0030.0277.86
4.3.00.0030.0137.86

preferences:
37.87 ms | 401 KiB | 5 Q