Categories > TinyButStrong general >

strpos, substr and preg_* functions

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: D.Z.
Date: 2005-11-04
Time: 12:58

strpos, substr and preg_* functions

This is the topic in the German forum, I think you missed it...

=====================
Hi,
I'm new to TBS and the concepts it uses is really fresh to me. And I noticed that lots of strpos (strrpos, etc) functions are used in the system to make it work, I wonder if this is much more efficient than preg_functions?

Besides, are there any performance charts/data?

Thank you, great idea and great job for TBS.
By: Skrol29
Date: 2005-11-04
Time: 13:25

Re: strpos, substr and preg_* functions

Hi DZ,

Despite TBS has undergo lot of performance tests and optimisiations, I must say that I've assumed that pure string searches should be faster than Regular Expression searches.
nevertheless, this assumption should be also tested.

> Besides, are there any performance charts/data?

Yes but they are old now. You can found some information with a search on keyword "smarty" on this forum.
By: ClausVB
Date: 2005-11-05
Time: 10:26

Re: strpos, substr and preg_* functions

> Besides, are there any performance charts/data?

Yes, they are:
http://vlib.clausvb.de/benchmarks/tpl_bench_1.php
http://vlib.clausvb.de/benchmarks/tpl_bench_2.php

http://vlib.powerhelpdesk.de/benchmarks/tpl_bench_1.php
http://vlib.powerhelpdesk.de/benchmarks/tpl_bench_2.php

Note: This tests differs from server to server. On my Windows notebook Smarty is always on top (#1). But on Linux vlibTemplate or ETS is often the fastest.

Regards,
Claus
By: D.Z.
Date: 2005-11-05
Time: 17:23

Re: strpos, substr and preg_* functions

Thanks for the bench chart.
Anyway TBS does not seem have lots of advantages on performance, as it parses every and each time. But I definitely the "designer-oriented" concepts that it follows, I'm thinking it would be wonderful if there is a template compiler.

PS: I checked the source code...phew, it's so hard to read and follow, but there does not seem to have lots (read: more than I expected) of string functions, so that is where the power comes, I guess.
By: Skrol29
Date: 2005-11-07
Time: 19:46

Re: strpos, substr and preg_* functions

Thanks ClausVB for that benches !!
Very interesting and often asked on the forum.

Lot of TinyButStrong Error messages are prompted on page
  http://vlib.clausvb.de/benchmarks/tpl_bench_1.php
this probably affects results.

Could you precise the version of Template Engines used?
By: Skrol29
Date: 2005-11-07
Time: 20:11

Re: strpos, substr and preg_* functions

ClauseVB :

The method of assigning variables is unfair for the TBS loop in Benchmark 1 (variable replacement). I explain why:

For other Template Engines the script assigns values to Template Engine's variables.
Like $tpl->setvar(…) or $tpl->assign(…).
TBS doesn't need such assignment, so it should be an advantage for it. But instead of assignment, the script creates one global variable which is a Php array containing 20 variables. Doing so, the script doesn't measure normal variable merging for TBS like for others TE, but it measures sub-variable merging which is a TBS (unique ?) special feature.

Instead of:
  $test_array["var$i"] = '-- TEST VAR --';
the script should do:
  $test_array = "var$i";
  $$test_array = '-- TEST VAR --';
And the template should contain [var.var10] instead of [var.test_array.var10]

Another thing is that the loop should not be measuring the variable creation time. This is out of the Template Engine hands when no assignment is needed. The script should assume that the variables to merge already exist.
By: ClausVB
Date: 2005-11-11
Time: 17:11

Re: strpos, substr and preg_* functions

I changed it. But it does not seem to matter.

Regards,
Claus
By: Maz
Date: 2005-11-11
Time: 19:11

Re: strpos, substr and preg_* functions

And you would be right:

Using preg_replace(), PHP has to parse the string for metacharacters first instead of proceeding straight to the searching.