3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $bar = 'baz'; public function getBar() { return $this->bar; } } // http://3v4l.org/pc6lo#v540 class ClassicLazyFoo extends Foo { private $initialized = false; public function getBar() { $this->init(); return parent::getBar(); } private function init() { if ($this->initialized) { return; } \Closure::bind(function() { var_dump('lazy loading!'); $this->bar = 'Loaded from DB!'; }, $this, get_parent_class($this))->__invoke(); } } // look ma: no method overrides! class LazyPropertyLazyFoo extends Foo { public function __construct() { \Closure::bind(function() { unset($this->bar); }, $this, get_parent_class($this))->__invoke(); } // note that other accessors also need to be created for full functional completeness public function __get($name) { \Closure::bind(function() { var_dump('lazy loading!'); $this->bar = 'Loaded from DB!'; }, $this, get_parent_class($this))->__invoke(); return \Closure::bind(function() use ($name) { return $this->$name; }, $this, get_parent_class($this))->__invoke(); } } var_dump('Trying classic lazy-loading via method overrides:'); $classic = new ClassicLazyFoo(); var_dump($classic->getBar()); var_dump($classic->getBar()); var_dump($classic->getBar()); var_dump('Trying lazy-loading via undefined properties:'); $lazyProperty = new LazyPropertyLazyFoo(); var_dump($lazyProperty->getBar()); var_dump($lazyProperty->getBar()); var_dump($lazyProperty->getBar());

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.3.60.0090.00618.31
8.3.50.0110.00822.12
8.3.40.0160.00618.66
8.3.30.0110.00419.17
8.3.20.0040.00420.28
8.3.10.0000.00820.45
8.3.00.0060.00319.38
8.2.180.0100.01018.41
8.2.170.0110.00422.96
8.2.160.0060.00919.25
8.2.150.0080.00024.18
8.2.140.0080.00024.66
8.2.130.0000.00826.16
8.2.120.0000.00722.23
8.2.110.0060.00322.13
8.2.100.0110.00017.91
8.2.90.0080.00019.21
8.2.80.0040.00417.97
8.2.70.0080.00017.50
8.2.60.0050.00317.93
8.2.50.0040.00418.07
8.2.40.0040.00418.28
8.2.30.0000.00719.33
8.2.20.0000.00817.68
8.2.10.0070.00018.16
8.2.00.0060.00317.66
8.1.280.0110.00425.92
8.1.270.0000.00823.91
8.1.260.0000.00726.35
8.1.250.0040.00428.09
8.1.240.0090.00023.84
8.1.230.0030.00719.16
8.1.220.0040.00417.74
8.1.210.0000.00918.77
8.1.200.0040.00417.35
8.1.190.0000.00817.35
8.1.180.0030.00618.10
8.1.170.0000.01018.65
8.1.160.0000.00822.05
8.1.150.0000.00818.93
8.1.140.0040.00417.39
8.1.130.0030.00317.86
8.1.120.0040.00417.52
8.1.110.0000.00817.51
8.1.100.0040.00417.51
8.1.90.0050.00217.34
8.1.80.0030.00717.34
8.1.70.0000.00717.51
8.1.60.0040.00417.64
8.1.50.0110.00017.58
8.1.40.0000.00817.54
8.1.30.0080.00017.64
8.1.20.0080.00317.66
8.1.10.0030.00517.61
8.1.00.0030.00617.55
8.0.300.0000.00818.77
8.0.290.0000.00716.75
8.0.280.0000.00718.49
8.0.270.0000.00717.36
8.0.260.0070.00017.30
8.0.250.0050.00216.93
8.0.240.0000.00817.02
8.0.230.0030.00316.93
8.0.220.0000.00716.89
8.0.210.0030.00316.88
8.0.200.0000.00816.86
8.0.190.0070.00016.96
8.0.180.0050.00216.93
8.0.170.0000.00816.95
8.0.160.0000.00717.00
8.0.150.0000.00816.89
8.0.140.0000.00816.94
8.0.130.0060.00013.32
8.0.120.0050.00316.95
8.0.110.0000.00817.00
8.0.100.0040.00416.86
8.0.90.0000.00716.89
8.0.80.0070.01016.93
8.0.70.0050.00316.75
8.0.60.0000.00716.83
8.0.50.0060.00316.95
8.0.30.0110.00717.33
8.0.20.0100.01217.40
8.0.10.0000.00717.02
8.0.00.0140.00516.92
7.4.330.0000.00515.09
7.4.320.0060.00016.55
7.4.300.0030.00316.56
7.4.290.0000.01016.57
7.4.280.0000.00716.50
7.4.270.0000.00716.63
7.4.260.0080.00016.63
7.4.250.0070.00016.60
7.4.240.0040.00416.66
7.4.230.0000.00716.75
7.4.220.0030.01616.58
7.4.210.0100.01016.59
7.4.200.0000.00716.56
7.4.160.0150.00716.62
7.4.150.0160.01017.40
7.4.140.0090.00917.86
7.4.130.0120.00716.58
7.4.120.0110.00916.50
7.4.110.0070.01016.61
7.4.100.0040.01316.59
7.4.90.0080.01616.60
7.4.80.0060.01019.37
7.4.70.0150.00816.36
7.4.60.0100.00716.70
7.4.50.0040.00416.40
7.4.40.0160.00016.52
7.4.30.0100.00716.60
7.4.00.0080.01015.02
7.3.330.0060.00013.34
7.3.320.0000.00613.40
7.3.310.0030.00316.23
7.3.300.0030.00316.35
7.3.290.0110.00816.31
7.3.280.0120.00516.38
7.3.270.0030.01517.40
7.3.260.0130.01516.74
7.3.250.0140.00616.43
7.3.240.0060.01116.45
7.3.230.0100.01016.65
7.3.210.0150.00316.37
7.3.200.0140.00319.39
7.3.190.0110.01116.40
7.3.180.0100.00716.36
7.3.170.0220.00016.50
7.3.160.0150.00716.38
7.3.120.0040.00714.86
7.3.110.0070.01115.01
7.3.100.0030.01414.48
7.3.90.0000.01415.10
7.3.80.0090.00314.84
7.3.70.0090.00014.74
7.3.60.0030.00614.99
7.3.50.0110.00314.68
7.3.40.0130.00614.74
7.3.30.0060.01214.54
7.3.20.0070.01116.76
7.3.10.0070.00716.71
7.3.00.0070.01016.29
7.2.330.0090.00816.79
7.2.320.0120.00416.87
7.2.310.0120.00616.49
7.2.300.0050.01016.39
7.2.290.0080.01616.50
7.2.250.0060.01314.91
7.2.240.0060.01615.07
7.2.230.0080.00415.00
7.2.220.0000.01015.13
7.2.210.0100.00315.37
7.2.200.0060.00915.28
7.2.190.0060.00915.22
7.2.180.0030.00915.23
7.2.170.0060.00915.18
7.1.330.0090.00615.59
7.1.320.0100.00315.73
7.1.310.0040.01115.79
7.1.300.0090.00615.77
7.1.290.0030.01415.92
7.1.280.0030.01315.89
7.1.270.0000.01815.67
7.1.260.0060.00615.71
7.1.70.0000.01117.29
7.1.60.0130.00016.96
7.1.50.0100.01316.68
7.1.00.0000.08022.36
7.0.200.0070.01016.62
7.0.140.0000.07721.96
7.0.60.0070.08019.97
7.0.50.0100.05018.01
7.0.40.0070.06020.09
7.0.30.0200.07020.20
7.0.20.0370.07020.25
7.0.10.0030.07320.21
7.0.00.0100.08720.12
5.6.280.0030.07021.13
5.6.210.0170.07020.46
5.6.200.0070.08318.28
5.6.190.0070.04320.60
5.6.180.3030.04320.63
5.6.170.0300.07720.51
5.6.160.0100.08020.39
5.6.150.0000.04318.16
5.6.140.0100.03318.27
5.6.130.0130.08318.18
5.6.120.0030.04021.02
5.6.110.0100.03320.98
5.6.100.0030.07720.99
5.6.90.0030.09021.10
5.6.80.0030.05720.50
5.6.70.0170.03320.30
5.5.350.0400.07020.36
5.5.340.0100.07718.05
5.5.330.0000.05320.18
5.5.320.0330.05320.30
5.5.310.0300.04320.34
5.5.300.0030.03718.07
5.5.290.0070.08317.95
5.5.280.0170.07721.00
5.5.270.0070.07020.75
5.5.260.0070.06021.00
5.5.250.0030.08320.57
5.5.240.0270.08020.18
5.4.450.0700.06319.71
5.4.440.0930.06019.48
5.4.430.0930.05719.33
5.4.420.0700.00019.44
5.4.410.0670.00019.27
5.4.400.0630.00019.23
5.4.390.0630.00019.16
5.4.380.0370.05718.76
5.4.370.0500.05018.79
5.4.360.0130.05318.52
5.4.350.0100.06018.58
5.4.340.0270.06318.77
5.4.320.0100.03312.52
5.4.310.0060.03812.52
5.4.300.0030.03912.52
5.4.290.0060.04312.52
5.4.280.0040.03612.42
5.4.270.0050.03612.42
5.4.260.0060.03812.41
5.4.250.0050.03712.42
5.4.240.0060.03512.42
5.4.230.0070.04212.41
5.4.220.0030.03812.41
5.4.210.0080.03812.41
5.4.200.0060.03612.41
5.4.190.0070.03512.41
5.4.180.0090.04312.41
5.4.170.0070.03312.42
5.4.160.0090.03912.41
5.4.150.0040.03712.40
5.4.140.0080.03312.09
5.4.130.0090.03212.08
5.4.120.0070.03412.04
5.4.110.0070.03312.03
5.4.100.0040.03612.03
5.4.90.0080.03512.03
5.4.80.0060.04112.03
5.4.70.0060.03512.03
5.4.60.0100.03412.03
5.4.50.0040.03612.03
5.4.40.0120.03012.01
5.4.30.0080.03212.01
5.4.20.0050.04812.01
5.4.10.0050.03812.01
5.4.00.0080.03311.50
5.3.290.0060.03912.80
5.3.280.0040.04212.73
5.3.270.0050.04212.73
5.3.260.0070.03912.73
5.3.250.0040.03812.73
5.3.240.0040.03912.73
5.3.230.0070.04212.73
5.3.220.0050.04012.70
5.3.210.0090.04512.70
5.3.200.0100.03712.70
5.3.190.0080.03412.70
5.3.180.0070.04112.69
5.3.170.0080.03812.69
5.3.160.0070.03512.69
5.3.150.0070.03512.69
5.3.140.0080.04112.69
5.3.130.0060.03812.68
5.3.120.0100.04112.67
5.3.110.0110.03412.68
5.3.100.0040.03912.16
5.3.90.0040.03912.14
5.3.80.0040.04712.13
5.3.70.0050.04312.13
5.3.60.0100.03112.12
5.3.50.0030.04512.06
5.3.40.0040.03812.07
5.3.30.0030.03612.04
5.3.20.0040.04211.82
5.3.10.0080.03111.77
5.3.00.0090.03311.75
5.2.170.0080.0299.23
5.2.160.0030.0299.23
5.2.150.0050.0299.23
5.2.140.0040.0309.23
5.2.130.0050.0279.18
5.2.120.0040.0369.19
5.2.110.0050.0289.19
5.2.100.0020.0309.19
5.2.90.0060.0329.18
5.2.80.0040.0319.18
5.2.70.0040.0319.18
5.2.60.0030.0319.14
5.2.50.0040.0349.11
5.2.40.0070.0289.08
5.2.30.0030.0319.05
5.2.20.0040.0289.04
5.2.10.0060.0268.96
5.2.00.0040.0308.82
5.1.60.0050.0278.10
5.1.50.0040.0288.09
5.1.40.0030.0258.08
5.1.30.0050.0268.43
5.1.20.0050.0308.45
5.1.10.0040.0278.17
5.1.00.0030.0268.17
5.0.50.0060.0226.65
5.0.40.0050.0246.51
5.0.30.0030.0316.32
5.0.20.0020.0226.29
5.0.10.0030.0266.27
5.0.00.0020.0326.26
4.4.90.0030.0164.78
4.4.80.0030.0184.76
4.4.70.0040.0154.75
4.4.60.0030.0194.76
4.4.50.0010.0174.77
4.4.40.0010.0264.71
4.4.30.0040.0144.76
4.4.20.0020.0164.84
4.4.10.0040.0144.85
4.4.00.0010.0324.76
4.3.110.0010.0174.67
4.3.100.0020.0184.66
4.3.90.0020.0154.63
4.3.80.0040.0234.59
4.3.70.0040.0124.63
4.3.60.0000.0174.63
4.3.50.0030.0154.63
4.3.40.0040.0274.54
4.3.30.0040.0213.30
4.3.20.0020.0163.28
4.3.10.0030.0143.24
4.3.00.0030.0207.18

preferences:
39.36 ms | 401 KiB | 5 Q