Skip to content

Avoid additional allocation in Document\createElementNS #14071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2024

Conversation

nielsdos
Copy link
Member

For the following benchmark code:

$dom = DOM\XMLDocument::createEmpty();
for ($i = 0; $i < 1000*100; $i++) $dom->createElementNS("urn:a", "thisisaveryverylongname");

We obtain the following on an i7-4790:

Benchmark 1: ./sapi/cli/php bench.php
  Time (mean ± σ):      34.5 ms ±   1.2 ms    [User: 31.4 ms, System: 2.9 ms]
  Range (min … max):    32.4 ms …  39.3 ms    84 runs

Benchmark 2: ./sapi/cli/php_old bench.php
  Time (mean ± σ):      36.6 ms ±   1.6 ms    [User: 33.6 ms, System: 2.9 ms]
  Range (min … max):    34.3 ms …  45.3 ms    80 runs

Summary
  ./sapi/cli/php bench.php ran
    1.06 ± 0.06 times faster than ./sapi/cli/php_old bench.php

For the following benchmark code:
```php
$dom = DOM\XMLDocument::createEmpty();
for ($i = 0; $i < 1000*100; $i++) $dom->createElementNS("urn:a", "thisisaveryverylongname");
```

We obtain the following on an i7-4790:
```
Benchmark 1: ./sapi/cli/php bench.php
  Time (mean ± σ):      34.5 ms ±   1.2 ms    [User: 31.4 ms, System: 2.9 ms]
  Range (min … max):    32.4 ms …  39.3 ms    84 runs

Benchmark 2: ./sapi/cli/php_old bench.php
  Time (mean ± σ):      36.6 ms ±   1.6 ms    [User: 33.6 ms, System: 2.9 ms]
  Range (min … max):    34.3 ms …  45.3 ms    80 runs

Summary
  ./sapi/cli/php bench.php ran
    1.06 ± 0.06 times faster than ./sapi/cli/php_old bench.php
```
@devnexen
Copy link
Member

Do you plan to use it in other places ?

@nielsdos
Copy link
Member Author

Do you plan to use it in other places ?

You mean use the alternative API in other places? No.

@nielsdos nielsdos merged commit ed91621 into php:master Apr 29, 2024
10 checks passed
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.

2 participants