Nolongerused3921 Posted December 29, 2006 Share Posted December 29, 2006 Whats a good general runtime for a parser that gets smileys (str_replace) and bbcode (regex) from a database, then parses data input into it... Say a 200 character string.Also, is there anything I can do to speed this up?[code=php:0] $sql = "SELECT * FROM `". $this->bbcode_db ."`"; $db->query($sql,'bbcode_query'); $pattern = array(); $replacement = array(); while ($bbcode = $db->fetch_row('bbcode_query')) { array_push($pattern,$bbcode[pattern]); array_push($replacement,$bbcode[replacement]); } $data = preg_replace($pattern, $replacement, $data); $sql = "SELECT * FROM `". $this->smiley_db ."`"; $db->query($sql,'smiley_query'); while ($smiley = $db->fetch_row('smiley_query')) { $data = str_replace($smiley[pattern], "<img src='".$this->rdir.$smiley[replacement]."' />", $data); }[/code]The code is pretty self explaintory. (My mysql functions do what you'd expect in those cases, and $rdir is just the real directory since I'm using mod_rewrite)Right now I'm sitting at 0.01 seconds to do various site things (About 0.0038 seconds) so the parser itself, to parse the string [code]WOOOOOOOOooo[b]ooooo[/b]Oooooo[i]oooo[/i]TAH! :)[/code]With 7 entries in the bbcode table, and 1 in the smileys table, takes around 0.0062 seconds to parse that string... Which I, personally, feel is pretty slow. Theres got to be a way to speed this up while leaving it open enough to add new smileys/bbcode easily in the future. Quote Link to comment https://forums.phpfreaks.com/topic/32189-need-help-with-a-parser-smileys-bbcode/ Share on other sites More sharing options...
wildteen88 Posted December 29, 2006 Share Posted December 29, 2006 That ain't slow. Thats pretty quick. 6 thousandths of a second! The only time you should worry is when you takes seconds to load. Quote Link to comment https://forums.phpfreaks.com/topic/32189-need-help-with-a-parser-smileys-bbcode/#findComment-149407 Share on other sites More sharing options...
Nolongerused3921 Posted December 29, 2006 Author Share Posted December 29, 2006 I know, but still... I'm a major speed freak, and my code is still pretty incomplete... I want to make sure everything is as fast as humanly possible now, so I don't kill my server when I'm done and my site is up. Quote Link to comment https://forums.phpfreaks.com/topic/32189-need-help-with-a-parser-smileys-bbcode/#findComment-149408 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.