Skip to content
This repository has been archived by the owner on Feb 19, 2025. It is now read-only.

Commit

Permalink
Add file cache closure hydrator
Browse files Browse the repository at this point in the history
  • Loading branch information
VolCh committed Dec 10, 2019
1 parent c352aef commit 55b01e4
Show file tree
Hide file tree
Showing 9 changed files with 602 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace GeneratedHydratorBenchmark\FileClosure;

use GeneratedHydratorBenchmark\Data\AllPrivateClass;

/**
* Benchmark class that contains only private properties hydration
*
* @BeforeMethods({"setUp"})
*/
class AllPrivateClassHydrationBench extends HydrationBench
{
public function setUp() : void
{
$this->createHydrator(AllPrivateClass::class);
$this->createData();
$this->object = new AllPrivateClass();
}

/**
* @Revs(100)
* @Iterations(200)
*/
public function benchConsume() : void
{
($this->hydrator)($this->data, $this->object);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace GeneratedHydratorBenchmark\FileClosure;

use GeneratedHydratorBenchmark\Data\AllProtectedClass;

/**
* Benchmark class that contains only protected properties hydration
*
* @BeforeMethods({"setUp"})
*/
class AllProtectedClassHydrationBench extends HydrationBench
{
public function setUp() : void
{
$this->createHydrator(AllProtectedClass::class);
$this->createData();
$this->object = new AllProtectedClass();
}

/**
* @Revs(100)
* @Iterations(200)
*/
public function benchConsume() : void
{
($this->hydrator)($this->data, $this->object);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace GeneratedHydratorBenchmark\FileClosure;

use GeneratedHydratorBenchmark\Data\AllPublicClass;

/**
* Benchmark class that contains only public properties hydration
*
* @BeforeMethods({"setUp"})
*/
class AllPublicClassHydrationBench extends HydrationBench
{
public function setUp() : void
{
$this->createHydrator(AllPublicClass::class);
$this->createData();
$this->object = new AllPublicClass();
}

/**
* @Revs(100)
* @Iterations(200)
*/
public function benchConsume() : void
{
($this->hydrator)($this->data, $this->object);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace GeneratedHydratorBenchmark\FileClosure;

use DateTime;
use GeneratedHydrator\ClosureGenerator\FileCache\GenerateFileCacheHydrator;
use GeneratedHydratorBenchmark\HydrationBench as BaseHydrationBenchAlias;
use stdClass;

class HydrationBench extends BaseHydrationBenchAlias
{
/** @var callable */
protected $hydrator;

/** @var mixed[] */
protected $data;

/** @var mixed */
protected $object;

/**
* Create and set the hydrator
*/
protected function createHydrator(string $class) : void
{
$this->hydrator = (new GenerateFileCacheHydrator('build/'))($class);
}

/**
* Populate test data array
*/
protected function createData() : void
{
$this->data = [
'foo' => 'some foo string',
'bar' => 42,
'baz' => new DateTime(),
'someFooProperty' => [12, 13, 14],
'someBarProperty' => 12354.4578,
'someBazProperty' => new stdClass(),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace GeneratedHydratorBenchmark\RuntimeClosure;

use DateTime;
use GeneratedHydratorBenchmark\Data\InheritanceClass;
use stdClass;

/**
* Benchmark class that contains mixed inherited properties hydration
*
* @BeforeMethods({"setUp"})
*/
class InheritanceClassHydrationBench extends HydrationBench
{
protected function createData() : void
{
parent::createData();

$this->data += [
'foo1' => 'some foo string',
'bar1' => 42,
'baz1' => new DateTime(),
'someFooProperty1' => [12, 13, 14],
'someBarProperty1' => 12354.4578,
'someBazProperty1' => new stdClass(),
];
}

public function setUp() : void
{
$this->createHydrator(InheritanceClass::class);
$this->createData();
$this->object = new InheritanceClass();
}

/**
* @Revs(100)
* @Iterations(200)
*/
public function benchConsume() : void
{
($this->hydrator)($this->data, $this->object);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace GeneratedHydratorBenchmark\RuntimeClosure;

use DateTime;
use GeneratedHydratorBenchmark\Data\InheritanceDeepClass;
use stdClass;

/**
* Benchmark class that contains mixed deeply inherited properties hydration
*
* @BeforeMethods({"setUp"})
*/
class InheritanceDeepClassHydrationBench extends HydrationBench
{
protected function createData() : void
{
parent::createData();

$this->data += [
'foo1' => 'some foo string',
'bar1' => 42,
'baz1' => new DateTime(),
'someFooProperty1' => [12, 13, 14],
'someBarProperty1' => 12354.4578,
'someBazProperty1' => new stdClass(),
'foo2' => 'some foo string',
'bar2' => 42,
'baz2' => new DateTime(),
'someFooProperty2' => [12, 13, 14],
'someBarProperty2' => 12354.4578,
'someBazProperty2' => new stdClass(),
];
}

public function setUp() : void
{
$this->createHydrator(InheritanceDeepClass::class);
$this->createData();
$this->object = new InheritanceDeepClass();
}

/**
* @Revs(100)
* @Iterations(200)
*/
public function benchConsume() : void
{
($this->hydrator)($this->data, $this->object);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace GeneratedHydratorBenchmark\RuntimeClosure;

use GeneratedHydratorBenchmark\Data\MixedClass;

/**
* Benchmark class that contains public, protected and private properties hydration
*
* @BeforeMethods({"setUp"})
*/
class MixedClassHydrationBench extends HydrationBench
{
public function setUp() : void
{
$this->createHydrator(MixedClass::class);
$this->createData();
$this->object = new MixedClass();
}

/**
* @Revs(100)
* @Iterations(200)
*/
public function benchConsume() : void
{
($this->hydrator)($this->data, $this->object);
}
}
Loading

0 comments on commit 55b01e4

Please sign in to comment.