Skip to content

Instantly share code, notes, and snippets.

@nyamsprod
Created January 28, 2015 14:09
Show Gist options
  • Select an option

  • Save nyamsprod/554deb252fb2835a4a9a to your computer and use it in GitHub Desktop.

Select an option

Save nyamsprod/554deb252fb2835a4a9a to your computer and use it in GitHub Desktop.
Benchmark for league Csv 6.4+
use League\Csv\Writer;
function generateRawData($start, $end)
{
for ($i = $start; $i < $end; $i++) {
$index = $i;
yield [
'cell--'.($index),
'cell--'.($index+1),
'cell--'.($index+2),
];
}
}
$start = microtime(true);
$nbrows = 200000;
$csv = Writer::createFromPath('result.csv', 'w'); //to work make sure you have the write permission
$csv->useValidation(false); //disable row validation
$csv->insertAll(generateRawData(0, $nbrows));
$duration = microtime(true) - $start;
$memory = memory_get_peak_usage(true);
echo 'adding '. $nbrows, ' rows in ', $duration, ' seconds using ', $memory, ' bytes', PHP_EOL;
die(0);
@nyamsprod
Copy link
Copy Markdown
Author

By disabling the content validation. we gain a major boost.

For 200000 rows:

  • with validation it tooks 16.26s
  • without validation it tooks 3.9s

Set up
PHP 5.5.9-1ubuntu4.5 (cli) (built: Oct 29 2014 11:59:42)
model name : Intel(R) Core(TM)2 Duo CPU E7200 @ 2.53GHz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment