thephpleague / csv

CSV data manipulation made easy in PHP
https://csv.thephpleague.com
MIT License
3.32k stars 333 forks source link

CPU usage scaling with file-size #114

Closed ryzr closed 9 years ago

ryzr commented 9 years ago

Given the following code:

ini_set("auto_detect_line_endings", '1');

$reader = \League\Csv\Reader::createFromPath(public_path($csv->file), 'r')
    ->setDelimiter($csv->delimeter)
    ->setEnclosure($csv->enclosure)
    ->setEscape($csv->escape);

$data = $reader->query();

foreach ($data as $row_num => $row) {
    //do nothing
}

Memory consumption is fine, achieving everything perfectly. However I see a higher CPU usage when using larger files. In a local environment:

38.8kb CSV -> Apache process reaches ~9% CPU 5.86MB CSV -> Apache process reaches ~45% CPU

Just wanting to know:

ryzr commented 9 years ago

Worth noting, adding a micro sleep in the loop usleep(100); normalized CPU usage to around 10%, for many different sized CSVs. The higher the sleep interval, the lesser the CPU usage.

nyamsprod commented 9 years ago

Hi @ryzr sorry But I fail to reproduce this behavior on my personal laptop or on a remote server must be a configuration problem outside of the package scope