3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace FlatFileParser; $definitions = [ ['name' => 'Serial Number', 'length' => 16, 'type' => 'int'], ['name' => 'Language', 'length' => 3, 'type' => 'string'], ['name' => 'Business Name', 'length' => 32, 'type' => 'string'], ['name' => 'Business Code', 'length' => 8, 'type' => 'string'], ['name' => 'Authorization Code', 'length' => 8, 'type' => 'string'], ['name' => 'Timestamp', 'length' => 20, 'type' => 'timestamp'], ]; $writer = new Writer(); $validator = new Validator(); $parser = new Parser(); if(count($argv) != 2){ $writer->write("ERROR: No flat file provided"); } try{ $data = new SplFileObject($argv[1]); if ($data->isFile() && $data->isReadable()) { $lineNumber = 1; while (!$file->eof()) { $line = $file->fgets(); if($validator->isValidLineLength($line)){ $business = convertLineToBusiness($line); $writer->writeBusiness($business); } else{ $writer->write("Line Number: " + $lineNumber + "ERROR: Line to Long"); } $lineNumber ++; } } else{ $writer->write("ERROR: Flat file not readable"); } } catch(Exception $e){ echo "err"; } class Writer{ public function write($text){ echo $text . "\n"; } public function writeBusiness($lineNumber, $business){ write("Line Number: " + $lineNumber); write("Serial Number: " + $business->serialNumber); write("Language: " + $business->language); write("Business Name: " + $business->businessName); write("Business Code: " + $business->businessCode); write("Authorization Code: " + $business->get(authorizationCode)); write("Timestamp: " + $business->timestamp); } } class Validator{ private $validLineLength; public function isValidLineLength($line){ return strlen($line) < $this->validLineLength; } function Validator(){ $this->validLineLength = 0; foreach($definitions as $definition){ $this->validLineLength += $definition->length; } } } class Parser{ public function convertLineToBusiness($line){ $start = 0; $parms = []; foreach($definitions as $definition){ array_push($parms, substr($line, $start, $definition->length)); $start += $definition->length; } return new Business($parms); } } class Business{ public $serialNumber; public $language; public $businessName; public $businessCode; private $authorizationCode; public $timestamp; /** * Getter for some private attributes * @return mixed $attribute */ public function __get($attribute){ if (isset($this->{"_".$attribute})){ return $this->{"_".$attribute}; } else{ return false; } } public function Business($parms){ $this->serialNumber = $parms[1]; $this->language = $parms[2]; $this->businessName = $parms[3]; $this->businessCode = $parms[4]; $this->authorizationCode = $parms[5]; $this->timestamp = $parms[6]; } } ?>

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.0150.00018.68
8.3.50.0250.01521.07
8.3.40.0070.01118.93
8.3.30.0040.01118.61
8.3.20.0030.00520.39
8.3.10.0070.00021.76
8.3.00.0040.00417.93
8.2.180.0190.00316.50
8.2.170.0180.00322.96
8.2.160.0070.00720.45
8.2.150.0030.00624.18
8.2.140.0060.00324.66
8.2.130.0000.00726.16
8.2.120.0030.00517.75
8.2.110.0070.01620.92
8.2.100.0110.00019.19
8.2.90.0060.00319.04
8.2.80.0040.00417.97
8.2.70.0090.00017.75
8.2.60.0000.00818.01
8.2.50.0000.00818.07
8.2.40.0000.00819.40
8.2.30.0000.00820.68
8.2.20.0050.00317.88
8.2.10.0050.00318.27
8.2.00.0070.00018.19
8.1.280.0160.00025.92
8.1.270.0040.01122.02
8.1.260.0000.00926.35
8.1.250.0040.00428.09
8.1.240.0000.01122.18
8.1.230.0060.00621.15
8.1.220.0030.00617.74
8.1.210.0040.00418.77
8.1.200.0030.00617.48
8.1.190.0040.00417.25
8.1.180.0030.00618.10
8.1.170.0040.00418.63
8.1.160.0000.00722.09
8.1.150.0050.00318.96
8.1.140.0080.00017.51
8.1.130.0000.00817.78
8.1.120.0000.00717.57
8.1.110.0060.00317.51
8.1.100.0080.00017.56
8.1.90.0030.00717.43
8.1.80.0000.00717.42
8.1.70.0000.00717.39
8.1.60.0060.00317.58
8.1.50.0040.00417.51
8.1.40.0000.01017.56
8.1.30.0030.00517.70
8.1.20.0000.00917.77
8.1.10.0000.00717.66
8.1.00.0030.00617.62
8.0.300.0000.00918.77
8.0.290.0070.00016.75
8.0.280.0040.00418.36
8.0.270.0030.00517.39
8.0.260.0000.00617.24
8.0.250.0050.00316.99
8.0.240.0000.00717.14
8.0.230.0030.00316.97
8.0.220.0000.00717.08
8.0.210.0000.00717.02
8.0.200.0070.00017.07
8.0.190.0060.00317.09
8.0.180.0000.00816.94
8.0.170.0040.00416.99
8.0.160.0060.00317.12
8.0.150.0070.00016.88
8.0.140.0000.00716.94
8.0.130.0000.00813.25
8.0.120.0040.00416.88
8.0.110.0060.00317.02
8.0.100.0030.00516.93
8.0.90.0000.00717.05
8.0.80.0060.00917.00
8.0.70.0050.00217.02
8.0.60.0070.00016.99
8.0.50.0040.00416.93
8.0.30.0090.00917.20
8.0.20.0130.00617.40
8.0.10.0020.00517.21
8.0.00.0100.00816.99
7.4.330.0000.00515.08
7.4.320.0060.00016.57
7.4.300.0070.00016.48
7.4.290.0000.00716.58
7.4.280.0000.01016.62
7.4.270.0030.00316.60
7.4.260.0000.00716.60
7.4.250.0000.00816.64
7.4.240.0040.00416.60
7.4.230.0000.00716.76
7.4.220.0060.01216.62
7.4.210.0070.00716.56
7.4.200.0000.00816.48
7.4.160.0100.00716.57
7.4.150.0100.01317.40
7.4.140.0180.00617.86
7.4.130.0080.01116.60
7.4.120.0060.01316.64
7.4.110.0100.01116.68
7.4.100.0070.01016.57
7.4.90.0060.01316.49
7.4.80.0140.00719.39
7.4.70.0070.01016.66
7.4.60.0100.00616.52
7.4.50.0040.00416.78
7.4.40.0000.01716.63
7.4.30.0100.01016.49
7.4.10.0060.01114.93
7.4.00.0060.00914.93
7.3.330.0030.00313.28
7.3.320.0030.00313.37
7.3.310.0070.00016.30
7.3.300.0030.00316.45
7.3.290.0100.00816.38
7.3.280.0080.00716.45
7.3.270.0110.00717.40
7.3.260.0120.00616.56
7.3.250.0120.00516.50
7.3.240.0080.00816.52
7.3.230.0160.00616.41
7.3.210.0100.00616.51
7.3.200.0030.01316.71
7.3.190.0060.00916.42
7.3.180.0130.00316.54
7.3.170.0120.00916.39
7.3.160.0100.01116.59
7.3.130.0080.01114.94
7.3.120.0080.00914.80
7.3.110.0080.00914.90
7.3.100.0040.01114.89
7.3.90.0050.00914.91
7.3.80.0030.00814.77
7.3.70.0080.00814.71
7.3.60.0040.00914.96
7.3.50.0070.00815.03
7.3.40.0080.00614.88
7.3.30.0040.00914.93
7.3.20.0100.00616.55
7.3.10.0070.00816.41
7.3.00.0060.00716.62
7.2.330.0110.00716.59
7.2.320.0120.00616.60
7.2.310.0070.01016.82
7.2.300.0130.00316.79
7.2.290.0100.01316.52
7.2.260.0030.01315.02
7.2.250.0070.01215.01
7.2.240.0050.01215.02
7.2.230.0070.00914.90
7.2.220.0080.00715.10
7.2.210.0060.01014.91
7.2.200.0090.00615.08
7.2.190.0070.00514.99
7.2.180.0080.00515.06
7.2.170.0070.00515.01
7.2.160.0030.01114.93
7.2.150.0080.00616.90
7.2.140.0120.00316.75
7.2.130.0060.00816.93
7.2.120.0050.00716.90
7.2.110.0050.00916.93
7.2.100.0050.01016.85
7.2.90.0070.00517.00
7.2.80.0080.00717.03
7.2.70.0060.00816.93
7.2.60.0070.00816.97
7.2.50.0050.00717.07
7.2.40.0050.01117.05
7.2.30.0070.00716.89
7.2.20.0060.01116.78
7.2.10.0080.00716.93
7.2.00.0040.00817.48
7.1.330.0090.00415.72
7.1.320.0040.00915.61
7.1.310.0050.01015.91
7.1.300.0080.00415.59
7.1.290.0050.00915.68
7.1.280.0020.01115.74
7.1.270.0060.00915.62
7.1.260.0070.00715.73
7.1.250.0040.01015.63
7.1.240.0050.00815.88
7.1.230.0050.01015.67
7.1.220.0080.00615.59
7.1.210.0080.00615.56
7.1.200.0050.00715.57
7.1.190.0050.00715.43
7.1.180.0050.00915.67
7.1.170.0060.00515.62
7.1.160.0050.01215.82
7.1.150.0050.00515.63
7.1.140.0070.00515.85
7.1.130.0040.00715.70
7.1.120.0060.00915.74
7.1.110.0080.00515.67
7.1.100.0010.01316.47
7.1.90.0000.01215.82
7.1.80.0070.00515.73
7.1.70.0060.00916.11
7.1.60.0020.01316.82
7.1.50.0090.00416.11
7.1.40.0030.01015.59
7.1.30.0080.00515.48
7.1.20.0050.00615.51
7.1.10.0040.01115.43
7.1.00.0080.02717.85
7.0.330.0060.00615.48
7.0.320.0060.00715.53
7.0.310.0050.00815.31
7.0.300.0080.00615.40
7.0.290.0070.00815.24
7.0.280.0030.01015.41
7.0.270.0030.01015.38
7.0.260.0010.00715.36
7.0.250.0050.00915.61
7.0.240.0050.00515.53
7.0.230.0050.00515.26
7.0.220.0030.01115.49
7.0.210.0060.00715.40
7.0.200.0040.00615.99
7.0.190.0030.00815.39
7.0.180.0020.01215.58
7.0.170.0050.00915.03
7.0.160.0050.00715.17
7.0.150.0060.00815.24
7.0.140.0060.00815.33
7.0.130.0060.00515.48
7.0.120.0050.00715.34
7.0.110.0040.00615.23
7.0.100.0010.01315.42
7.0.90.0050.01015.36
7.0.80.0030.00715.31
7.0.70.0000.01115.36
7.0.60.0070.02116.93
7.0.50.0040.02516.39
7.0.40.0050.02115.70
7.0.30.0150.03015.76
7.0.20.0140.03215.67
7.0.10.0060.03215.62
7.0.00.0070.03315.60
5.6.400.0030.00914.46
5.6.390.0080.00614.48
5.6.380.0030.01214.57
5.6.370.0020.01114.44
5.6.360.0050.01014.36
5.6.350.0050.00814.18
5.6.340.0050.00914.28
5.6.330.0030.01014.46
5.6.320.0030.00914.52
5.6.310.0070.00614.40
5.6.300.0070.00914.43
5.6.290.0090.00714.30
5.6.280.0080.02716.61
5.6.270.0060.00714.36
5.6.260.0070.00714.53
5.6.250.0070.00714.48
5.6.240.0050.00814.60
5.6.230.0060.00814.34
5.6.220.0050.01214.31
5.6.210.0090.03116.44
5.6.200.0080.01715.56
5.6.190.0100.02916.19
5.6.180.0230.02516.43
5.6.170.0160.02816.47
5.6.160.0030.02316.32
5.6.150.0030.03515.56
5.6.140.0100.02615.76
5.6.130.0040.01915.62
5.6.120.0060.03116.56
5.6.110.0060.03316.50
5.6.100.0020.03716.51
5.6.90.0040.02916.31
5.6.80.0010.02216.25
5.6.70.0030.01214.11
5.6.60.0020.01114.15
5.6.50.0060.00714.14
5.6.40.0090.00614.09
5.6.30.0120.00014.25
5.6.20.0050.00914.38
5.6.10.0060.00814.25
5.6.00.0050.00914.07
5.5.380.0050.00714.19
5.5.370.0050.00814.29
5.5.360.0000.01314.45
5.5.350.0110.02016.26
5.5.340.0080.02115.61
5.5.330.0050.02116.34
5.5.320.0030.03116.39
5.5.310.0140.01916.10
5.5.300.0030.02715.65
5.5.290.0070.02415.68
5.5.280.0060.01616.43
5.5.270.0060.02816.45
5.5.260.0100.03016.48
5.5.250.0090.02916.20
5.5.240.0060.03216.16
5.5.230.0050.01014.47
5.5.220.0040.00914.30
5.5.210.0040.01013.94
5.5.200.0060.00614.21
5.5.190.0050.00714.03
5.5.180.0070.00514.08
5.5.170.0070.00914.37
5.5.160.0020.00814.24
5.5.150.0080.00514.49
5.5.140.0050.00614.18
5.5.130.0100.00314.21
5.5.120.0030.00814.19
5.5.110.0030.01014.22
5.5.100.0020.01214.14
5.5.90.0080.00614.04
5.5.80.0030.00914.23
5.5.70.0060.00514.05
5.5.60.0050.00914.21
5.5.50.0060.00914.12
5.5.40.0030.01114.21
5.5.30.0070.00914.39
5.5.20.0090.00814.13
5.5.10.0070.00914.21
5.5.00.0060.00814.21
5.4.450.0220.02214.16
5.4.440.0240.02314.20
5.4.430.0250.02214.38
5.4.420.0280.02414.19
5.4.410.0280.02014.22
5.4.400.0240.02314.29
5.4.390.0210.02514.09
5.4.380.0220.02113.98
5.4.370.0250.02114.28
5.4.360.0210.02414.06
5.4.350.0250.02214.16
5.4.340.0220.02414.11
5.4.330.0010.00811.49
5.4.320.0240.02014.16
5.4.310.0290.01914.27
5.4.300.0220.02314.22
5.4.290.0290.02214.09
5.4.280.0310.02614.27
5.4.270.0310.02414.28
5.4.260.0270.02014.07
5.4.250.0210.02614.16
5.4.240.0280.02114.13
5.4.230.0200.02314.24
5.4.220.0240.02014.18
5.4.210.0230.02214.12
5.4.200.0280.02214.20
5.4.190.0300.02013.96
5.4.180.0230.02214.13
5.4.170.0290.02014.11
5.4.160.0230.02014.22
5.4.150.0250.02114.17
5.4.140.0210.02313.19
5.4.130.0250.01613.39
5.4.120.0280.02113.39
5.4.110.0220.02113.28
5.4.100.0270.02013.13
5.4.90.0250.02113.29
5.4.80.0300.02013.20
5.4.70.0130.02113.38
5.4.60.0130.01513.17
5.4.50.0120.01713.26
5.4.40.0070.01613.26
5.4.30.0120.02713.15
5.4.20.0100.02113.32
5.4.10.0080.01413.16
5.4.00.0020.00811.63

preferences:
46.1 ms | 401 KiB | 5 Q