Re: String comparison for fixed strings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxx
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

Attachment: pgp960rFHAKgW.pgp
Description: PGP signature


[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux