perf tests in development branch

This commit is contained in:
madflow authored and Adrien Loison committed 2019-03-24 22:53:28 +01:00
1 parent 171a2fab10
commit e8693834a0
12 files changed
+1000533 -11

No files matched your search

+62
View File
@@ -0,0 +1,62 @@
<?php
namespace Box\Spout\Reader\CSV;
use Box\Spout\Common\Type;
use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
use Box\Spout\TestUsingResource;
use PHPUnit\Framework\TestCase;
/**
* Class ReaderPerfTest
* Performance tests for CSV Reader
*/
class ReaderPerfTest extends TestCase
{
use TestUsingResource;
/**
* 1 million rows (each row containing 3 cells) should be read
* in less than 1 minute and the execution should not require
* more than 1MB of memory
*
* @group perf-tests
*
* @return void
*/
public function testPerfWhenReadingOneMillionRowsCSV()
{
// getting current memory peak to avoid taking into account the memory used by PHPUnit
$beforeMemoryPeakUsage = memory_get_peak_usage(true);
$expectedMaxExecutionTime = 60; // 1 minute in seconds
$expectedMaxMemoryPeakUsage = 1 * 1024 * 1024; // 1MB in bytes
$startTime = time();
$fileName = 'csv_with_one_million_rows.csv';
$resourcePath = $this->getResourcePath($fileName);
$reader = ReaderEntityFactory::createReader(Type::CSV);
$reader->open($resourcePath);
$numReadRows = 0;
/** @var Sheet $sheet */
foreach ($reader->getSheetIterator() as $sheet) {
foreach ($sheet->getRowIterator() as $row) {
$numReadRows++;
}
}
$reader->close();
$expectedNumRows = 1000000;
$this->assertEquals($expectedNumRows, $numReadRows, "$expectedNumRows rows should have been read");
$executionTime = time() - $startTime;
$this->assertTrue($executionTime < $expectedMaxExecutionTime, "Reading 1 million rows should take less than $expectedMaxExecutionTime seconds (took $executionTime seconds)");
$memoryPeakUsage = memory_get_peak_usage(true) - $beforeMemoryPeakUsage;
$this->assertTrue($memoryPeakUsage < $expectedMaxMemoryPeakUsage, 'Reading 1 million rows should require less than ' . ($expectedMaxMemoryPeakUsage / 1024 / 1024) . ' MB of memory (required ' . round($memoryPeakUsage / 1024 / 1024, 2) . ' MB)');
}
}
+62
View File
@@ -0,0 +1,62 @@
<?php
namespace Box\Spout\Reader\ODS;
use Box\Spout\Common\Type;
use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
use Box\Spout\TestUsingResource;
use PHPUnit\Framework\TestCase;
/**
* Class ReaderPerfTest
* Performance tests for ODS Reader
*/
class ReaderPerfTest extends Testcase
{
use TestUsingResource;
/**
* 1 million rows (each row containing 3 cells) should be read
* in less than 10 minutes and the execution should not require
* more than 1MB of memory
*
* @group perf-tests
*
* @return void
*/
public function testPerfWhenReadingOneMillionRowsODS()
{
// getting current memory peak to avoid taking into account the memory used by PHPUnit
$beforeMemoryPeakUsage = memory_get_peak_usage(true);
$expectedMaxExecutionTime = 600; // 10 minutes in seconds
$expectedMaxMemoryPeakUsage = 1 * 1024 * 1024; // 1MB in bytes
$startTime = time();
$fileName = 'ods_with_one_million_rows.ods';
$resourcePath = $this->getResourcePath($fileName);
$reader = ReaderEntityFactory::createReader(Type::ODS);
$reader->open($resourcePath);
$numReadRows = 0;
/** @var Sheet $sheet */
foreach ($reader->getSheetIterator() as $sheet) {
foreach ($sheet->getRowIterator() as $row) {
$numReadRows++;
}
}
$reader->close();
$expectedNumRows = 1000000;
$this->assertEquals($expectedNumRows, $numReadRows, "$expectedNumRows rows should have been read");
$executionTime = time() - $startTime;
$this->assertTrue($executionTime < $expectedMaxExecutionTime, "Reading 1 million rows should take less than $expectedMaxExecutionTime seconds (took $executionTime seconds)");
$memoryPeakUsage = memory_get_peak_usage(true) - $beforeMemoryPeakUsage;
$this->assertTrue($memoryPeakUsage < $expectedMaxMemoryPeakUsage, 'Reading 1 million rows should require less than ' . ($expectedMaxMemoryPeakUsage / 1024 / 1024) . ' MB of memory (required ' . round($memoryPeakUsage / 1024 / 1024, 2) . ' MB)');
}
}
@@ -0,0 +1,76 @@
<?php
namespace Box\Spout\Reader\XLSX;
use Box\Spout\Common\Type;
use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
use Box\Spout\TestUsingResource;
use PHPUnit\Framework\TestCase;
/**
* Class ReaderPerfTest
* Performance tests for XLSX Reader
*/
class ReaderPerfTest extends TestCase
{
use TestUsingResource;
/**
* @return array
*/
public function dataProviderForTestPerfWhenReading300kRowsXLSX()
{
return [
[$shouldUseInlineStrings = true, $expectedMaxExecutionTime = 390], // 6.5 minutes in seconds
[$shouldUseInlineStrings = false, $expectedMaxExecutionTime = 600], // 10 minutes in seconds
];
}
/**
* 300,000 rows (each row containing 3 cells) should be read
* in less than 6.5 minutes for inline strings, 10 minutes for
* shared strings and the execution should not require
* more than 3MB of memory.
*
* @dataProvider dataProviderForTestPerfWhenReading300kRowsXLSX
* @group perf-tests
*
* @param bool $shouldUseInlineStrings
* @param int $expectedMaxExecutionTime
* @return void
*/
public function testPerfWhenReading300kRowsXLSX($shouldUseInlineStrings, $expectedMaxExecutionTime)
{
// getting current memory peak to avoid taking into account the memory used by PHPUnit
$beforeMemoryPeakUsage = memory_get_peak_usage(true);
$expectedMaxMemoryPeakUsage = 3 * 1024 * 1024;
$startTime = time();
$fileName = ($shouldUseInlineStrings) ? 'xlsx_with_300k_rows_and_inline_strings.xlsx' : 'xlsx_with_300k_rows_and_shared_strings.xlsx';
$resourcePath = $this->getResourcePath($fileName);
$reader = ReaderEntityFactory::createReader(Type::XLSX);
$reader->open($resourcePath);
$numReadRows = 0;
/** @var Sheet $sheet */
foreach ($reader->getSheetIterator() as $sheet) {
foreach ($sheet->getRowIterator() as $row) {
$numReadRows++;
}
}
$reader->close();
$expectedNumRows = 300000;
$this->assertEquals($expectedNumRows, $numReadRows, "$expectedNumRows rows should have been read");
$executionTime = time() - $startTime;
$this->assertTrue($executionTime < $expectedMaxExecutionTime, "Reading 300,000 rows should take less than $expectedMaxExecutionTime seconds (took $executionTime seconds)");
$memoryPeakUsage = memory_get_peak_usage(true) - $beforeMemoryPeakUsage;
$this->assertTrue($memoryPeakUsage < $expectedMaxMemoryPeakUsage, 'Reading 300,000 rows should require less than ' . ($expectedMaxMemoryPeakUsage / 1024 / 1024) . ' MB of memory (required ' . ($memoryPeakUsage / 1024 / 1024) . ' MB)');
}
}