tweaking efficiency

Kenneth Brody kenbrody at bestweb.net
Wed Sep 28 14:45:49 PDT 2005


Quoting Brian K. White (Wed, 28 Sep 2005 16:38:42 -0400):

> Is there any difference in the amount of work done behind the scenes
> between
> these two?
>
> ... < xlate(@t4,"/","") < xlate(@tm,":","")
>
> ... < xlate(@t4<@tm,"/:","")

Without any actual timing, my gut says that the first method is
slightly more efficient due to looking for only a single character
in each of the fields, rather than looking for both characters in
a combined field.

> They don't produce the exact same output, the 2nd one leaves more than
> one space between the two values

No, it doesn't.

[...]
> The 1st version is more quicly read and understood, but I'm always
> trying to make things as efficient as possible so the 2nd version
> occured to me.

How many times is the command going to be executed?

> It's one less comand, but it's doing the same work so unless there is
> some overhead just calling and returning from a command at all, I'm
> guessing there is no advantage to the 2nd way?

The second way looks for two characters within a 19-character field,
whereas the first looks for a single character within a 10-character
field and a single character within an 8 character field.  Although
there is a miniscule amount of overhead in calling xlate() twice,
the fact that each call only looks for a single character should more
than outweigh the overhead of calling it twice.

> It's obviously more an academic question than anything. If this was in a
> tight loop that ran hundreds of times per second for a hundred different
> users at the same time, it might have a real world consequence, but
> that's not the case.

Given that the difference is probably in the order of microseconds,
and probably fractions of microseconds, even a thousand executions
for a thousand users would probably be only a fraction of a second
diference.

> Actually originally I had this but I'm just assuming that xlate is
> lighter weight than doedit
>
> ... < doedit(@t4,"yymd") < xlate(@tm,":","")

Yes, xlate is more efficient here.

--
KenBrody at BestWeb dot net        spamtrap: <g8ymh8uf001 at sneakemail.com>
http://www.hvcomputer.com
http://www.fileProPlus.com


More information about the Filepro-list mailing list