Skip to content
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

Check CDATA is needed #136

Closed
dominikzogg opened this issue Aug 28, 2013 · 2 comments
Closed

Check CDATA is needed #136

dominikzogg opened this issue Aug 28, 2013 · 2 comments

Comments

@dominikzogg
Copy link

Hello @schmittjoh

I would like to add a check if cdata is needed.

Example with check:

<?php

$document = new \DOMDocument('1.0', 'UTF-8');
$signs = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&<>';
$signCount = strlen($signs);
$start = microtime();
for($i=0;$i<=1000;$i++) {
    $word = '';
    for($y=0;$y<=10;$y++) {
        $word .= $signs[rand(0, $signCount - 1)];
    }
    $node = $document->createElement('entry');
    if(strpos($word, '<') !== false || strpos($word, '&') !== false) {
        $cdata = $document->createCDATASection($word);
        $node->appendChild($cdata);
    } else {
        $node->nodeValue = $word;
    }
    $document->appendChild($node);
}
echo microtime() - $start;

Example without check:

<?php

$document = new \DOMDocument('1.0', 'UTF-8');
$signs = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&<>';
$signCount = strlen($signs);
$start = microtime();
for($i=0;$i<=1000;$i++) {
    $word = '';
    for($y=0;$y<=10;$y++) {
        $word .= $signs[rand(0, $signCount - 1)];
    }
    $node = $document->createElement('entry');
    $cdata = $document->createCDATASection($word);
    $node->appendChild($cdata);
    $document->appendChild($node);
}
echo microtime() - $start;

Time needed with check:
0.018812
0.018168
0.018789

Time needed without check:
0.01897
0.018391
0.020334
0.025101
0.018615

In worst case had it ones, it can be 40% slower, but most of time it was nearly as fast as without check. In the serializer the percentage would be much lower, cause its much more complex than my example.

@marcospassos
Copy link
Contributor

The PR #119 adds this possibility.

@goetas
Copy link
Collaborator

goetas commented Mar 10, 2017

implemented with #187

@goetas goetas closed this as completed Mar 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants