Opening/Closing Tags & Performance

Opening/closing tags & performance?

3 simple rules for you to get it right:

  • No syntax issue can affect performance. Data manipulation does.
  • Speak of performance only backed with results of profiling.
  • Premature optimization is the root of all evil

Performance issues are quite hard to understand. It is advised for the newbies not to take it into account. Because they are always impressed with trifle things and fail to see a real important things. Just because lack of experience.

Same for your question. Imagine you'll ever get some difference. Even big one, say, one method is 2 times faster. Oh my, 2 times! I choose it and optimized my app well, it will run 50% faster now!

Wrong. Not 50%. You'd never notice or even measure this speed increase. Because you optimized a part that take only 0,0001% of whole script runtime.

As for the big HTML tables, it take a long time for the browser to render it. Much more than you took to generate.

Profiling is a key word in the performance world. One can trash any performance related question with no doubts if there is no word "profiling" in it.
At the same time profiling is not a rocket science. It's just measuring of runtime of different parts of your script. Can be done with some profiler, like xdebug, or even manually, using microtime(1). And only after detecting the slowest part, may you start with tests.

Learn to profile before asking performance questions.
And learn not to ask performance questions if there is no real reasons for it.

Premature optimization is the root of all evil - D.Knuth.

Does opening and closing php tags multiple times increases page load?

  1. Theoretically yes, but the difference is so miniscule that in almost all cases it wouldn't matter.

  2. Not sure about what you mean. If there is a possibility of a file being included multiple times, use include_once or require_once. This will prevent multiple loads and prevents errors like 'Cannot redeclare class'. Again this is more expensive than include and require, but more stable.

As a side note, your questions are not anything related to code, and I am sure these have already been asked and answered multiple times in SO, so please try to search/ask better next time :)

All the best!

Does the quantity of ?php and ? tags affect performance?

Does it have a performance impact? Yes. Simply because there is more text for the parser to parse. It must have an impact. And yes, it will have a measurable impact.

Does it have a meaningful impact? No. Not at all. You would be hard pressed to see any difference even if you had millions of them in your app. Yes, there will be more clock cycles used, but trivially...

The bigger thing is to note that the two pieces of code are not identical in general. PHP will strip a single new line after a closing ?>, but any other characters after ?> will render in the output. So trailing spaces or multiple newlines after ?> will be rendered directly.

So my suggestion is ignore the performance, write the correct and more readable code (the more semantically correct code). And ignore small performance differences...

Closing and opening the php tag

I don't know of any performance issue. There might be a very minor performance issue due to the emission of what is between the two statements, but I think it would be unnoticeable.

However, you should not break out of php for a different reason: this emission prevents you from sending any other headers with your request. I think that breaking out of php to print is an antiquated notion and should be avoided entirely. If you are going to do it, reserve it for printing the results of your logic (all done long before any printing, probably in a different file).

How to add closing and opening div tags every X amount of divs inside another div?

I won't use jQuery to change html tag structure.

Maybe you can change your for loop like this.

var groups = {};$(".product-list .product-list_item").each(function(i) {  var c = $(this).attr("class");  if (!groups[c]) groups[c] = [];  groups[c].push(this);});
/*for (var i in groups) { //$(groups[i]).wrapAll('<div class="product-list_row" />'); $(groups[i]).wrapAll('<div class="product-list_row" />').each(function(i) { if (((i + 1) % 3) == 0) $(this).after('</div><div class="product-list_row">'); });}*/
for (var i in groups) { var group = groups[i]; var count=0; var rowEles=[]; for(var j=0;j<group.length;j++){ rowEles.push(group[j]); count++; if(rowEles.length==3||count==group.length){ $(rowEles).wrapAll('<div class="product-list_row" />'); rowEles=[]; } }}
body {  padding: 20px;}
.product-list { margin-bottom: 10px; padding: 5px; border: 1px solid red;}
.product-list_row { border: 1px solid #bbb; padding: 5px; margin-bottom: 10px;}
.whatever { margin-bottom: 10px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><div class="product-list">
<div class="product-list_item jackson">x</div> <div class="product-list_item jackson">x</div> <div class="product-list_item jackson">x</div> <div class="product-list_item jackson">x</div> <div class="product-list_item mason">x</div> <div class="product-list_item mason">x</div> <div class="product-list_item mason">x</div>
</div><div class="whatever"> hello i'm different</div><div class="product-list">
<div class="product-list_item taylor">x</div> <div class="product-list_item taylor">x</div> <div class="product-list_item pencil">x</div> <div class="product-list_item pencil">x</div> <div class="product-list_item pencil">x</div>
</div>

Edit HTML opening and closing tag at the same time in RubyMine

Refactor | Rename (Shift+F6), then edit one of the tags and another one will be edited to the same value automatically.

Opening & Closing HTML tags with multiple logic Loops inbetween

$close_div = "";
@foreach($catWomen->getDescendants() as $descendant)
<?php
if($descendant->depth == 1){
echo($close_div);// first time it is empty string, then always is "</div>"
$close_div = "</div>";
echo '<div class="col-md-4 header-navigation-col">';
echo '<h4>Category Name</h4>';
}elseif($descendant->depth == 2){
echo '<li><a>Sub Category</a></li>';
}
?>
@endforeach


Related Topics



Leave a reply



Submit