3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Class FyndiqCSVFeedWriter generates CSV export feed */ class FyndiqCSVFeedWriter { { /** * @var array export column names */ private $header = array(); /** * @var array products for export */ private $products = array(); /** * @var array fields upon which `addslashes` will be applied */ private $slashFields = array( 'article-name', 'product-brand', 'product-title', 'product-description', ); /** * Apply field transformations * * @param array $product * @return array mixed */ private function processProduct($product) { foreach($this->slashFields as $field) { if (!empty($product[$field])) { $product[$field] = addslashes($product[$field]); } } return $product; } /** * Add product to the feed * * @param $product * @return bool */ public function addProduct($product) { if ($this->isValidProduct($product)) { $this->header = array_unique(array_merge($this->header, array_keys($product))); $this->products[] = $this->processProduct($product); return true; } return false; } /** * Flush the feed data to the stream * * @return bool */ public function write() { // Write header if (fputcsv($this->stream, $this->header) === false) { return false; } // Write data foreach ($this->products as $product) { $finalProduct = array(); foreach ($this->header as $column) { $finalProduct[] = isset($product[$column]) ? $product[$column] : ''; } if (fputcsv($this->stream, $finalProduct) === false) { return false; } } unset($this->header); unset($this->products); return true; } }

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)
5.6.80.0070.07720.32
5.5.240.0000.05320.04
5.4.400.0400.06718.77
5.4.390.0370.05718.84
5.4.380.0330.07018.79
5.4.370.0400.05718.75
5.4.360.0570.05018.72
5.4.350.0470.05018.50
5.4.340.0430.06018.59
5.4.320.0430.05718.59
5.4.310.0400.05718.89
5.4.300.0430.05318.69
5.4.290.0370.05018.69
5.4.280.0430.06318.76
5.4.270.0470.07318.52
5.4.260.0470.07018.68
5.4.250.0400.05718.52
5.4.240.0400.06318.80
5.4.230.0430.04718.74
5.4.220.0400.08718.68
5.4.210.0270.07018.50
5.4.200.0370.05016.80
5.4.190.0270.06318.82
5.4.180.0430.06318.79
5.4.170.0470.06718.76
5.4.160.0500.07318.48
5.4.150.0330.06718.83
5.4.140.0500.06316.33
5.4.130.0530.06316.44
5.4.120.0370.04716.29
5.4.110.0300.05016.32
5.4.100.0270.06316.29
5.4.90.0470.06716.32
5.4.80.0400.05716.26
5.4.70.0370.06716.42
5.4.60.0600.05716.40
5.4.50.0430.05016.25
5.4.40.0330.05316.20
5.4.30.0330.05016.28
5.4.20.0370.05716.21
5.4.10.0370.05716.29
5.4.00.0370.06715.69
5.3.290.0370.05714.88
5.3.280.0430.05714.81
5.3.270.0700.05014.63
5.3.260.0430.05014.73
5.3.250.0430.04714.64
5.3.240.0400.05714.70
5.3.230.0370.05014.61
5.3.220.0270.05714.62
5.3.210.0300.06014.62
5.3.200.0570.06014.55
5.3.190.0400.07014.56
5.3.180.0300.06014.67
5.3.170.0430.06014.72
5.3.160.0500.05714.68
5.3.150.0530.05314.66
5.3.140.0530.05714.68
5.3.130.0570.07014.73
5.3.120.0370.07314.70
5.3.110.0530.06314.52
5.3.100.0400.05714.07
5.3.90.0370.05314.03
5.3.80.0500.04014.05
5.3.70.0430.06714.09
5.3.60.0430.06014.20
5.3.50.0300.05714.00
5.3.40.0470.04713.98
5.3.30.0300.05714.00
5.3.20.0470.05013.68
5.3.10.0700.05313.76
5.3.00.0430.06713.69
5.2.170.0300.06011.17
5.2.160.0370.05711.36
5.2.150.0300.05311.34
5.2.140.0430.05011.34
5.2.130.0430.04711.14
5.2.120.0330.05011.09
5.2.110.0330.05011.13
5.2.100.0170.04711.21
5.2.90.0230.04311.09
5.2.80.0170.05311.29
5.2.70.0270.04011.12
5.2.60.0200.04311.08
5.2.50.0270.04711.09
5.2.40.0200.04311.11
5.2.30.0200.05011.17
5.2.20.0200.04711.14
5.2.10.0200.04310.91
5.2.00.0130.04310.82
5.1.60.0230.03310.12
5.1.50.0270.03710.12
5.1.40.0270.03310.16
5.1.30.0230.04310.35
5.1.20.0200.04310.36
5.1.10.0170.04010.15
5.1.00.0170.04710.20
5.0.50.0070.0378.54
5.0.40.0130.0308.45
5.0.30.0170.0608.34
5.0.20.0070.0438.33
5.0.10.0130.0378.17
5.0.00.0230.0438.27
4.4.90.0200.0205.91
4.4.80.0130.0275.93
4.4.70.0130.0275.88
4.4.60.0170.0205.93
4.4.50.0200.0136.00
4.4.40.0130.0375.88
4.4.30.0130.0205.93
4.4.20.0070.0275.94
4.4.10.0100.0235.93
4.4.00.0130.0335.91
4.3.110.0030.0335.80
4.3.100.0130.0235.95
4.3.90.0100.0235.82
4.3.80.0100.0375.78
4.3.70.0170.0175.87
4.3.60.0070.0235.79
4.3.50.0100.0235.80
4.3.40.0100.0375.75
4.3.30.0030.0234.68
4.3.20.0030.0234.56
4.3.10.0100.0204.61
4.3.00.0130.0206.88

preferences:
142.39 ms | 1394 KiB | 7 Q