3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace foo\bar\baz; class ClassA{ public function getClassExplode(){ $c = array_pop(explode('\\', get_class())); return $c; } public function getClassReflection(){ $c = (new \ReflectionClass($this))->getShortName(); return $c; } public function getClassBasename(){ $c = basename(str_replace('\\', '/', get_class())); return $c; } } $a = new ClassA(); $num = 1000; $rounds = 10; $res = array( "Reflection" => array(), "Basename" => array(), "Explode" => array(), ); for($r = 0; $r < $rounds; $r++){ $start = microtime(true); for($i = 0; $i < $num; $i++){ $a->getClassReflection(); } $end = microtime(true); $res["Reflection"][] = ($end-$start); $start = microtime(true); for($i = 0; $i < $num; $i++){ $a->getClassBasename(); } $end = microtime(true); $res["Basename"][] = ($end-$start); $start = microtime(true); for($i = 0; $i < $num; $i++){ $a->getClassExplode(); } $end = microtime(true); $res["Explode"][] = ($end-$start); } echo "Reflection: ".array_sum($res["Reflection"])/count($res["Reflection"])." s ".$a->getClassReflection()."\n"; echo "Basename: ".array_sum($res["Basename"])/count($res["Basename"])." s ".$a->getClassBasename()."\n"; echo "Explode: ".array_sum($res["Explode"])/count($res["Explode"])." s ".$a->getClassExplode()."\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)
8.0.110.0000.00816.83
8.0.100.0000.00816.92
8.0.90.0060.00316.88
8.0.80.0000.01816.89
8.0.70.0000.00916.66
8.0.60.0060.00316.71
8.0.50.0040.00416.87
8.0.30.0100.00916.97
8.0.20.0130.01217.40
8.0.10.0060.00316.98
8.0.00.0060.02216.90
7.4.240.0040.00416.35
7.4.230.0030.00616.35
7.4.220.0120.01616.64
7.4.210.0050.01416.58
7.4.200.0050.00516.32
7.4.160.0120.00816.40
7.4.150.0130.00817.40
7.4.140.0100.01417.86
7.4.130.0150.01316.38
7.4.120.0120.01516.54
7.4.110.0120.01216.52
7.4.100.0100.01616.45
7.4.90.0060.01416.48
7.4.80.0140.00719.39
7.4.70.0130.01016.66
7.4.60.0110.00816.43
7.4.50.0030.01716.45
7.4.40.0120.00616.49
7.4.30.0120.02016.36
7.4.00.0080.00814.91
7.3.300.0000.00816.38
7.3.290.0000.00816.32
7.3.280.0110.01216.37
7.3.270.0100.01017.40
7.3.260.0100.01216.55
7.3.250.0100.01516.38
7.3.240.0140.00916.56
7.3.230.0170.00616.47
7.3.210.0100.01316.55
7.3.200.0160.00716.63
7.3.190.0100.01016.49
7.3.180.0130.01616.38
7.3.170.0160.01216.46
7.3.160.0160.00916.40
7.2.330.0080.01416.71
7.2.320.0140.01116.64
7.2.310.0120.00916.37
7.2.300.0090.01216.72
7.2.290.0110.01116.87
7.2.110.0200.00416.10
7.2.60.0070.00717.01
7.1.200.0060.00315.98
7.1.90.0060.01817.97
7.1.80.0040.01117.98
7.1.70.0060.00917.00
7.1.60.0180.01235.21
7.1.50.0180.00734.80
7.1.40.0200.00734.66
7.1.30.0180.01234.70
7.1.20.0160.02334.59
7.1.10.0060.01716.49
7.1.00.0000.01416.67
7.0.230.0050.01817.59
7.0.220.0080.00817.52
7.0.210.0000.01416.65
7.0.200.0030.01216.65
7.0.190.0000.01616.93
7.0.180.0070.00716.37
7.0.170.0110.01116.54
7.0.160.0030.01916.32
7.0.150.0060.01616.38
7.0.140.0080.00516.42
7.0.130.0050.01016.78
7.0.120.0030.01216.53
7.0.110.0030.01216.46
7.0.100.0000.01416.59
7.0.90.0030.01216.34
7.0.80.0090.00616.52
7.0.70.0030.01816.54
7.0.60.0060.00916.25
7.0.50.0040.01116.32
7.0.40.0060.00916.51
7.0.30.0030.01316.61
7.0.20.0070.00716.38
7.0.10.0030.01716.55
7.0.00.0030.01316.63

preferences:
39.38 ms | 400 KiB | 5 Q