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