-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
80 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
use Blackfire\Client; | ||
use Blackfire\Profile\Configuration; | ||
use Faker\Factory as Faker; | ||
use PTS\DataTransformer\DataTransformer; | ||
|
||
require_once __DIR__ .'/../vendor/autoload.php'; | ||
require_once 'UserModel.php'; | ||
$faker = Faker::create(); | ||
|
||
$iterations = $argv[1] ?? 1000; | ||
$blackfire = $argv[2] ?? false; | ||
$iterations++; | ||
|
||
$service = new DataTransformer; | ||
$service->getMapsManager()->setMapDir(UserModel::class, __DIR__); | ||
|
||
$collectionDto = []; | ||
while ($iterations--) { | ||
$collectionDto[] = [ | ||
'id' => $faker->randomDigit, | ||
'creAt' => $faker->unixTime(), | ||
'name' => $faker->name, | ||
'login' => $faker->name, | ||
'active' => $faker->numberBetween(0, 2), | ||
'email' => $faker->email, | ||
'childModel' => [ | ||
'id' => $faker->randomDigit, | ||
'creAt' => time(), | ||
'name' => $faker->unixTime(), | ||
'login' => $faker->name, | ||
'active' => $faker->boolean, | ||
'email' => $faker->email, | ||
] | ||
]; | ||
} | ||
|
||
if ($blackfire) { | ||
$client = new Client; | ||
$probe = $client->createProbe(new Configuration); | ||
} | ||
$startTime = microtime(true); | ||
|
||
$models = $service->toModelsCollection(UserModel::class, $collectionDto); | ||
$collectionDto = $service->toDtoCollection($models); | ||
|
||
$diff = (microtime(true) - $startTime) * 1000; | ||
echo sprintf('%2.3f ms', $diff); | ||
echo "\n" . memory_get_peak_usage()/1024; | ||
|
||
if ($blackfire) { | ||
$client->endProbe($probe); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,42 +2,47 @@ | |
|
||
use Blackfire\Client; | ||
use Blackfire\Profile\Configuration; | ||
use Faker\Factory as Faker; | ||
use PTS\DataTransformer\DataTransformer; | ||
|
||
require_once __DIR__ .'/../vendor/autoload.php'; | ||
require_once 'UserModel.php'; | ||
$faker = Faker::create(); | ||
|
||
$iterations = $argv[1] ?? 1000; | ||
$blackfire = $argv[2] ?? false; | ||
$iterations++; | ||
|
||
$service = new DataTransformer; | ||
$service->getMapsManager()->setMapDir(UserModel::class, __DIR__); | ||
|
||
$collectionDto = []; | ||
while ($iterations--) { | ||
$collectionDto[] = [ | ||
'id' => $faker->randomDigit, | ||
'creAt' => $faker->unixTime(), | ||
'name' => $faker->name, | ||
'login' => $faker->name, | ||
'active' => $faker->numberBetween(0, 2), | ||
'email' => $faker->email, | ||
'childModel' => [ | ||
'id' => $faker->randomDigit, | ||
'creAt' => time(), | ||
'name' => $faker->unixTime(), | ||
'login' => $faker->name, | ||
'active' => $faker->boolean, | ||
'email' => $faker->email, | ||
] | ||
]; | ||
} | ||
|
||
if ($blackfire) { | ||
$client = new Client; | ||
$probe = $client->createProbe(new Configuration); | ||
} | ||
|
||
$startTime = microtime(true); | ||
$service = new DataTransformer; | ||
$service->getMapsManager()->setMapDir(UserModel::class, __DIR__); | ||
|
||
$dto = [ | ||
'id' => 1, | ||
'creAt' => time(), | ||
'name' => 'Alex', | ||
'login' => 'login', | ||
'active' => 1, | ||
'email' => '[email protected]', | ||
'childModel' => [ | ||
'id' => 2, | ||
'creAt' => time(), | ||
'name' => 'Alex2', | ||
'login' => 'login2', | ||
'active' => false, | ||
'email' => '[email protected]', | ||
] | ||
]; | ||
|
||
while ($iterations--) { | ||
foreach ($collectionDto as $dto) { | ||
$model = $service->toModel(UserModel::class, $dto); | ||
$dto = $service->toDTO($model); | ||
} | ||
|