Skip to content

Commit

Permalink
improve benchmark scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpts committed Feb 16, 2020
1 parent 0904fce commit 484c585
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 21 deletions.
54 changes: 54 additions & 0 deletions benchmark/bechmark-collections.php
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);
}
47 changes: 26 additions & 21 deletions benchmark/bechmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 484c585

Please sign in to comment.