Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there overhead using PHP Doc comments vs regular comments?

I read that when the PHP lexer parses the php and encounters a doccomment, that it stores the contents of that comments as metadata. So I would assume this might have a slight overhead compared to using regular comments in non-doccomment format?

Regular comment...

<?php

/*
some text
/*
// more comments

?>

doccomment...

<?php
/**
 * @author Kenneth Davis
 * @copyright 2011
 * @filename Exception.class.php
*/
?>
like image 899
JasonDavis Avatar asked Oct 05 '11 23:10

JasonDavis


1 Answers

As others have mentioned, the difference is so small that it doesn't matter. But to answer your question, there is a difference in runtimes. To test this, I've generated two php files, each with 50000 classes, and each weighing in at exactly 4288896 bytes.

Here's the template I used for the docblock version:

/**
 * My Docblock
 */
class MyClass%s {}

and here's the version with no true docblock (without the two * at the beginning, ReflectionClass::getDocComment() did not find the comment):

/*-
 * My Docblock
 */
class MyClass%s {}

The full script to generate the php files is here: https://gist.github.com/1268179

To see any noticable difference in time, I had to run each through php 10 times, like so:

time yes docblock.php | head -n 10 | xargs -n 1 php

Here's the outcome:

with docblocks:

xargs -n 1 php  2.22s user 0.63s system 99% cpu 2.873 total

without docblocks:

xargs -n 1 php  2.16s user 0.63s system 99% cpu 2.813 total

Running this several times, seemed to yield consistent faster (barely) times for the no docblock version.

To sum it up, that's about 0.00012 milliseconds per docblock that php keeps track of (if I did my math right there).

like image 119
Adam Wagner Avatar answered Oct 07 '22 14:10

Adam Wagner