Skip to content

Instantly share code, notes, and snippets.

@beberlei
Created February 3, 2024 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beberlei/be346b3e1139d3b70f74b290cd361a13 to your computer and use it in GitHub Desktop.
Save beberlei/be346b3e1139d3b70f74b290cd361a13 to your computer and use it in GitHub Desktop.
<?php
use Tideways\Profiler\WithSpan;
$dom = new DOMDocument();
$root = $dom->createElementNS('http://www.w3.org/2000/xhtml', 'html');
$dom->appendChild($root);
#[WithSpan]
function addParagraphs($dom, $node, $number) {
$s = microtime(true);
for ($i = 0; $i < $number; $i++) {
$element = $dom->createElementNS('http://www.w3.org/2000/xhtml', 'p', 'Hello World');
$node->appendChild($element);
}
echo number_format(microtime(true) - $s, 6) . "\n";
}
for ($i = 0; $i < 3; $i++) {
addParagraphs($dom, $root, 10000);
usleep(PHP_VERSION_ID >= 80300 ? 1000 : 10000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment