3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Ajgl\Csv; class SplFileObject extends \SplFileObject { use CsvFileObjectTrait; public function __construct($filename, $open_mode='r', $use_include_path=false, $context=null) { parent::__construct($filename, $open_mode, $use_include_path, $context); $this->fixCsvControl(); } } class SplTempFileObject extends \SplTempFileObject { use CsvFileObjectTrait; public function __construct ($max_memory=null) { parent::__construct($max_memory); $this->fixCsvControl(); } } trait CsvFileObjectTrait { protected function fixCsvControl() { list($delimiter, $enclosure) = $this->getCsvControl(); $this->setCsvControl($delimiter, $enclosure); } protected function checkEscapeChar($enclosure, $escape) { check_csv_escape($enclosure, $escape); } public function fgetcsv($delimiter=",", $enclosure='"', $escape='"') { $this->checkEscapeChar($enclosure, $escape); return parent::fgetcsv($delimiter, $enclosure, $enclosure); } public function fputcsv($fields, $delimiter=',', $enclosure='"', $escape='"') { $this->checkEscapeChar($enclosure, $escape); $this->fwrite(str_putcsv_rfc($fields, $delimiter, $enclosure)); } public function setCsvControl($delimiter=",", $enclosure='"', $escape='"') { $this->checkEscapeChar($enclosure, $escape); parent::setCsvControl($delimiter, $enclosure, $enclosure); } } function fputcsv($handle, $fields, $delimiter=',', $enclosure='"', $escape='"') { check_csv_escape($enclosure, $escape); \fwrite($handle, str_putcsv_rfc($fields, $delimiter, $enclosure)); } function fgetcsv($handle, $length=0, $delimiter=",", $enclosure='"', $escape='"') { check_csv_escape($enclosure, $escape); return \fgetcsv($handle, $length, $delimiter, $enclosure, $enclosure); } function str_getcsv($input, $delimiter=",", $enclosure='"', $escape='"') { check_csv_escape($enclosure, $escape); return \str_getcsv($input, $delimiter, $enclosure, $enclosure); } function str_putcsv($fields, $delimiter=",", $enclosure='"') { $file = new \SplTempFileObject(); $file->fputcsv($fields, $delimiter, $enclosure); $file->rewind(); $line = ''; while (!$file->eof()) { $line .= $file->fgets(); } return \str_replace('\\'.$enclosure, '\\'.$enclosure.$enclosure, $line); } function check_csv_escape($enclosure, $escape) { if ($enclosure !== $escape) { trigger_error( sprintf( "The 'escape' and 'enclosure' chars must be equals. The given 'escape' char '%s' will be ignored.", $escape ), E_USER_WARNING ); } } $a = new SplTempFileObject(); $a->fputcsv(array('Hello \"World"!')); $a->rewind(); var_dump($a->fread(4096));

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.4.120.0040.00620.67
8.4.110.0110.00922.44
8.4.100.0050.00517.75
8.4.90.0080.01120.49
8.4.80.0130.00717.91
8.4.70.0090.01017.83
8.4.60.0050.01118.85
8.4.50.0120.00919.65
8.4.40.0130.00719.45
8.4.30.0100.00319.70
8.4.20.0130.00717.86
8.4.10.0100.00617.48
8.3.250.0140.00518.74
8.3.240.0120.01016.87
8.3.230.0120.00716.57
8.3.220.0120.00717.07
8.3.210.0070.01216.79
8.3.200.0040.00516.73
8.3.190.0050.00317.07
8.3.180.0050.00616.66
8.3.170.0090.00918.88
8.3.160.0080.00018.68
8.3.150.0110.00720.57
8.3.140.0000.00816.74
8.3.130.0080.00016.98
8.3.120.0090.00619.04
8.3.110.0040.00420.94
8.3.100.0060.00324.06
8.3.90.0030.00626.77
8.3.80.0060.00317.97
8.3.70.0150.00316.75
8.3.60.0070.00718.68
8.3.50.0050.01122.06
8.3.40.0040.01118.63
8.3.30.0120.00918.51
8.3.20.0040.00420.21
8.3.10.0080.00020.49
8.3.00.0040.00420.56
8.2.290.0120.00720.48
8.2.280.0060.01318.51
8.2.270.0130.00618.90
8.2.260.0070.01118.51
8.2.250.0090.00918.33
8.2.240.0030.00619.03
8.2.230.0080.00022.58
8.2.220.0070.00337.54
8.2.210.0080.00026.77
8.2.200.0030.00618.16
8.2.190.0060.00918.54
8.2.180.0110.00716.63
8.2.170.0120.00622.96
8.2.160.0070.00720.38
8.2.150.0040.00424.18
8.2.140.0050.00324.66
8.2.130.0040.00419.24
8.2.120.0040.00426.35
8.2.110.0090.00019.18
8.2.100.0030.00917.50
8.2.90.0080.00019.18
8.2.80.0030.00517.97
8.2.70.0050.00517.38
8.2.60.0080.00017.91
8.2.50.0040.00418.09
8.2.40.0060.00320.46
8.2.30.0070.00019.47
8.2.20.0050.00317.76
8.2.10.0040.00418.14
8.2.00.0040.00418.13
8.1.330.0050.00422.11
8.1.320.0120.00915.78
8.1.310.0040.00418.52
8.1.300.0070.00415.91
8.1.290.0100.00030.84
8.1.280.0120.00325.92
8.1.270.0080.00024.02
8.1.260.0040.00428.09
8.1.250.0040.00428.09
8.1.240.0140.00323.92
8.1.230.0060.00617.43
8.1.220.0000.00817.74
8.1.210.0090.00018.77
8.1.200.0030.00617.10
8.1.190.0040.00716.98
8.1.180.0050.00318.10
8.1.170.0040.00418.51
8.1.160.0030.00420.85
8.1.150.0000.00718.86
8.1.140.0040.00419.52
8.1.130.0000.00717.66
8.1.120.0040.00417.47
8.1.110.0040.00417.39
8.1.100.0040.00417.43
8.1.90.0030.00517.48
8.1.80.0000.00717.49
8.1.70.0050.00217.43
8.1.60.0000.00817.46
8.1.50.0030.00617.44
8.1.40.0000.00817.50
8.1.30.0040.00417.71
8.1.20.0000.00817.50
8.1.10.0040.00417.38
8.1.00.0040.00417.41
8.0.300.0070.00018.77
8.0.290.0040.00416.88
8.0.280.0000.00718.41
8.0.270.0020.00517.24
8.0.260.0070.00320.18
8.0.250.0070.00017.13
8.0.240.0070.00017.03
8.0.230.0030.00416.98
8.0.220.0070.00016.99
8.0.210.0040.00416.96
8.0.200.0030.00317.11
8.0.190.0000.00816.95
8.0.180.0000.00817.03
8.0.170.0040.00417.09
8.0.160.0050.00317.04
8.0.150.0040.00416.93
8.0.140.0000.00716.84
8.0.130.0000.00613.48
8.0.120.0000.00816.97
8.0.110.0040.00416.97
8.0.100.0040.00416.87
8.0.90.0040.00417.00
8.0.80.0060.00917.05
8.0.70.0020.00516.87
8.0.60.0000.00816.88
8.0.50.0000.00716.83
8.0.30.0180.00317.13
8.0.20.0120.01517.40
8.0.10.0060.00317.19
8.0.00.0090.00816.94
7.4.330.0020.00216.67
7.4.320.0030.00316.66
7.4.300.0000.00616.57
7.4.290.0050.00316.64
7.4.280.0110.00016.67
7.4.270.0030.00516.61
7.4.260.0000.00716.49
7.4.250.0000.00716.63
7.4.240.0000.00716.48
7.4.230.0080.00016.74
7.4.220.0130.00316.59
7.4.210.0060.00916.69
7.4.200.0050.00216.75
7.4.160.0040.01116.39
7.4.150.0070.01417.40
7.4.140.0130.00517.86
7.4.130.0110.00616.61
7.4.120.0140.00416.59
7.4.110.0090.00916.40
7.4.100.0070.01116.43
7.4.90.0150.00916.74
7.4.80.0150.00919.39
7.4.70.0030.01216.75
7.4.60.0130.01016.64
7.4.50.0070.00716.20
7.4.40.0070.01016.57
7.4.30.0120.00616.58
7.4.10.0070.01114.79
7.4.00.0070.00915.04
7.3.330.0000.00713.32
7.3.320.0030.00513.48
7.3.310.0000.00716.52
7.3.300.0000.00716.51
7.3.290.0080.01016.52
7.3.280.0050.01216.44
7.3.270.0170.01017.40
7.3.260.0070.01016.68
7.3.250.0100.00816.61
7.3.240.0100.01216.44
7.3.230.0170.00316.50
7.3.210.0100.00716.50
7.3.200.0140.00719.39
7.3.190.0110.00816.48
7.3.180.0130.00316.49
7.3.170.0120.00916.77
7.3.160.0130.00316.73
7.3.130.0110.00715.18
7.3.120.0110.00715.00
7.3.110.0030.01315.09
7.3.100.0070.00715.05
7.3.90.0150.00314.99
7.3.80.0110.00715.04
7.3.70.0060.00614.78
7.3.60.0070.00714.84
7.3.50.0030.00814.82
7.3.40.0030.01015.01
7.3.30.0070.00415.08
7.3.20.0060.00316.82
7.3.10.0070.00716.46
7.3.00.0000.01116.67
7.2.330.0060.01216.65
7.2.320.0150.00716.70
7.2.310.0070.01116.67
7.2.300.0030.01416.71
7.2.290.0090.00916.52
7.2.260.0030.01414.96
7.2.250.0030.01614.68
7.2.240.0030.01314.79
7.2.230.0000.01715.14
7.2.220.0000.01615.36
7.2.210.0090.00915.25
7.2.200.0070.01014.87
7.2.190.0060.00615.21
7.2.180.0080.00615.10
7.2.170.0030.01014.80
7.2.160.0030.01015.03
7.2.150.0050.00516.77
7.2.140.0120.00016.98
7.2.130.0030.00716.75
7.2.120.0100.00316.71
7.2.110.0060.01216.61
7.2.100.0000.01116.86
7.2.90.0110.00416.81
7.2.80.0070.00716.82
7.2.70.0070.00716.85
7.2.60.0020.01016.85
7.2.50.0090.00616.94
7.2.40.0070.00716.70
7.2.30.0110.00416.76
7.2.20.0060.00916.80
7.2.10.0030.00917.05
7.2.00.0030.01316.97
7.1.330.0100.00315.84
7.1.320.0100.00715.66
7.1.310.0000.01415.70
7.1.300.0030.01015.57
7.1.290.0000.01215.74
7.1.280.0000.00815.81
7.1.270.0070.00715.82
7.1.260.0100.00315.82
7.1.250.0070.00315.88
7.1.240.0110.00315.61
7.1.230.0000.01315.87
7.1.220.0040.00415.84
7.1.210.0070.00415.88
7.1.200.0060.00615.63
7.1.190.0090.00615.82
7.1.180.0030.00915.68
7.1.170.0040.00715.73
7.1.160.0070.00715.84
7.1.150.0000.01115.99
7.1.140.0110.00015.51
7.1.130.0080.00615.79
7.1.120.0040.01115.65
7.1.110.0000.01415.86
7.1.100.0110.00415.85
7.1.90.0130.00015.97
7.1.80.0060.00915.47
7.1.70.0050.00716.38
7.1.60.0050.01017.60
7.1.50.0100.00816.30
7.1.40.0030.01315.87
7.1.30.0030.01015.80
7.1.20.0030.01015.48
7.1.10.0100.00715.91
7.1.00.0030.04319.19
7.0.330.0060.00315.25
7.0.320.0060.00315.25
7.0.310.0140.00315.14
7.0.300.0120.00615.51
7.0.290.0060.00915.42
7.0.280.0040.00815.10
7.0.270.0000.00915.09
7.0.260.0030.00715.33
7.0.250.0060.00315.38
7.0.240.0080.00615.19
7.0.230.0000.01315.50
7.0.220.0060.01015.50
7.0.210.0030.01015.49
7.0.200.0050.00616.13
7.0.190.0060.00315.55
7.0.180.0060.00615.26
7.0.170.0060.00615.54
7.0.160.0030.01015.14
7.0.150.0000.01415.32
7.0.140.0110.00315.45
7.0.130.0030.00915.39
7.0.120.0090.00615.14
7.0.110.0030.00615.50
7.0.100.0100.00315.54
7.0.90.0030.01015.09
7.0.80.0070.01115.03
7.0.70.0090.00415.13
7.0.60.0120.03417.70
7.0.50.0040.02716.77
7.0.40.0130.04116.85
7.0.30.0160.02116.75
7.0.20.0190.03816.77
7.0.10.0070.02616.91
7.0.00.0070.04316.86
5.6.400.0090.00014.57
5.6.390.0030.00914.42
5.6.380.0040.01114.28
5.6.370.0060.01014.53
5.6.360.0070.01014.58
5.6.350.0110.00414.29
5.6.340.0070.00314.60
5.6.330.0070.01014.61
5.6.320.0060.00614.85
5.6.310.0070.00714.28
5.6.300.0130.00313.98
5.6.290.0030.01514.53
5.6.280.0030.04417.61
5.6.270.0100.00314.56
5.6.260.0090.00614.36
5.6.250.0060.00614.52
5.6.240.0030.01314.30
5.6.230.0060.00614.19
5.6.220.0030.00814.38
5.6.210.0080.02117.58
5.6.200.0070.04116.33
5.6.190.0030.04117.36
5.6.180.0000.02917.49
5.6.170.0200.04217.39
5.6.160.0080.04217.54
5.6.150.0080.04516.28
5.6.140.0150.03816.27
5.6.130.0060.04316.39
5.6.120.0100.04217.74
5.6.110.0110.04217.65
5.6.100.0100.04017.76
5.6.90.0100.03817.80
5.6.80.0080.04317.51
5.6.70.0110.00314.25
5.6.60.0070.00314.55
5.6.50.0060.00914.57
5.6.40.0120.00014.50
5.6.30.0090.00314.48
5.6.20.0070.01014.41
5.6.10.0100.00314.46
5.6.00.0040.01114.25
5.5.380.0080.00414.13
5.5.370.0060.00614.16
5.5.360.0110.00314.15
5.5.350.1780.02617.47
5.5.340.0050.04716.16
5.5.330.0080.02717.41
5.5.320.0170.04317.29
5.5.310.0190.03817.31
5.5.300.0100.04116.29
5.5.290.0020.05016.12
5.5.280.0070.03517.64
5.5.270.0080.04217.39
5.5.260.0160.03017.52
5.5.250.0070.04517.54
5.5.240.0100.04317.34
5.5.230.0090.00614.32
5.5.220.0110.00414.39
5.5.210.0040.01113.92
5.5.200.0120.00013.98
5.5.190.0080.00314.31
5.5.180.0100.00013.85
5.5.170.0030.00913.91
5.5.160.0070.01014.48
5.5.150.0060.00914.20
5.5.140.0060.00614.43
5.5.130.0000.01614.40
5.5.120.0070.00714.15
5.5.110.0090.00614.39
5.5.100.0040.00814.06
5.5.90.0030.00914.29
5.5.80.0060.00314.38
5.5.70.0090.00314.34
5.5.60.0070.00714.11
5.5.50.0090.00614.56
5.5.40.0060.00614.45
5.5.30.0000.01313.82
5.5.20.0030.00614.48
5.5.10.0030.00514.11
5.5.00.0030.00714.10

preferences:
119.54 ms | 403 KiB | 5 Q