PerformanceTest::getFixtures()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of graze/csv-token
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/csv-token/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/csv-token
12
 */
13
14
namespace Graze\CsvToken\Test\Performance;
15
16
use Graze\CsvToken\Csv\CsvConfiguration;
17
use Graze\CsvToken\Parser;
18
use Graze\CsvToken\Test\TestCase;
19
use Graze\CsvToken\Tokeniser\StreamTokeniser;
20
21
class PerformanceTest extends TestCase
22
{
23
    /**
24
     * @dataProvider getFixtures
25
     *
26
     * @param string $path
27
     * @param int    $iterations
28
     */
29
    public function testPerformance($path, $iterations)
30
    {
31
        $runs = array_pad([], $iterations, -1);
32
33
        foreach ($runs as &$iteration) {
34
            $start = microtime(true);
35
            $parser = new Parser();
36
            $tokeniser = new StreamTokeniser(new CsvConfiguration(), fopen($path, 'r'));
37
            foreach ($parser->parse($tokeniser->getTokens()) as $row) {
38
                echo '';
39
            }
40
            $iteration = microtime(true) - $start;
41
        }
42
43
        $average = array_sum($runs) / count($runs);
44
45
        printf("\nPath: %s - iterations: %d - average: %.2f ms\n", $path, count($runs), $average * 1000);
46
    }
47
48
    /**
49
     * @return array
50
     */
51
    public function getFixtures()
52
    {
53
        return [
54
            [__DIR__ . '/fixture.csv', 20],
55
            [__DIR__ . '/big.csv', 5],
56
        ];
57
    }
58
}
59