Skip to content

Conversation

soyuka
Copy link
Contributor

@soyuka soyuka commented Aug 25, 2025

Q A
Branch? 7.4
Bug fix? no
New feature? yes
Deprecations? no
Issues n/a
License MIT

needs #61497

(code-gen ✗)❯ /home/linuxbrew/.linuxbrew/Cellar/php/8.4.11/bin/php ./vendor/bin/phpbench run
PHPBench (84.x-dev) running benchmarks... #standwithukraine
with configuration file: /home/soyuka/forks/symfony/src/Symfony/Component/ObjectMapper/phpbench.json
with PHP version 8.4.11, xdebug ✔, opcache ❌

\Symfony\Component\ObjectMapper\Benchmarks\ObjectMapperBench

    benchObjectMapper.......................I4 - Mo268.351μs (±0.86%)
    benchCachedObjectMapper.................I4 - Mo134.417μs (±0.41%)

Subjects: 2, Assertions: 0, Failures: 0, Errors: 0
Benchmark code
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\ObjectMapper\Benchmarks;

use PhpBench\Attributes as Bench;
use Symfony\Component\ObjectMapper\CachedObjectMapper;
use Symfony\Component\ObjectMapper\ObjectMapper;
use Symfony\Component\ObjectMapper\Tests\Fixtures\A;
use Symfony\Component\ObjectMapper\Tests\Fixtures\C;
use Symfony\Component\ObjectMapper\Tests\Fixtures\D;

#[Bench\BeforeMethods('setUp')]
class ObjectMapperBench
{
    private ObjectMapper $objectMapper;
    private CachedObjectMapper $cachedObjectMapper;
    private A $sourceObject;
    private string $cacheDir;

    public function setUp(): void
    {
        $this->objectMapper = new ObjectMapper();
        $this->cacheDir = sys_get_temp_dir() . '/symfony_object_mapper_bench_' . uniqid();
        $this->cachedObjectMapper = new CachedObjectMapper($this->cacheDir);

        $d = new D(baz: 'foo', bat: 'bar');
        $c = new C(foo: 'foo', bar: 'bar');
        $this->sourceObject = new A();
        $this->sourceObject->foo = 'test';
        $this->sourceObject->transform = 'test';
        $this->sourceObject->baz = 'me';
        $this->sourceObject->notinb = 'test';
        $this->sourceObject->relation = $c;
        $this->sourceObject->relationNotMapped = $d;
    }

    public function tearDown(): void
    {
        if (is_dir($this->cacheDir)) {
            array_map('unlink', glob($this->cacheDir . '/*'));
            rmdir($this->cacheDir);
        }
    }

    #[Bench\Revs(100)]
    #[Bench\Iterations(5)]
    public function benchObjectMapper(): void
    {
        $this->objectMapper->map($this->sourceObject);
    }

    #[Bench\Warmup(1)]
    #[Bench\Revs(100)]
    #[Bench\Iterations(5)]
    public function benchCachedObjectMapper(): void
    {
        $this->cachedObjectMapper->map($this->sourceObject);
    }
}

@fabpot
Copy link
Member

fabpot commented Aug 27, 2025

#61497 has been merged now.

@mtarld
Copy link
Contributor

mtarld commented Aug 27, 2025

@soyuka maybe you can leverage the Filesystem component like it has been done in the JsonStreamer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants