All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jesse Ruffin <joruffin@gmail.com>
To: linux-c-programming@vger.kernel.org
Subject: Re: String comparison for fixed strings
Date: Wed, 15 Aug 2007 14:51:21 -0400	[thread overview]
Message-ID: <200708151451.48929.joruffin@gmail.com> (raw)
In-Reply-To: <9870a8150708150406x6297b877u473bfbbc62949f10@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 865 bytes --]

If you are only checking for exact equality of a buffer against a string, the memcmp() function may be slightly faster.

if ( memcmp( (const void*) s, (const void*) "ABC", 3 ) == 0 ) {
	// equal
} else {
	// not equal
}

Jesse Ruffin

On Wednesday 15 August 2007 07:06, 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.
> -
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

      parent reply	other threads:[~2007-08-15 18:51 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
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 [this message]

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=200708151451.48929.joruffin@gmail.com \
    --to=joruffin@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.