Exemple #1
0
 /**
  * @dataProvider getFixtures
  *
  * @param string $path
  * @param int    $iterations
  */
 public function testPerformance($path, $iterations)
 {
     $runs = array_pad([], $iterations, -1);
     foreach ($runs as &$iteration) {
         $start = microtime(true);
         $parser = new Parser();
         $tokeniser = new StreamTokeniser(new CsvConfiguration(), fopen($path, 'r'));
         foreach ($parser->parse($tokeniser->getTokens()) as $row) {
             echo '';
         }
         $iteration = microtime(true) - $start;
     }
     $average = array_sum($runs) / count($runs);
     printf("\nPath: %s - iterations: %d - average: %.2f ms\n", $path, count($runs), $average * 1000);
 }
Exemple #2
0
 /**
  * StringTokeniser constructor.
  *
  * @param CsvConfigurationInterface $config
  * @param string                    $csv
  */
 public function __construct(CsvConfigurationInterface $config, $csv)
 {
     $stream = fopen('php://memory', 'r+');
     fwrite($stream, $csv);
     rewind($stream);
     parent::__construct($config, $stream);
 }
Exemple #3
0
 /**
  * @param resource $stream
  *
  * @return Iterator
  */
 public function parse($stream)
 {
     $tokeniser = new StreamTokeniser($this->csvFormat, $stream);
     $parser = new Parser();
     return $this->parseIterator($parser->parse($tokeniser->getTokens()));
 }
Exemple #4
0
 /**
  * @return Iterator Iterator of csv line arrays
  */
 public function read()
 {
     $tokens = new StreamTokeniser($this->config, $this->stream);
     $parser = new Parser();
     return $parser->parse($tokens->getTokens());
 }