Skip to content

Commit

Permalink
fix: Dependencies updated
Browse files Browse the repository at this point in the history
  • Loading branch information
patrykbaszak committed May 2, 2024
1 parent 8fb80bf commit 9e17ff7
Show file tree
Hide file tree
Showing 17 changed files with 1,112 additions and 1,056 deletions.
112 changes: 98 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,62 @@
# Dedicated Mapper (Bundle*) #
**I present to You the fastest PHP Dedicated Mapper ever created!**<br>
It's even **37** times faster than **JMS Serializer** and even **2500** times faster than **Symfony Serializer** in denormalization!<br>
It's even **31** times faster than **JMS Serializer** and even **43** times faster than **Symfony Serializer** in denormalization!<br>
<sub>*The package supports Symfony Bundle system but not require to be used with Symfony.</sub>

## Usage
```php
<?php

declare(strict_types=1);

namespace App;

use PBaszak\DedicatedMapper\Expression\Builder\ArrayExpressionBuilder as ArrayBuilder;
use PBaszak\DedicatedMapper\Expression\Builder\ReflectionClassExpressionBuilder as ClassBuilder;
use PBaszak\DedicatedMapper\MapperService;

class Test
{
private string $name;
}

$data = [
'name' => 'test';
];
$mapper = new MapperService('/app/var/mapper/');

/** @var Test $test */
$test = $mapper->map(
$data,
Test::class,
new ArrayBuilder(), # You have to specify $data type, available options: 'array', 'object', 'class object'. In this case it's a `array`
new ClassBuilder(), # You have to specify output type, in this case it's `class object` based on the blueprint class `Test`.
);
```

## How it works?
The **Dedicated Mapper** generates php file which looks like this one *(it's only example for specific case)*:

```php
<?php

declare(strict_types=1);

return function (array $data): PBaszak\DedicatedMapper\Tests\Performance\SimpleData {
$ref_df1d1d13 = new ReflectionClass(PBaszak\DedicatedMapper\Tests\Performance\SimpleData::class);
/** @var PBaszak\DedicatedMapper\Tests\Performance\SimpleData $output */
$output = $ref_df1d1d13->newInstanceWithoutConstructor();

if (array_key_exists('name', $data)) {
$ref_df1d1d13->getProperty('name')->setValue($output, $data['name']);
}

return $output;
};
```

and using it in the mapping process.

## Report ##
### Environment Details
- **PHP**: 8.2.7 (from Dockerfile and without xdebug)
Expand All @@ -24,19 +78,49 @@ It's even **37** times faster than **JMS Serializer** and even **2500** times fa
#### JMS Serializer vs Dedicated Mapper
| Test Case | Metric | JMS Serializer | Dedicated Mapper | Performance Gain |
| Test Case | Metric | JMS Serializer | Dedicated Mapper | Performance Gain |
|:---------------------------------:|:------:|----------------------:|-----------------------:|----------------------:|
| Build & Use | avg | 0.00073563575744629 s | 0.00022567272186279 s | 3.26x faster |
| | min | 0.00061202049255371 s | 0.0001990795135498 s | 3.07x faster |
| | max | 0.006666898727417 s | 0.0012781620025635 s | 5.22x faster |
| Use (one time) | avg | 0.00064053297042847 s | 0.00020017862319946 s | 3.2x faster |
| | min | 0.00055694580078125 s | 0.00018501281738281 s | 3.01x faster |
| | max | 0.0044717788696289 s | 0.0002751350402832 s | 16.25x faster |
| Second Use (Same Data) | avg | 0.00031213998794556 s | 5.3181648254395E-5 s | 5.87x faster |
| | min | 0.00029683113098145 s | 5.0067901611328E-5 s | 5.93x faster |
| | max | 0.0003669261932373 s | 7.8916549682617E-5 s | 4.65x faster |
| Second Use (Different Data) | avg | 0.00062076330184937 s | 5.8262348175049E-5 s | 10.65x faster |
| | min | 0.0005500316619873 s | 5.4836273193359E-5 s | 10.03x faster |
| | max | 0.0029869079589844 s | 9.5129013061523E-5 s | 31.4x faster |
#### Symfony Serializer vs Dedicated Mapper
| Test Case | Metric | Symfony Serializer | Dedicated Mapper | Performance Gain |
|:---------------------------------:|:------:|-----------------------:|-----------------------:|----------------------:|
| Build & Use | avg | 0.0010306453704834 s | 0.00020055055618286 s | 5.14x faster |
| | min | 0.00090694427490234 s | 0.00018501281738281 s | 4.9x faster |
| | max | 0.0069160461425781 s | 0.001025915145874 s | 6.74x faster |
| Use (one time) | avg | 0.00077522277832031 s | 0.00018158197402954 s | 4.27x faster |
| | min | 0.00063705444335938 s | 0.00016999244689941 s | 3.75x faster |
| | max | 0.0062828063964844 s | 0.00025200843811035 s | 24.93x faster |
| Second Use (Same Data) | avg | 0.00035294532775879 s | 4.8666000366211E-5 s | 7.25x faster |
| | min | 0.00033092498779297 s | 4.6014785766602E-5 s | 7.19x faster |
| | max | 0.00045204162597656 s | 8.2015991210938E-5 s | 5.51x faster |
| Second Use (Different Data) | avg | 0.00069396495819092 s | 5.272388458252E-5 s | 13.16x faster |
| | min | 0.0006108283996582 s | 4.7922134399414E-5 s | 12.75x faster |
| | max | 0.0049350261688232 s | 0.00013303756713867 s | 37.09x faster |
| Build & Use | avg | 0.0021615481376648 s | 0.00021748304367065 s | 9.94x faster |
| | min | 0.0019149780273438 s | 9.3221664428711E-5 s | 20.54x faster |
| | max | 0.01357889175415 s | 0.00031518936157227 s | 43.08x faster |
| Use (one time) | avg | 0.0019077062606812 s | 0.0002018141746521 s | 9.45x faster |
| | min | 0.0017900466918945 s | 0.00018596649169922 s | 9.63x faster |
| | max | 0.0043408870697021 s | 0.0002748966217041 s | 15.79x faster |
| Second Use (Same Data) | avg | 0.0011084413528442 s | 6.0606002807617E-5 s | 18.29x faster |
| | min | 0.0010659694671631 s | 5.5074691772461E-5 s | 19.35x faster |
| | max | 0.0017890930175781 s | 0.0001060962677002 s | 16.86x faster |
| Second Use (Different Data) | avg | 0.0019117307662964 s | 6.1674118041992E-5 s | 31x faster |
| | min | 0.0017828941345215 s | 5.6028366088867E-5 s | 31.82x faster |
| | max | 0.0042397975921631 s | 0.00010395050048828 s | 40.79x faster |
| Build, Use & Validation | avg | 0.0023907327651978 s | 0.00046631574630737 s | 5.13x faster |
| | min | 0.002216100692749 s | 0.00043201446533203 s | 5.13x faster |
| | max | 0.007519006729126 s | 0.00083398818969727 s | 9.02x faster |
| Use & Validation (one time) | avg | 0.0022232341766357 s | 0.00038869619369507 s | 5.72x faster |
| | min | 0.0020699501037598 s | 0.0003659725189209 s | 5.66x faster |
| | max | 0.0052480697631836 s | 0.0004730224609375 s | 11.09x faster |
| Second Use & Validation (Same Data) | avg | 0.0012864065170288 s | 0.00018531322479248 s | 6.94x faster |
| | min | 0.0012338161468506 s | 0.00017285346984863 s | 7.14x faster |
| | max | 0.0020201206207275 s | 0.0002751350402832 s | 7.34x faster |
| Second Use & Validation (Different Data) | avg | 0.0021827912330627 s | 0.00018846273422241 s | 11.58x faster |
| | min | 0.00205397605896 s | 0.00017499923706055 s | 11.74x faster |
| | max | 0.0047998428344727 s | 0.0003211498260498 s | 14.95x faster |
<sub>*Tables generated using Chat GPT-4 based on test data. This information is here because the chat is not a perfect tool and could mess up the measured times for example.</sub>
25 changes: 14 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
"php": ">=8.0",
"phpdocumentor/reflection-docblock": "^5.3",
"friendsofphp/php-cs-fixer": "^3.22",
"symfony/uid": "^5.4 || ^6.0 || ^6.2"
"symfony/uid": "^5.4 || ^6 || ^7"
},
"require-dev": {
"symfony/config": "^5.4 || ^6.0 || ^6.2",
"symfony/dependency-injection": "^5.4 || ^6.0 || ^6.2",
"symfony/console": "^5.4 || ^6.0 || ^6.2",
"symfony/http-kernel": "^5.4 || ^6.0 || ^6.2",
"symfony/runtime": "^5.4 || ^6.0 || ^6.2",
"symfony/phpunit-bridge": "^5.4 || ^6.0 || ^6.2",
"symfony/framework-bundle": "^5.4 || ^6.0 || ^6.2",
"symfony/yaml": "^5.4 || ^6.0 || ^6.2",
"symfony/validator": "^5.4 || ^6.0 || ^6.2",
"symfony/serializer": "^5.4 || ^6.0 || ^6.2",
"symfony/config": "^5.4 || ^6 || ^7",
"symfony/dependency-injection": "^5.4 || ^6 || ^7",
"symfony/console": "^5.4 || ^6 || ^7",
"symfony/http-kernel": "^5.4 || ^6 || ^7",
"symfony/runtime": "^5.4 || ^6 || ^7",
"symfony/phpunit-bridge": "^5.4 || ^6 || ^7",
"symfony/framework-bundle": "^5.4 || ^6 || ^7",
"symfony/yaml": "^5.4 || ^6 || ^7",
"symfony/validator": "^5.4 || ^6 || ^7",
"symfony/serializer": "^5.4 || ^6 || ^7",
"symfony/serializer-pack": "^1.2",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan": "^1.9",
Expand Down Expand Up @@ -60,6 +60,7 @@
"phpunit": "vendor/bin/phpunit --colors=always",
"test:unit": "@phpunit --group unit tests",
"test:func": "@phpunit --group func tests",
"test:e2e": "@phpunit --group e2e tests",
"test:integration": "@phpunit --group integration tests",
"test:performance": [
"@putenv APP_DEBUG=0",
Expand All @@ -70,11 +71,13 @@
"@code:analyse",
"@test:unit",
"@test:func",
"@test:e2e",
"@test:integration"
],
"test:all": [
"@test:unit",
"@test:func",
"@test:e2e",
"@test:integration",
"@test:performance"
]
Expand Down
Loading

0 comments on commit 9e17ff7

Please sign in to comment.