What's going on here, that causes such a large performance hit when inserting HTML into a template?
<?phprequire"vendor/autoload.php";
// 1-kilobyte string of random characters:$oneK = random_bytes(1024);
// 1-kilobyte string of HTML:$html = <<<HTML<tr><td>one </td><td>two</td><td>three</td><td>four</td><td>five</td><td>six</td><td>seven</td></tr><tr><td>one </td><td>two</td><td>three</td><td>four</td><td>five</td><td>six</td><td>seven</td></tr><tr><td>one </td><td>two</td><td>three</td><td>four</td><td>five</td><td>six</td><td>seven</td></tr><tr><td>one </td><td>two</td><td>three</td><td>four</td><td>five</td><td>six</td><td>seven</td></tr><tr><td>one </td><td>two</td><td>three</td><td>four</td><td>five</td><td>six</td><td>seven</td></tr><tr><td>one </td><td>two</td><td>three</td><td>four</td><td>five</td><td>six</td><td>seven</td></tr><tr><td>one </td><td>two</td><td>three</td><td>four</td><td>five</td><td>six</td><td>seven</td></tr><tr><td>one </td><td>two</td><td>three</td><td>four</td><td>five</td><td>six</td><td>seven</td></tr><tr><td>one </td><td>two</td><td>three</td><td>four</td><td>five</td><td>six</td><td>seven</td></tr><tr><td>one </td><td>two</td><td>three</td><td>four</td><td>five</td><td>six</td><td>seven</td></tr>HTML;
$xml = ' <main> @@ </main> ';
$tss = <<<TSSmain { content: data(html); content-mode: replace; format: html;}TSS;
$tss2 = <<<TSS2main { content: data(html); content-mode: replace;}TSS2;
$data['html'] = str_repeat($html, 4000);
$data2['html'] = str_repeat($oneK, 4000);
test($xml, $tss, $data2, "format html with random string");
test($xml, $tss2, $data2, "no format with random string");
test($xml, $tss, $data, "format html with HTML");
test($xml, $tss2, $data, "no format with HTML");
functiontest($xml, $tss, $data, $title) {
$template = newTransphporm\Builder($xml, $tss);
$start = microtime(true);
$template->output($data)->body;
$stop = microtime(true);
echosprintf("%30s time: %12.6f seconds\n", $title, ($stop - $start));
}format html with random string time: 0.033743 seconds
no format with random string time: 0.002971 seconds
format html with HTML time: 36.562475 seconds
no format with HTML time: 0.123278 seconds
What's going on here, that causes such a large performance hit when inserting HTML into a template?
And the output on my laptop: