String Replacement Speed Question
I am working on a cache system for my CMS and would like some insight into string replacement speed.
If I have 5 possible strings to be replaced in my template, but only 2 of these strings are actually present in the template, will the speed of attempting to replace all 5 of the strings be quicker when only 2 of the strings are present?
For example, from a database I have the tags <1>,<2>,<3>,<4>,<5> that will be replaced in the template by their associated values. I run a first round of string replacements that will replace all the found tags as long as they are not wrapped in <nocache></nocache> tags. The tags that were not replaced are then inserted back into the template, and the template is saved. Next time the template is called, the already replaced tags will be cached, and the available tags will be searched and replaced once again on template display request. Maybe ONLY 2 tags will be replaced on template call.
In short, if I need to iterate through each possible tag each time the template is called, is it quicker to replace all at once or cache some of the tags if they are not dynamic? I figure each tag must be searched for, but how 'time consuming' is the actual replacement? FYI, I am using str_replace to replace the tags.
I hope this makes sense to someone..Thanks!