Re: improve strlen
- From: "randyhyde@xxxxxxxxxxxxx" <spamtrap@xxxxxxxxxx>
- Date: Wed, 26 Oct 2005 20:16:41 +0000 (UTC)
jukka@xxxxxxxxxxxx wrote:
> Hello. Your latest optimizations make the assembly version _slower_
> than the C++ version here. The original code was ~6% faster, now it is
> ~15% slower.
>
> Unrolling like that kinda kills branch prediction, I suppose. And burns
> code/tracecache for no real gain..
Unrolling code won't *kill* branch prediction; it might not take
advantage of branch prediction, but it doesn't kill it (i.e., make it
less effective when it is used).
Of course, the main problem I'm seeing here is that people are running
their programs and measuring the results on different CPUs. And all
bets are off when you do that. This is why it's almost a worthless
exercise to "count cycles" these days. If you optimize the code on one
CPU, chances are pretty good it *won't* be optimal on a different CPU.
So unless you're writing the code to run on a specific rev of a
specific CPU, shaving one or two clock cycles off the execution time of
an algorithm is a real waste of time.
While I can appreciate why it would be nice to have the world's fastest
strlen program, given the effort that seems to be put into this problem
over and over again, the more reasonable question to ask is "why aren't
all these people using a better data structure that makes string
operations more efficient?" (e.g., including the length as part of the
string data type; maybe reference counters, too). Sure, we'd all love
the idea of simply recompiling old programs that don't know any better
and having them run faster, but the truth is that if people would
simply stop using zstrings (except for interface with OSes and other
code that uses them) and employ a better internal data structure, the
whole issue of the "fastest strlen" algorithm would go away. If people
would use reference counters and pointers, then worrying about the
"fastest block move operation" would diminish, too.
As the old saying goes - get the algorithm (and, presumably, data
structure) right *FIRST*.
Cheers,
Randy Hyde
.
- Follow-Ups:
- Re: improve strlen
- From: hutch--
- Re: improve strlen
- From: jukka@xxxxxxxxxxxx
- Re: improve strlen
- References:
- improve strlen
- From: Claudio Daffra
- Re: improve strlen
- From: spamtrap
- Re: improve strlen
- From: hutch--
- Re: improve strlen
- From: spamtrap
- Re: improve strlen
- From: jukka@xxxxxxxxxxxx
- Re: improve strlen
- From: jukka@xxxxxxxxxxxx
- Re: improve strlen
- From: jukka@xxxxxxxxxxxx
- Re: improve strlen
- From: hutch--
- Re: improve strlen
- From: jukka@xxxxxxxxxxxx
- improve strlen
- Prev by Date: Why gcc translate a c program into assemble as follow
- Next by Date: Re: Why gcc translate a c program into assemble as follow
- Previous by thread: Re: improve strlen
- Next by thread: Re: improve strlen
- Index(es):
Relevant Pages
|