[DGD]Re Need tips with LPC function Im writing.

Felix A. Croes felix at dworkin.nl
Wed Mar 24 15:24:41 CET 1999


Geir Harald Hansen <geirhans at ifi.uio.no> wrote:

> Interesting idea.  parse_string() is a versatile function :)
>
> Anyone have some wise words about efficiency of parse_string(), explode()
> and sscanf() for things like this?

sscanf() is fastest for simple operations.  If you can do it with a
single explode()/implode() combination and not much additional code,
that method is fastest if you expect multiple occurances of the
separator string.  parse_string() is likely to be fastest in other
cases, especially with a complex grammar.  parse_string() is well-
suited for command parsing.

Of course, speed is not the only consideration.  If you are
familiar with parse_string(), you might decide to use it because
using a grammar would be the most elegant solution to a particular
problem.


> And lookups? The switch statement is faster than a mapping?

Yes, though of course mapping lookups are more versatile.


> If all, or most, of messages sent to players get converted like this, I
> guess it should be fast. ;)
>
> If the majority of messages do not contain colorcodes, maybe there is also
> something to gain by first checking for the existence of colorcodes with a
> little loop before actually calling a function to translate them?

In this case, I'd denote the colour code separator with a special
character that does not appear in normal output, for instance \0.
If it is expected that many of the output strings have colour codes
in them, I would use explode()/implode().  If only a few do, I'd
use sscanf() to test for the occurance, and then explode()/implode()
if a \0 was found.

Regards,
Dworkin

List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list