Skip to content

Commit

Permalink
Add unit tests for the object writer plus a few benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
DASPRiD committed Dec 4, 2015
1 parent 4effa77 commit a586884
Show file tree
Hide file tree
Showing 11 changed files with 399 additions and 125 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ PDFs up to version 1.7.
## Documentation
You can find the latest documentation over at Read the Docs:
https://baconpdf.readthedocs.org/en/latest/

# Running benchmarks
When doing performance sensitive changes to core classes, make sure to run the benchmarks before and after making your
changes to ensure that they don't cause a huge impact:

```bash
php vendor/bin/athletic -p benchmark -b vendor/autoload.php
```
126 changes: 126 additions & 0 deletions benchmark/ObjectWriterEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php
/**
* BaconPdf
*
* @link http://github.com/Bacon/BaconPdf For the canonical source repository
* @copyright 2015 Ben Scholzen (DASPRiD)
* @license http://opensource.org/licenses/BSD-2-Clause Simplified BSD License
*/

namespace Bacon\PdfBenchmark;

use Athletic\AthleticEvent;
use Bacon\Pdf\Writer\ObjectWriter;
use SplFileObject;

class ObjectWriterEvent extends AthleticEvent
{
/**
* @var ObjectWriter
*/
private $objectWriter;

/**
* {@inheritdoc}
*/
public function setUp()
{
$this->objectWriter = new ObjectWriter(new SplFileObject('php://memory', 'w+'));
}

/**
* @iterations 10000
*/
public function writeRawLine()
{
$this->objectWriter->writeRawLine('foo');
}

/**
* @iterations 10000
*/
public function startDictionary()
{
$this->objectWriter->startDictionary();
}

/**
* @iterations 10000
*/
public function endDictionary()
{
$this->objectWriter->endDictionary();
}

/**
* @iterations 10000
*/
public function startArray()
{
$this->objectWriter->startArray();
}

/**
* @iterations 10000
*/
public function endArray()
{
$this->objectWriter->endArray();
}

/**
* @iterations 10000
*/
public function writeNull()
{
$this->objectWriter->writeNull();
}

/**
* @iterations 10000
*/
public function writeBoolean()
{
$this->objectWriter->writeBoolean(true);
}

/**
* @iterations 10000
*/
public function writeIntegerNumber()
{
$this->objectWriter->writeNumber(1);
}

/**
* @iterations 10000
*/
public function writeFloatNumber()
{
$this->objectWriter->writeNumber(1.1);
}

/**
* @iterations 10000
*/
public function writeName()
{
$this->objectWriter->writeName('foo');
}

/**
* @iterations 10000
*/
public function writeLiteralString()
{
$this->objectWriter->writeLiteralString('foo');
}

/**
* @iterations 10000
*/
public function writeHexadecimalString()
{
$this->objectWriter->writeHexadecimalString('foo');
}
}
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
},
"autoload-dev": {
"psr-4": {
"Bacon\\PdfBenchmark\\": "benchmark/",
"Bacon\\PdfTest\\": "test/"
}
},
"require-dev": {
"ext-openssl": "*",
"squizlabs/php_codesniffer": "^2.4",
"phpunit/phpunit": "^4.8|^5.0"
"phpunit/phpunit": "^4.8|^5.0",
"athletic/athletic": "^0.1.8"
},
"suggest": {
"ext-openssl": "Allows using the encryption features"
Expand Down

0 comments on commit a586884

Please sign in to comment.