linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Kratzer <kratzers@pa.net>
To: KhaOsh <ficheironegro@gmail.com>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: String comparison for fixed strings
Date: Wed, 15 Aug 2007 09:18:52 -0400	[thread overview]
Message-ID: <200708150918.52599.kratzers@pa.net> (raw)
In-Reply-To: <9870a8150708150406x6297b877u473bfbbc62949f10@mail.gmail.com>

On Wednesday 15 August 2007 07:06:24 KhaOsh wrote:
> Hello everyone,
>
> In terms of speed what the fastest way of doing a strings comparison
> on fixed strings? Using one of those strcmp() functions or doing the
> following:
>
> (Pseudo code)
> "if (s[0] == 0xa && s[1] == 0xb && s[2] == 0xc)" (etc)
> or
> "if (s[0] == 'A' && s[1] == 'B' && s[2[ == 'C')" (etc)
>
> Thanks for your help.

The function strcmp uses a do/while loop, a conditional to test every 
character in the first string against the null character, and pointer 
arithmetic, so, in terms of sheer speed, your method would probably be 
faster. But, in terms of program clarity, strcmp wins by a mile.

Stephen Kratzer

  reply	other threads:[~2007-08-15 13:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-15 11:06 String comparison for fixed strings KhaOsh
2007-08-15 13:18 ` Stephen Kratzer [this message]
2007-08-15 14:46   ` Glynn Clements
2007-08-15 17:26     ` Leslie P. Polzer
2007-08-16  1:44       ` Glynn Clements
2007-08-16  7:30         ` Per Jessen
2007-08-16 18:14           ` Glynn Clements
2007-08-17  7:49             ` Per Jessen
2007-08-17 20:22               ` KhaOsh
2007-08-16  1:54     ` Glynn Clements
2007-08-15 18:51 ` Jesse Ruffin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200708150918.52599.kratzers@pa.net \
    --to=kratzers@pa.net \
    --cc=ficheironegro@gmail.com \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).