Categories > TinyButStrong general >

Speed of tbs

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: RwD
Date: 2004-06-08
Time: 20:44

Speed of tbs

I am discussing in a forum now about template engines, and ofcourse I recommended it for its easy way of programming (bottom of this post) but one thing came up I can't answer...

Someone asked about the speed of tbs when the blocks are being located, say you define inside a td element the block to be the tr element around it, then how fast is the tr element located and how fast is this system when compared to systems like Smarty?

I know you test it, so I think you will have an answer ready :)

I am sorry, but the forum is in Dutch, so you can't simply join if you want to (unless you speak Dutch as well???)

To show easy of use I compared TBS to the optimum piece of code a moderator posted there using PHP as a template engine

his code+template
PHP:
<?php
$output = array ();

$query = "SELECT some, stuff FROM myTable";
$res = mysql_query ( $query );
$output [ 'rows' ] = array ();
while ( $row = mysql_fetch_assoc ( $res ) ) {
   $output [ 'rows' ][]= $row;
}

include ( './template/mytable.php' );
?>

Template:
<? if ( empty ( $output [ 'rows' ] ) ): ?>
   <p>No results</p>
<? else: ?>
   <table>
      <?foreach ( $output [ 'rows' ] as $row ): ?>
         <tr>
            <td><?=html ( $row [ 'some' ] )?></td>
            <td><?=html ( $row [ 'stuff' ] )?></td>
         </tr>
      <?endforeach;?>
   </table>
<? endif; ?>

My tbs version of it:
PHP:
<?php
   // $cnx_id is the connection id made in the code before this part
   $TBS = new clsTinyButStrong;
   $TBS->LoadTemplate( 'example.htm' );
   $TBS->MergeBlock( 'example', $cnx_id, 'SELECT some, stuff FROM myTable' );
   $TBS->Show() ;
?>

Template:
<table>
   <tr>
      <td>[example.some;block=tr]</td>
      <td>[example.stuff]</td>
   </tr>
   <tr>
      <td colspan="2">[example;block=tr;nodata]No results.</td>
   </tr>
</table>

Second piece of code is much easier to read, but the question came about its speed...
By: Skrol29
Date: 2004-06-09
Time: 01:28

Re: Speed of tbs

Hi RwD,

The TBS block syntaxes (explicit, relative or simplified) have not a big impact on the merge speed. Because the block definition is read only once during the merge. You can change your TBS test with the explicit syntax (block=begin + block=end), this will not save significant time.

But when merging each rows, TBS search again for all TBS tags in the current section. That's smart and agile but slower.

But guess what... I've alread improved that. Yes. I have TBS 1.97b ready to test now. This coming next version put TBS fields in cache, so time is saved. This version has good results. And any beta testers are welcome.

TBS will still be under Smarty benches because TBS does more. For exemple, TBS has event properties that enables you to change data dynamically. But TBS is geting closer and closer.

Unfortunatly, I don't understand german words. But I would be glade to take part of template discutions, because I've be looking around a lot before to start TBS.
By: RwD
Date: 2004-06-09
Time: 10:59

Re: Speed of tbs

Well, the big discussion point is why one would use tbs over PHP as a template engine:

<?php
$output = array ();

$query = "SELECT some, stuff FROM myTable";
$res = mysql_query ( $query );
$output [ 'rows' ] = array ();
while ( $row = mysql_fetch_assoc ( $res ) ) {
   $output [ 'rows' ][]= $row;
}

include ( './template/mytable.php' );
?>

with template
<? if ( empty ( $output [ 'rows' ] ) ): ?>
   <p>Er zijn geen resultaten</p>
<? else: ?>
   <table>
      <?foreach ( $output [ 'rows' ] as $row ): ?>
         <tr>
            <td><?=html ( $row [ 'some' ] )?></td>
            <td><?=html ( $row [ 'stuff' ] )?></td>
         </tr>
      <?endforeach;?>
   </table>
<? endif; ?>

versus tbs way:
<?php
   // $cnx_id is de connectie id die ergens in de code is aangemaakt
   
   $TBS = new clsTinyButStrong;
   $TBS->LoadTemplate( 'voorbeeld.htm' );
   $TBS->MergeBlock( 'voorbeeld', $cnx_id, 'SELECT some, stuff FROM myTable' );
   $TBS->Show() ;
?>
<table>
   <tr>
      <td>[voorbeeld.some;block=tr]</td>
      <td>[voorbeeld.stuff]</td>
   </tr>
   <tr>
      <td colspan="2">[voorbeeld;block=tr;nodata]Er zijn geen resultaten.</td>
   </tr>
</table>

So, why would you use tbs over php if you put it like this. The discussion point is that PHP in it self can be used as a template engine...

Perhaps you have some arguments which make clear why one should use tbs or a template enigne in general?

(you why use it section was not good enough for them :S)
By: Skrol29
Date: 2004-06-09
Time: 11:42

Re: Speed of tbs

Ok,

Maybe I can speak in english in your forum. But here is my aswer (you can post in the german forum if you want) :

The Template you suggest to compare with TBS (let's call it a Smarty Template) is not what I would call a template. For me, since there is program statements, it's a kind of script over PHP.

Only a developper can build such a Template. A pure Html designer is not able to do it. He must has some algorythm understanding.

Designing Html Templates should be like designing C++Builder Forms, Delphi Forms, 4D Forms, Visual Basic Forms, .Net Forms ... I mean just like any visual RAD tools: forms in one side, program in another side.
That's what templates are (template = static form), or should be.  And that's what Template Systems before TBS never did.
By: RwD
Date: 2004-06-09
Time: 14:40

Re: Speed of tbs

Ok, but then how does a designer design a template?
I mean, in the templates I build I need some knowledge of the php files before I can build them...

So why is tbs so easy for the designer? Doesn't he still need to understand some algorythms to be able to put in the tbs tags at the right places?

I know it took some effort from me on my side to learn how to apply tbs in certain cituations.
By: RwD
Date: 2004-06-09
Time: 14:46

Re: Speed of tbs

Ow, and designers still have to learn TBS, why not learn php straight away...

ok, I know, "pain in the butt questions" but not really unexpected I think :P
By: .oisyn
Date: 2004-06-09
Time: 15:59

Re: Speed of tbs

> Designing Html Templates should be like designing C++Builder Forms, Delphi Forms, ...

Weird comparison. Designing such a form does not involve data formatting. However, when designing a webpage, you usually want more than just enumerating all the data between some html tags. For example, one might choose to sort the data, or maybe convert the data to an alternative representation. That is not a job of the logic layer, that is a job for the designer. True, such tasks involve using program statements, but that doesn't exclude the fact that you're still working on a _template_.

I think your opinion that templates shouldn't have any form of control structures or other programming statements is simply wrong, because of the above. Your claim regarding HTML designers not having any understanding of program execution isn't correct either: most designers know how to use javascript. If they know how to use javascript, they can just as easily include program statements in their templates, as they have a fair understanding of the script's execution model.

The essence of templates is separation of data and representation. That doesn't mean you can't use code in the representation layer, it simply means no business logic or data retrieval is done in the representation layer.

I, for one, see no extra value whatsoever of using TBS as opposed to PHP for developing templates. Why develop a template engine in a language that is in itself a template engine (BTW, did you know that the soul purpose of one of the first versions of PHP was parsing templates?). The only reason I can think of is limiting the variables and functions you can use within a template, but to me that's just a matter of discipline. I am a C++ developer, I choose freedom ;)
By: .oisyn
Date: 2004-06-09
Time: 16:28

Re: Speed of tbs

Besides, the fact that you have to use constructions like MergeBlock in code shows that code and templates are too much entangled. In my opinion, the only thing that data logic code should do is to say: "This is my data, and the template is here. Output that for me". The code shouldn't be aware of what is in the template. However, by having to use block names in both templates and code, this awareness is created and the representation in the template is limited (you can't use extra blocks; if you do, those wouldn't be expanded because the programmer didn't specify to do so)
By: Skrol29
Date: 2004-06-09
Time: 16:49

Re: Speed of tbs

I'm surpise that it appears like an evidence for me is not so easy to explain.

There is a difference between learning a tool and learning programming. When a designer have to learn to work with a Template system, he should only have to understand the controls (tags) philosophy and their syntax. The PHP developer tels hims which controls he have prepared for which templates. The Designer shouldn't have to manage loops, data retrieving, ... And The programmer shouldn't have to manage data formating Html/Text differentitation...

Sometime, they have to work closed to each other. For example conditional display is someting to do with programing and something to do with designing.

In reality, it's quite rare when the designer and the programmer are two different persons. But the phylosophy for building an application is the same. Melting design and programing procedures makes the source hard to read, hard to maintain, and difficult to be writed. Designing and Programing procedures are two different aspects of an application. Those aspects are respected by alost all development tools, but not for "Smarty like" Template Systems.
Note that Template System from big editor are not "Smarty like". Dreamweaver/Cold Fusion template for example.
By: Skrol29
Date: 2004-06-10
Time: 11:30

Re: Speed of tbs

I agree that the design part and the program part are not always well split.

Developers have different habits and tool preferences for programming. For examples, some are Mouse, and some are Keyboard. For Html, some are Textual and some are Wysiwyg. (with a collegue, we made a pool on a forum and realised that 50% of Html developers are Textual and 50% are Wysiwyg).

So TBS won't be a tool for all. But Wysiwygable Template System is wanted by lot of people in the "PHP + Html" development. And I can say that The "Smarty Template" philosophy is very specific to the "PHP + Html" world.

In other programming worlds, Template Systems are much more like TBS. To Program melting output design and algorithm is something specific to "PHP + Html" application. A Template System is supposed to reorganize that, and TBS is going further than "Smarty like" systems on this point.