Mail Archives: djgpp/1999/11/16/14:26:52
Hans-Bernhard Broeker (broeker AT acp3bf DOT knirsch DOT de) wrote:
: Alain Magloire (alainm AT news DOT mcgill DOT ca) wrote:
: > Malcolm (donald DOT mcleanNOdoSPAM AT talk21 DOT com DOT invalid) wrote:
: > : What does strset do ? I imagine it sets a string to all one
: > : character. This is easy to code
: [...]
: > Then, in that case you are better off with memset() which on most
: > OS/libc coded in assembly for speed.
: Wrong, at least for some applications. The difference is that you have
: to know the length of the string to be 'blanked out', before you can
: call memset(), i.e. strset(string, c) would be equivalent to
: memset(string, c, strlen(string));
: That's two loops over the string, one to find its end, the second to
: fill it with 'c'. Almost certainly slower than strset, if that is
: implemented in the straightforward way demonstrated by the posting you
: answered to. Two loops doing so little are practically always slower
: than one, even if both of them are especially cleverly written, and
: the single loop is just compiled ordinarily.
Allright, Fair enough, for that particular example, especially as you pointed
out the length is unknown. But I will still advocate to use What you got,
and Frankly Hans, I admit no more beleiving in little speed tricks, as you
demostrated above. When programing on modern CPUs like the PPC, MIPS etc
with branch prediction, branch folding, out-of-order execution etc ..
It's better to use the full extent of the C lib and let the compiler
do it's magic.
Nevertheless your point is well taken.
--
au revoir, alain
----
Aussi haut que l'on soit assis, on est toujours assis que sur son cul !!!
- Raw text -