3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Validator { const GREATER = [self::class, 'greater']; const IS_TYPE = [self::class, 'isType']; public static function all(...$rules) { foreach ($rules as $def) { $rule = array_shift($def); if ($rule(...$def)) { continue; } return false; } return true; } public static function greater($value, $compare) : bool { return $value > $compare; } public static function isType($value, $type) : bool { return gettype($value) === $type; } } class Model { const RULES = [ 'foo' => [ 'integer', // shorthand for [Validator::IS_TYPE, 'integer'] [Validator::GREATER, 10] ] ]; protected $foo; public function set($name, $value) { if ($this->isValid($name, $value)) { $this->$name = $value; return; } throw new Exception("{$name} cannot be {$value}"); } function isValid($name, $value) : bool { $rules = []; foreach (self::RULES[$name] as $rule) { // convenience: turn strings into typehints if (is_string($rule)) { $rules[] = [Validator::IS_TYPE, $value]; continue; } // ... other convenience parsing ... // for fully defined rules, just add value arg at proper spot array_splice($rule, 1, 0, $value); $rules[] = $rule; } return Validator::ALL($rules); } } $m = new Model; $m->set('foo', 15); var_dump($m); $m->set('foo', 7);

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.0070.01118.68
8.3.50.0170.00316.67
8.3.40.0090.00918.98
8.3.30.0090.00618.94
8.3.20.0040.00420.25
8.3.10.0070.00721.90
8.3.00.0040.00421.02
8.2.180.0150.00618.54
8.2.170.0200.00022.96
8.2.160.0100.00722.13
8.2.150.0050.00324.18
8.2.140.0110.00324.66
8.2.130.0000.00822.25
8.2.120.0000.00726.35
8.2.110.0000.01020.45
8.2.100.0110.00017.91
8.2.90.0030.00619.26
8.2.80.0060.00319.48
8.2.70.0030.00517.75
8.2.60.0000.00817.92
8.2.50.0000.00918.10
8.2.40.0000.00820.59
8.2.30.0030.00621.11
8.2.20.0060.00318.02
8.2.10.0040.00418.13
8.2.00.0000.00718.12
8.1.280.0100.01025.92
8.1.270.0070.00022.16
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0100.00023.80
8.1.230.0040.00722.21
8.1.220.0080.00017.74
8.1.210.0050.00318.77
8.1.200.0030.00617.35
8.1.190.0030.00517.35
8.1.180.0000.00818.10
8.1.170.0080.00018.62
8.1.160.0070.00018.91
8.1.150.0040.00418.83
8.1.140.0040.00419.59
8.1.130.0000.00718.84
8.1.120.0000.00717.48
8.1.110.0090.00317.09
8.1.100.0040.00417.48
8.1.90.0040.00417.48
8.1.80.0000.00817.55
8.1.70.0000.00817.47
8.1.60.0000.00817.61
8.1.50.0000.00817.50
8.1.40.0050.00317.56
8.1.30.0000.00817.75
8.1.20.0040.00417.57
8.1.10.0000.00817.60
8.1.00.0000.01117.48
8.0.300.0000.00818.77
8.0.290.0000.00716.75
8.0.280.0070.00018.53
8.0.270.0000.00717.27
8.0.260.0000.00818.54
8.0.250.0070.00017.04
8.0.240.0060.00316.89
8.0.230.0050.00517.11
8.0.220.0000.00716.88
8.0.210.0030.00317.01
8.0.200.0070.00017.03
8.0.190.0000.00817.03
8.0.180.0040.00417.01
8.0.170.0070.00017.02
8.0.160.0000.00716.88
8.0.150.0040.00416.93
8.0.140.0000.00816.96
8.0.130.0000.00513.50
8.0.120.0070.00016.94
8.0.110.0000.00716.95
8.0.100.0060.00317.04
8.0.90.0040.00416.78
8.0.80.0120.01016.86
8.0.70.0070.00016.84
8.0.60.0040.00416.87
8.0.50.0040.00416.84
8.0.30.0080.01017.06
8.0.20.0150.01217.40
8.0.10.0030.00316.93
8.0.00.0120.00616.84
7.4.330.0000.00615.55
7.4.320.0000.00616.46
7.4.300.0070.00016.53
7.4.290.0030.00316.59
7.4.280.0020.00516.63
7.4.270.0030.00316.42
7.4.260.0000.00513.22
7.4.250.0000.00916.48
7.4.240.0000.00716.49
7.4.230.0020.00416.63
7.4.220.0060.01616.70
7.4.210.0090.00616.49
7.4.200.0040.00416.43
7.4.160.0080.01016.64
7.4.150.0120.00617.40
7.4.140.0180.00317.86
7.4.130.0150.00416.60
7.4.120.0140.00416.53
7.4.110.0100.01316.39
7.4.100.0100.01316.37
7.4.90.0120.01216.59
7.4.80.0090.01219.39
7.4.70.0070.01016.61
7.4.60.0130.00316.60
7.4.50.0040.01116.58
7.4.40.0110.00816.50
7.4.30.0100.01316.50
7.4.00.0030.01315.02
7.3.330.0000.00613.40
7.3.320.0040.00413.41
7.3.310.0090.00016.49
7.3.300.0070.00016.41
7.3.290.0080.00816.38
7.3.280.0080.00816.42
7.3.270.0090.00917.40
7.3.260.0080.00916.62
7.3.250.0120.01016.46
7.3.240.0080.01116.44
7.3.230.0090.00916.61
7.3.210.0110.00716.53
7.3.200.0110.00716.36
7.3.190.0060.00916.43
7.3.180.0090.00616.45
7.3.170.0090.00616.46
7.3.160.0130.01016.57
7.3.120.0070.00914.91
7.3.110.0100.00814.87
7.3.100.0080.00714.86
7.3.90.0050.01014.91
7.3.80.0060.00814.94
7.3.70.0020.01114.86
7.3.60.0100.00614.78
7.3.50.0030.01014.91
7.3.40.0070.00514.82
7.3.30.0020.01414.95
7.3.20.0070.00916.66
7.3.10.0050.00916.72
7.3.00.0040.01016.58
7.2.330.0030.01316.85
7.2.320.0140.00716.75
7.2.310.0080.00816.65
7.2.300.0090.00916.55
7.2.290.0080.00816.50
7.2.250.0080.00815.18
7.2.240.0050.01215.06
7.2.230.0030.01215.09
7.2.220.0060.00915.15
7.2.210.0070.00714.99
7.2.200.0040.01215.21
7.2.190.0030.01315.11
7.2.180.0070.00714.86
7.2.170.0060.00915.03
7.2.160.0060.00614.99
7.2.150.0050.01316.91
7.2.140.0040.00816.76
7.2.130.0080.00916.90
7.2.120.0060.00917.01
7.2.110.0050.01116.76
7.2.100.0050.00716.93
7.2.90.0020.01216.96
7.2.80.0030.00916.88
7.2.70.0070.00717.08
7.2.60.0030.01117.04
7.2.50.0080.00516.92
7.2.40.0020.01216.94
7.2.30.0060.00617.00
7.2.20.0060.00617.02
7.2.10.0030.01316.95
7.2.00.0060.01017.66
7.1.330.0050.01215.93
7.1.320.0090.00715.80
7.1.310.0050.00715.88
7.1.300.0050.00915.87
7.1.290.0040.00615.78
7.1.280.0060.00715.76
7.1.270.0060.01015.68
7.1.260.0050.00815.70
7.1.250.0020.01115.59
7.1.240.0030.01615.71
7.1.230.0100.00715.64
7.1.220.0060.00315.73
7.1.210.0060.00315.87
7.1.200.0060.00915.93
7.1.190.0000.01415.89
7.1.180.0100.00315.65
7.1.170.0060.00915.77
7.1.160.0090.00615.53
7.1.150.0060.00315.56
7.1.140.0100.00315.84
7.1.130.0090.00315.49
7.1.120.0060.00315.85
7.1.110.0040.00415.96
7.1.100.0070.00415.68
7.1.90.0080.00315.94
7.1.80.0000.01115.60
7.1.70.0040.00816.52
7.1.60.0050.01424.60
7.1.50.0450.00424.40
7.1.40.0630.01524.19
7.1.30.0320.01224.29
7.1.20.0220.00524.21
7.1.10.0260.01115.48
7.1.00.0380.00915.30
7.0.330.0100.00315.42
7.0.320.0100.00615.10
7.0.310.0030.00915.18
7.0.300.0070.00715.45
7.0.290.0040.00715.41
7.0.280.0040.00715.39
7.0.270.0040.00415.40
7.0.260.0030.00615.49
7.0.250.0040.01115.48
7.0.240.0070.00715.55
7.0.230.0060.00315.45
7.0.220.0080.00615.45
7.0.210.0040.01115.58
7.0.200.0070.01115.09
7.0.190.0360.00615.15
7.0.180.0410.00614.91
7.0.170.0270.00814.96
7.0.160.0050.01014.99
7.0.150.0350.00314.91
7.0.140.0090.00614.87
7.0.130.0050.01115.21
7.0.120.0020.01115.14
7.0.110.0080.00714.93
7.0.100.0400.00715.02
7.0.90.0480.01114.84
7.0.80.0400.01115.03
7.0.70.0370.00515.02
7.0.60.0020.01114.94
7.0.50.0320.00915.05
7.0.40.0500.00313.86
7.0.30.0410.00614.06
7.0.20.0380.01213.96
7.0.10.0290.00614.06
7.0.00.0310.00813.89
5.6.400.0000.01113.97
5.6.390.0060.01314.09
5.6.380.0070.00714.25
5.6.370.0070.00714.27
5.6.360.0090.00614.16
5.6.350.0030.01014.10
5.6.340.0040.00714.24
5.6.330.0030.00613.97
5.6.320.0040.00814.25
5.6.310.0060.00914.18
5.6.300.0060.00914.14
5.6.290.0000.00813.82
5.6.280.0000.01314.12
5.6.270.0080.00014.39
5.6.260.0060.00914.15
5.6.250.0080.00014.00
5.6.240.0070.00714.33
5.6.230.0070.00713.95
5.6.220.0030.01014.04
5.6.210.0110.00314.07
5.6.200.0060.00914.19
5.6.190.0100.00314.23
5.6.180.0060.00314.36
5.6.170.0070.00714.08
5.6.160.0030.01014.17
5.6.150.0080.00313.89
5.6.140.0070.00714.23
5.6.130.0000.01114.34
5.6.120.0070.01014.34
5.6.110.0120.00314.24
5.6.100.0100.00714.09
5.6.90.0110.00013.99
5.6.80.0100.00014.30
5.6.70.0000.00914.09
5.6.60.0120.00014.18
5.6.50.0100.00313.82
5.6.40.0070.00714.07
5.6.30.0000.01614.08
5.6.20.0120.00414.00
5.6.10.0070.00714.12
5.6.00.0080.00413.90

preferences:
72.98 ms | 401 KiB | 5 Q