Categories > TinyButStrong general >

Performance compared to Smarty, i18n and Auto-Authentication

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: dDo
Date: 2005-03-15
Time: 01:38

Performance compared to Smarty, i18n and Auto-Authentication

I am evaluating to use TinyButStrong or Smarty for an important project,  performance compared to Smarty? support for i18n? TinyButStrong is appropiate for big projects?

Auto Authentication? during several years I have developed sites with a Java template engine, templates and actions could need authentication to accede to them, example:
auth template theTemplate {...}

If the user had not authenticated itself was automatically directed to the login page. And after login was OK, automatically continue with template required previously. New feature?

Thanks!
By: Outer
Date: 2005-03-15
Time: 06:08

Re: Performance compared to Smarty, i18n and Auto-Authentication

yes, I would also like to know the performance compared to Smarty and Ect.

I am developing a CMS based on a game, and I need to decide whether to use Smarty, PHP Fast Template, or TinyButStrong

Thx :)
By: Skrol29
Date: 2005-03-15
Time: 15:29

Re: Performance compared to Smarty, i18n and Auto-Authentication

Hello,

Performance:
---------------
Some benches I just made are saying that Smarty is about 22% faster that TinyButStrong. (But take this with care because I'm not a Smarty developper). The benches are between Smarty 2.6.7 (last version) and TBS 2.02b (which is 0.5% faster than TBS 2.01).
The benches consist in one Html template displaying 1,000 rows with alternated colours. Rows come from a Php array stored in a file. Each row has 4 named fields, one is a string, one is a date displayed using a format. The two benches use the same chrono function and they include only data merging, not the class instantiation. I made 16 successive executions for each solution, and compute the average on the 12 last measures.
Smarty: 1.197 sec (= - 22.7%)
TBS:     1.549 sec
(I can give the source of the benches for those who want to)

FastTemplate:
-----------------
This Template Engine is know to not be fast.
I didn't made benches but a TBS user did so for TBS version 1.57 and they confirmed this.

i18n (internationalization):
------------------------------
TinyButStrong gives several useful features to make easily Multilanguage applications.
- The MergeField() method enables you to merge a group of fields using a custom user function which is able to get field’s parameters and sub-names.
- You can also define a known Html charset that will be used to merge data. If you wan to use an unsupported charset, you can define a custom user function instead.
- You can use parameter 'local' to change the date/Number format displaying, another issue is to merge the formats first, and then the data.

Auto Authentication:
----------------------
I made exactly the same feature as yours for one of my applications. now I re-use it often. It consists in one function that can do PASSIVE authentication (reading cookies), LOGIN or LOGOUT.
I'm shared about providing such a feature in a Template Engine. Maybe is should be an add-in. But TBS doesn’t support this feature for now.
By: Skrol29
Date: 2005-03-15
Time: 16:16

Re: Performance compared to Smarty, i18n and Auto-Authentication

I just restarted the same benchs and TBS comes faster than Smarty.
This is very strange, and I noticed that Smarty produce irregular time executions while TBS is quite regular.
Smarty: 1.730
TBS: 1.541 (= - 10.9%)

Maybe I omitted something in Smarty but my code is very simple:
$smarty = new Smarty;
$smarty->assign("Data",$data);
$smarty->display('index.tpl');
By: Skrol29
Date: 2005-03-16
Time: 01:16

Re: Performance compared to Smarty, i18n and Auto-Authentication

TinyButStrong for big projects:
----------------------------------
TinyButStrong is the only Template Engine that can have WYSIWYG templates, and this is very precious when you have a full project with big number of pages or many people taking part. It's also the only Template Engine that I know which doesn't need programming in the Html side. The way it deals with databases or data sources is fast and enables you to merge using only one line of code. Those features really make applications much more simple to code and to maintain.
In those considerations, TBS is the best for important projects.
Performances are good but Smarty stay faster ; TBS doesn't produce compiled templates neither. Some TBS features that make the Html side easier to build can slow down performances when used with big data (especially 'selected' and conditional blocks into merged blocks), but you can do the same from the Php side with better performances. TBS can work with site having a heavy number of users, but this need some optimization consideration in your way of using it.
By: RwD
Date: 2005-03-16
Time: 14:39

Re: Performance compared to Smarty, i18n and Auto-Authentication

Indeed, authentication has nothing to do with a template engine as authentication is between client and server no matter what the layout is.

I wrote a authentication script a while ago. Skrol, would you be interested in exchanging the scripts, see what the other did, if it can be improved and if it indeed is secure??
By: Skrol29
Date: 2005-03-16
Time: 17:48

Re: Performance compared to Smarty, i18n and Auto-Authentication

Hello,

Here is my function. It uses two SQL functions m_Sql_Record() and m_Sql_Execute() that I can provide if you need so, but they simply do what they seems.

Here are the function, and an example of use just after:
/*
Authentication function
Return an array with items: id,acount,action,error,errmsg
If connection fails => id=0 and error<>0
Arguments:
$tablestr : User Table structure (exemple = "table_name,id_field,acount_field,pwd_field")
$action   : 'login' => check acount+pwd ; 'logout'=> exit ; other => passive authetication reading cookies
$acount+$pwd : needed when $action=='login'
$nbrdays : life duration of cookies
*/
function m_Sec_CurrentUser($tablestr='',$action='',$acount='',$pwd='',$newpwd=false,$nbrdays=365) {

    $user = array('id'=>0,'acount'=>'','action'=>$action,'error'=>0) ;
    $cookie_pwd = 0;
    $cookie_id  = 0;
   
    // Reading the User Table structure
    if ($tablestr==='') $tablestr='t_sec_user,us_id,us_acount,us_pwd';
    $tablestr = explode(',',$tablestr);

    // Action to performe
    if ($user['action']==='') {
        if (isset($_GET['sec_action'])) {
            $user['action'] = $_GET['sec_action'] ;
        } elseif (isset($_POST['sec_action'])) {
            $user['action'] = $_POST['sec_action'] ;
        }
    }
   
    if ($user['action']==='logout') { // Disconnection : delete cookies
       
        $cookie_id = -1;
        $cookie_pwd = -1;
       
    } elseif ($user['action']==='login') { // Login with acount+pwd not crypted
       
        // Retrieving user's acount
        if ($user['acount']==='') {
            if (isset($_GET['sec_acount'])) {
                $user['acount'] = $_GET['sec_acount'] ;
            } elseif (isset($_POST['sec_acount'])) {
                $user['acount'] = $_POST['sec_acount'] ;
            }
            if (get_magic_quotes_gpc()==1) $user['acount'] = stripslashes($user['acount']) ;
        }
        if ($user['acount']==='') {
            $user['error'] = 2 ;
            $user['errmsg'] = 'Acount missing' ;
            return $user ;
        }

        // Retrieving password
        if ($pwd==='') {
            if (isset($_GET['sec_pwd'])) {
                $pwd = $_GET['sec_pwd'] ;
            } elseif (isset($_POST['sec_pwd'])) {
                $pwd = $_POST['sec_pwd'] ;
            }
            if (get_magic_quotes_gpc()==1) $pwd = stripslashes($pwd) ;
        }

        // Retrieving User's Information
        $pwd = md5($pwd) ;
        $info = m_Sql_Record('SELECT '.$tablestr[1].' AS id FROM '.$tablestr[0].' WHERE ('.$tablestr[2].'=@1@) AND ('.$tablestr[3].'=@2@)',$user['acount'],$pwd) ;
        if ($info===False) {
            $user['error'] = 1 ;
            $user['errmsg'] = 'Bad acount or password.' ;
        } else {
            $user['id'] = $info['id'] ;
            $cookie_pwd = 1;
            $cookie_id  = 1;
        }

    } else { // Passive login using id+pwd crypted
       
        // Readin info into cookies
        if (isset($_COOKIE['sec_id']) and isset($_COOKIE['sec_pwd'])) {
            $id = intval($_COOKIE['sec_id']) ;
            if ($id>0) {
                $info = m_Sql_Record('SELECT '.$tablestr[2].' AS acount FROM '.$tablestr[0].' WHERE ('.$tablestr[1].'=@1@) AND ('.$tablestr[3].'=@2@)',$id,$_COOKIE['sec_pwd']) ;
                if ($info===False) {
                    //Mot de passe erroné dans les cookies => on retire le cookies par sécurité
                    $cookie_pwd = -1;
                    $cookie_id  = -1;
                } else {
                    $user['id'] = $id ;
                    $user['acount'] = $info['acount'] ;
                }
            }
        }
       
    }

    // Change password
    if ($newpwd!==false) {
        if ($user['id']!=0) {
            $pwd = md5($newpwd);
            $cookie_pwd = 1;
            m_Sql_Execute('UPDATE '.$tablestr[0].' SET '.$tablestr[3].'=@2@ WHERE ('.$tablestr[1].'=@1@)',$user['id'],$pwd);
        }
    }

    // Managing cookies (deleting cookies using setcookie('sec_id') doesn't work.
    if ($cookie_id!=0) {
        if ($cookie_id==-1) {
            $user['id'] = 0;
            $nbrdays = -1;
        }
        setcookie('sec_id', $user['id'],time()+$nbrdays*24*3600,'/');
    }
    if ($cookie_pwd!=0) {
        if ($cookie_pwd==-1) {
            $pwd = '';
            $nbrdays = -1;
        }
        setcookie('sec_pwd',$pwd,time()+$nbrdays*24*3600,'/');
    }

    return $user ;

}

Example:
$table_info = 't_user,user_id,user_compte,user_pwd';
$UtiSecu = m_Sec_CurrentUser($table_info) ; // Passive authentication

// Authentication screen
// ---------------------
if ($UtiSecu['id']==0) {
    $TBS->LoadTemplate('tmpl_page_connection.htm');
    $TBS->Show();
}
By: RwD
Date: 2005-03-17
Time: 11:49

Re: Performance compared to Smarty, i18n and Auto-Authentication

I'm not posting mine online. I'll send it to you next week.
By: ClausVB
Date: 2005-03-26
Time: 21:41

Re: Performance compared to Smarty, i18n and Auto-Authentication

Quote: "TinyButStrong is the only Template Engine that can have WYSIWYG templates, (...)"

That is not entirly correct, vlibTemplate is able to use WYSIWYG templates, too.

See for yourself:
http://lamp.clausvb.de/examples/tmpl/multiple_pages_kelvin.htm
http://lamp.clausvb.de/examples/multiple_pages_kelvin.php

However ... your template engine has more features.

Regards,
Claus
By: Skrol29
Date: 2005-03-27
Time: 13:38

Re: Performance compared to Smarty, i18n and Auto-Authentication

Hi Clause,

vlibTemplate is Wysiwyg for fields (data items) but not for block definition.
It has blocks with the same special chars as Html, so they are not visible in preview mode.
By: ClausVB
Date: 2005-03-27
Time: 13:59

Re: Performance compared to Smarty, i18n and Auto-Authentication

If you mean something like that
<tmpl_loop name="table_data">
I have to disagree, because you can write
{tmpl_loop name="table_data"}
too. You can use "{" and other special chars. Even your "[" should work. I have to look in the source code, though.

It's just my favourite to see only the variables not the structure like TMPL_IF or TMPL_LOOP.

I testet your class, great peace of work. I think I will use it for one of my projects to compare vLIB with TBS.

Regards,
Claus
By: Skrol29
Date: 2005-03-27
Time: 14:26

Re: Performance compared to Smarty, i18n and Auto-Authentication

Ok, but this block definition syntax is not allways visible.
How do you define a block on the row of an Html table for example?
<table>
{tmpl_loop name="myblock"}
<tr><td> Hello World </td></tr>
{/tmpl_loop}
</table>
And this is not Wysiwyg.
By: digitallysmooth
Date: 2005-08-17
Time: 09:17

Re: Performance compared to Smarty, i18n and Auto-Authentication

I dropped the above example into dreamweaver MX 2004 and found that the table showed up and the tags did not which is the expected result.

I am reading through all these threads to get an idea about TBS and figured I'd test this out just to see what happens.

Looks like both work (TBS and vlibTemplate).
By: Skrol29
Date: 2005-08-18
Time: 18:51

Re: Performance compared to Smarty, i18n and Auto-Authentication

Hi,

This is not the expecting result when we talk about Wysiwyg Coding because you cannot edit this template snippet in the visual mode (of Dreamweaver). You have to edit the source code.

Also, the table seems to be something valid in the visual mode (of dreamweaver), but it not let you know what are the bounds of the block. You cannot even guess that there is a block. (But I must admit that some TBS blocks connot be guessed is some cases).

In both FireFox and Internet Exlorer, you will have the two tags displayed before the table. Wich is not valid anymore.