-
- Notifications
You must be signed in to change notification settings - Fork 344
Expand file tree
/
Copy pathReaderBench.php
More file actions
50 lines (39 loc) · 1.3 KB
/
ReaderBench.php
File metadata and controls
50 lines (39 loc) · 1.3 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* League.Csv (https://csv.thephpleague.com)
*
* (c) Ignace Nyamagana Butera <nyamsprod@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace League\Csv;
use PhpBench\Attributes as Bench;
use SplFileObject;
use function assert;
final class ReaderBench
{
#[Bench\OutputTimeUnit('seconds')]
#[Bench\Assert('mode(variant.mem.peak) < 2097152'), Bench\Assert('mode(variant.time.avg) < 10000000')]
public function benchReading1MRowsCSVUsingSplFileObject(): void
{
$path = dirname(__DIR__).'/test_files/csv_with_one_million_rows.csv';
$numReadRows = 0;
foreach (Reader::from(new SplFileObject($path)) as $__) {
++$numReadRows;
}
assert(1_000_000 === $numReadRows);
}
#[Bench\OutputTimeUnit('seconds')]
#[Bench\Assert('mode(variant.mem.peak) < 2097152'), Bench\Assert('mode(variant.time.avg) < 10000000')]
public function benchReading1MRowsCSVUsingStream(): void
{
$path = dirname(__DIR__).'/test_files/csv_with_one_million_rows.csv';
$numReadRows = 0;
foreach (Reader::from($path) as $__) {
++$numReadRows;
}
assert(1_000_000 === $numReadRows);
}
}