summaryrefslogtreecommitdiffstats
path: root/examples/writer-benchmark.php
blob: 20e72894dee3bca17c4cf3c02bbce3955c77707a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php

//To work the benchmark need PHP5.5+ has it relies on PHP generator

use League\Csv\Writer;

require '../vendor/autoload.php';

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->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);