Re: Question on strncmp / strnicmp use
- From: vippstar@xxxxxxxxx
- Date: Fri, 16 Jan 2009 09:45:39 -0800 (PST)
On Jan 16, 7:34 pm, Barry Schwarz <schwa...@xxxxxxxx> wrote:
On Fri, 16 Jan 2009 08:13:59 -0800 (PST), vipps...@xxxxxxxxx wrote:
Here's what I have in mind:
strlen can't be less than O(n) (optimizations that, say, check 4
elements at once are still O(n))
mycomparison can't be less than O(n).
Using just mycomparison instead of strlen + mycomparison is one less O
(n) function called, so in that way, I'm correct.
You mention increment of pointers and comparison, but those operations
are O(1).
All that is not supported by the standard which doesn't even mention
the concept of efficiency/time of operation, but I hope you can see
what I'm trying to say.
As an abstract theoretical exercise, maybe you are right. But I
think your frame of reference may be restricted by your experience
with a limited number of systems.
There are machines where strlen can be implemented as a single
instruction. Under the as if rule, the compiler need not even
generate a function call.
The same is true regarding strncmp. Furthermore, these machines can
allow both strings to populate cache.
Standards seem to have a life of 10+ years while hardware development
proceeds at a much faster rate. Since the manufacturer of one such
machine is on the standards committee (and made these optimizations
primarily to support C and C++), this may one reason the standard
omits such considerations.
Thanks, with your explanation now I see the point Ben Bacarisse made,
and I agree with both.
.
- References:
- Question on strncmp / strnicmp use
- From: C . J . Clegg
- Re: Question on strncmp / strnicmp use
- From: vippstar
- Re: Question on strncmp / strnicmp use
- From: Ben Bacarisse
- Re: Question on strncmp / strnicmp use
- From: vippstar
- Re: Question on strncmp / strnicmp use
- From: Barry Schwarz
- Question on strncmp / strnicmp use
- Prev by Date: Re: Different ways
- Next by Date: Re: Question on strncmp / strnicmp use
- Previous by thread: Re: Question on strncmp / strnicmp use
- Next by thread: Re: Question on strncmp / strnicmp use
- Index(es):
Relevant Pages
|