3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace foo\bar\baz; class ClassA{ public function getClassExplode(){ return explode('\\', static::class)[0]; } public function getClassReflection(){ return (new \ReflectionClass($this))->getShortName(); } public function getClassBasename(){ return basename(str_replace('\\', '/', static::class)); } } $a = new ClassA(); $num = 100000; $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)
7.4.100.0101.45016.10
7.4.90.0111.36816.63
7.4.80.0131.46117.89
7.4.70.0081.69116.32
7.4.60.0211.33916.49
7.4.50.0281.34216.44
7.4.40.0161.58216.18
7.4.30.0061.38216.22
7.4.20.0181.57616.41
7.4.10.0111.61316.38
7.4.00.0181.43916.48
7.3.220.0101.55916.55
7.3.210.0101.38616.65
7.3.200.0111.55816.59
7.3.190.0101.45016.47
7.3.180.0161.59316.49
7.3.170.0131.41916.47
7.3.160.0142.11116.38
7.3.150.0101.52316.41
7.3.140.0261.54716.37
7.3.130.0181.58616.52
7.3.120.0131.60116.46
7.3.110.0141.48416.43
7.3.100.0111.45515.93
7.3.90.0161.59615.93
7.3.80.0131.59516.03
7.3.70.0131.51915.81
7.3.60.0131.66715.91
7.3.50.0161.54415.97
7.3.40.0321.57915.95
7.3.30.0121.54215.93
7.3.20.0211.55215.96
7.3.10.0151.59016.00
7.3.00.0141.76415.92
7.2.330.0181.59116.80
7.2.320.0101.67416.73
7.2.310.0081.49416.70
7.2.300.0181.83816.76
7.2.290.0111.70316.66
7.2.280.0061.61216.53
7.2.270.0301.87116.67
7.2.260.0161.66716.70
7.2.250.0151.81416.55
7.2.240.0131.78416.68
7.2.230.0131.65816.25
7.2.220.0241.73816.22
7.2.210.0111.72416.07
7.2.200.0111.78816.11
7.2.190.0181.89716.07
7.2.180.0201.78516.20
7.2.170.0221.80416.13
7.2.160.0201.77216.22
7.2.150.0161.63016.28
7.2.140.0201.79216.20
7.2.130.0101.63716.17
7.2.120.0231.78116.05
7.2.110.0201.78116.07
7.2.100.0171.80516.10
7.2.90.0121.67916.14
7.2.80.0121.66116.14
7.2.70.0151.71916.14
7.2.60.0211.87316.19
7.2.50.0211.69916.16
7.2.40.0161.90216.20
7.2.30.0121.77516.20
7.2.20.0091.72216.35
7.2.10.0161.73716.45
7.2.00.0151.73616.34
7.1.330.0131.84415.57
7.1.320.0231.87615.02
7.1.310.0161.75015.07
7.1.300.0281.90315.11
7.1.290.0241.78815.01
7.1.280.0221.88614.92
7.1.270.0221.97515.01
7.1.260.0241.75014.95
7.1.250.0151.81214.99
7.1.240.0131.66815.17
7.1.230.0211.73815.21
7.1.220.0231.85515.21
7.1.210.0121.75415.15
7.1.200.0152.02215.21
7.1.190.0161.75715.16
7.1.180.0231.82815.20
7.1.170.0161.89415.19
7.1.160.0191.89415.22
7.1.150.0171.93815.16
7.1.140.0171.69115.58
7.1.130.0252.02115.53
7.1.120.0101.84615.50
7.1.110.0171.86915.52
7.1.100.0152.06615.58
7.1.90.0182.10915.61
7.1.80.0131.73715.57
7.1.70.0181.84015.62
7.1.60.0242.04715.61
7.1.50.0152.00015.54
7.1.40.0131.83115.54
7.1.30.0131.82715.47
7.1.20.0181.81215.56
7.1.10.0141.83315.54
7.1.00.0171.94315.49

preferences:
37.1 ms | 401 KiB | 5 Q